fix: resolve ViewReorient/UpdateLevel enum at runtime with multiple fallback paths

This commit is contained in:
2026-02-16 19:15:57 +00:00
parent 8143da96e9
commit 61dcefb5ea

View File

@@ -95,15 +95,12 @@ def _find_or_create_sketch(
if existing_sketch is not None:
# Clear existing geometry for update
try:
existing_sketch.Activate(NXOpen.ViewReorient.FalseValue)
existing_sketch.Activate(False)
all_geom = existing_sketch.GetAllGeometry()
if all_geom:
existing_sketch.DeleteObjects(list(all_geom))
lister.WriteLine(f"[import] Cleared {len(all_geom)} objects from existing sketch")
existing_sketch.Deactivate(
NXOpen.ViewReorient.FalseValue,
NXOpen.UpdateLevel.Model,
)
existing_sketch.Deactivate(False, False)
except Exception as exc:
lister.WriteLine(f"[import] Warning clearing sketch: {exc}")
return existing_sketch
@@ -452,8 +449,30 @@ def main():
# Activate sketch for drawing
try:
# NXOpen.ViewReorient: FalseValue = don't reorient, TrueValue = reorient
sketch.Activate(NXOpen.ViewReorient.FalseValue)
# ViewReorient enum — try multiple access paths
view_false = None
for path in [
"NXOpen.ViewReorient.FalseValue",
"NXOpen.Sketch.ViewReorient.FalseValue",
"NXOpen.SketchViewReorient.FalseValue",
]:
try:
parts_p = path.split(".")
obj = __import__(parts_p[0])
for attr in parts_p[1:]:
obj = getattr(obj, attr)
view_false = obj
lister.WriteLine(f"[import] ViewReorient resolved via: {path}")
break
except (AttributeError, ImportError):
continue
if view_false is None:
# Last resort: pass False as boolean
view_false = False
lister.WriteLine("[import] ViewReorient: using False (boolean fallback)")
sketch.Activate(view_false)
except Exception as exc:
lister.WriteLine(f"[import] ERROR activating sketch: {exc}")
continue
@@ -486,8 +505,8 @@ def main():
# Deactivate sketch
try:
sketch.Deactivate(
NXOpen.ViewReorient.FalseValue,
NXOpen.UpdateLevel.Model,
view_false,
False, # UpdateLevel — False or Model
)
except Exception as exc:
lister.WriteLine(f"[import] Warning deactivating: {exc}")