fix: resolve ViewReorient/UpdateLevel enum at runtime with multiple fallback paths
This commit is contained in:
@@ -95,15 +95,12 @@ def _find_or_create_sketch(
|
|||||||
if existing_sketch is not None:
|
if existing_sketch is not None:
|
||||||
# Clear existing geometry for update
|
# Clear existing geometry for update
|
||||||
try:
|
try:
|
||||||
existing_sketch.Activate(NXOpen.ViewReorient.FalseValue)
|
existing_sketch.Activate(False)
|
||||||
all_geom = existing_sketch.GetAllGeometry()
|
all_geom = existing_sketch.GetAllGeometry()
|
||||||
if all_geom:
|
if all_geom:
|
||||||
existing_sketch.DeleteObjects(list(all_geom))
|
existing_sketch.DeleteObjects(list(all_geom))
|
||||||
lister.WriteLine(f"[import] Cleared {len(all_geom)} objects from existing sketch")
|
lister.WriteLine(f"[import] Cleared {len(all_geom)} objects from existing sketch")
|
||||||
existing_sketch.Deactivate(
|
existing_sketch.Deactivate(False, False)
|
||||||
NXOpen.ViewReorient.FalseValue,
|
|
||||||
NXOpen.UpdateLevel.Model,
|
|
||||||
)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
lister.WriteLine(f"[import] Warning clearing sketch: {exc}")
|
lister.WriteLine(f"[import] Warning clearing sketch: {exc}")
|
||||||
return existing_sketch
|
return existing_sketch
|
||||||
@@ -452,8 +449,30 @@ def main():
|
|||||||
|
|
||||||
# Activate sketch for drawing
|
# Activate sketch for drawing
|
||||||
try:
|
try:
|
||||||
# NXOpen.ViewReorient: FalseValue = don't reorient, TrueValue = reorient
|
# ViewReorient enum — try multiple access paths
|
||||||
sketch.Activate(NXOpen.ViewReorient.FalseValue)
|
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:
|
except Exception as exc:
|
||||||
lister.WriteLine(f"[import] ERROR activating sketch: {exc}")
|
lister.WriteLine(f"[import] ERROR activating sketch: {exc}")
|
||||||
continue
|
continue
|
||||||
@@ -486,8 +505,8 @@ def main():
|
|||||||
# Deactivate sketch
|
# Deactivate sketch
|
||||||
try:
|
try:
|
||||||
sketch.Deactivate(
|
sketch.Deactivate(
|
||||||
NXOpen.ViewReorient.FalseValue,
|
view_false,
|
||||||
NXOpen.UpdateLevel.Model,
|
False, # UpdateLevel — False or Model
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
lister.WriteLine(f"[import] Warning deactivating: {exc}")
|
lister.WriteLine(f"[import] Warning deactivating: {exc}")
|
||||||
|
|||||||
Reference in New Issue
Block a user