fix(extract): use UF_MODL_ask_curve_props instead of UF_EVAL

UF_EVAL.Evaluate() doesn't exist in NXOpen Python.
UF_MODL.AskCurveProps(tag, param) uses normalized 0-1
parameter and returns (point, tangent, normal, binormal,
torsion, radius). Works on all edge types.
This commit is contained in:
2026-02-17 01:31:29 +00:00
parent 97fe055b8d
commit fc1c1dc142

View File

@@ -169,42 +169,41 @@ def _sample_edge_polyline(edge: Any, chord_tol_mm: float, lister: Any = None) ->
f"len={length:.3f} tol={tol:.3f} n_pts={n_pts}"
)
# 1) Primary: UF_EVAL sampling
# 1) Primary: UF_MODL_ask_curve_props — normalized parameter 0..1
try:
import NXOpen
import NXOpen.UF
uf = NXOpen.UF.UFSession.GetUFSession()
evaluator = uf.Eval.Initialize2(edge.Tag)
limits = uf.Eval.AskLimits(evaluator)
t0, t1 = float(limits[0]), float(limits[1])
pts: List[Point3D] = []
parse_failures = 0
try:
for i in range(n_pts + 1):
t = t0 + (t1 - t0) * (i / n_pts)
result = uf.Eval.Evaluate(evaluator, 0, t)
p = _parse_eval_point(result)
if p is None:
param = float(i) / float(n_pts) # 0.0 to 1.0
# AskCurveProps returns: (point[3], tangent[3], normal[3], binormal[3], torsion, radius_of_curvature)
result = uf.Modl.AskCurveProps(edge.Tag, param)
# result[0] is the point array [x, y, z]
if isinstance(result, (list, tuple)) and len(result) >= 1:
pt_data = result[0]
if isinstance(pt_data, (list, tuple)) and len(pt_data) >= 3:
pts.append((float(pt_data[0]), float(pt_data[1]), float(pt_data[2])))
elif hasattr(pt_data, '__len__') and len(pt_data) >= 3:
pts.append((float(pt_data[0]), float(pt_data[1]), float(pt_data[2])))
else:
parse_failures += 1
else:
parse_failures += 1
if parse_failures <= 3:
_log(f"[edge] UF_EVAL parse miss at t={t:.6g}, raw={repr(result)}")
continue
pts.append(p)
finally:
try:
uf.Eval.Free(evaluator)
except Exception:
pass
pass
if len(pts) >= 2:
_log(f"[edge] sampled via UF_EVAL ({len(pts)} pts)")
_log(f"[edge] sampled via UF_MODL ({len(pts)} pts, {parse_failures} failures)")
return pts
_log(f"[edge] UF_EVAL insufficient points ({len(pts)}), falling back")
_log(f"[edge] UF_MODL insufficient points ({len(pts)}), falling back")
except Exception as exc:
_log(f"[edge] UF_EVAL failed: {exc}")
_log(f"[edge] UF_MODL failed: {exc}")
# 2) Fallback: IBaseCurve.Evaluate (signature differs by NX versions)
try: