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:
@@ -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}"
|
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:
|
try:
|
||||||
import NXOpen
|
import NXOpen
|
||||||
import NXOpen.UF
|
import NXOpen.UF
|
||||||
|
|
||||||
uf = NXOpen.UF.UFSession.GetUFSession()
|
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] = []
|
pts: List[Point3D] = []
|
||||||
parse_failures = 0
|
parse_failures = 0
|
||||||
try:
|
try:
|
||||||
for i in range(n_pts + 1):
|
for i in range(n_pts + 1):
|
||||||
t = t0 + (t1 - t0) * (i / n_pts)
|
param = float(i) / float(n_pts) # 0.0 to 1.0
|
||||||
result = uf.Eval.Evaluate(evaluator, 0, t)
|
# AskCurveProps returns: (point[3], tangent[3], normal[3], binormal[3], torsion, radius_of_curvature)
|
||||||
p = _parse_eval_point(result)
|
result = uf.Modl.AskCurveProps(edge.Tag, param)
|
||||||
if p is None:
|
# 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
|
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:
|
finally:
|
||||||
try:
|
pass
|
||||||
uf.Eval.Free(evaluator)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if len(pts) >= 2:
|
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
|
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:
|
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)
|
# 2) Fallback: IBaseCurve.Evaluate (signature differs by NX versions)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user