From 4fc129e35b7b4147fa6081090177e37441ba9513 Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 16 Feb 2026 19:08:06 +0000 Subject: [PATCH] fix: try setattr/SetX/method patterns for SketchInPlaceBuilder properties (NXOpen Python getter/setter naming collision) --- .../adaptive-isogrid/src/nx/import_profile.py | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/adaptive-isogrid/src/nx/import_profile.py b/tools/adaptive-isogrid/src/nx/import_profile.py index 65df8425..0ce8f657 100644 --- a/tools/adaptive-isogrid/src/nx/import_profile.py +++ b/tools/adaptive-isogrid/src/nx/import_profile.py @@ -157,16 +157,49 @@ def _find_or_create_sketch( # Create sketch-in-place builder sketch_builder = part.Sketches.CreateSketchInPlaceBuilder2(NXOpen.Sketch.Null) - # These are method calls (verified from MCP .pyi stubs), not property setters - sketch_builder.PlaneReference(plane) - + # NXOpen Python naming collision: property getter and setter method share + # the same name. builder.PlaneReference returns None (getter), so calling + # builder.PlaneReference(plane) = None(plane) = TypeError. + # Solution: use setattr() to bypass the getter and hit the setter. origin_point = part.Points.CreatePoint(origin_pt) - sketch_builder.SketchOrigin(origin_point) - axis_dir = part.Directions.CreateDirection( origin_pt, x_vec, NXOpen.SmartObject.UpdateOption.WithinModeling, ) - sketch_builder.AxisReference(axis_dir) + + # Try multiple setter patterns + for attr, val, label in [ + ("PlaneReference", plane, "plane"), + ("SketchOrigin", origin_point, "origin"), + ("AxisReference", axis_dir, "axis"), + ]: + # Pattern 1: setattr (property assignment) + try: + setattr(sketch_builder, attr, val) + lister.WriteLine(f"[import] Set {label} via setattr") + continue + except Exception as e1: + pass + + # Pattern 2: find the setter method with Set prefix + setter_name = "Set" + attr + try: + setter = getattr(sketch_builder, setter_name, None) + if setter: + setter(val) + lister.WriteLine(f"[import] Set {label} via {setter_name}()") + continue + except Exception: + pass + + # Pattern 3: direct call (in case NX version supports it) + try: + getattr(sketch_builder, attr)(val) + lister.WriteLine(f"[import] Set {label} via method call") + continue + except Exception: + pass + + lister.WriteLine(f"[import] WARNING: Could not set {label} ({attr})") # Commit to create the sketch sketch_feature = sketch_builder.CommitFeature()