diff --git a/tools/adaptive-isogrid/src/nx/import_profile.py b/tools/adaptive-isogrid/src/nx/import_profile.py index 1b5bd7b0..65df8425 100644 --- a/tools/adaptive-isogrid/src/nx/import_profile.py +++ b/tools/adaptive-isogrid/src/nx/import_profile.py @@ -118,32 +118,55 @@ def _find_or_create_sketch( origin_pt = NXOpen.Point3d(origin[0], origin[1], origin[2]) normal_vec = NXOpen.Vector3d(normal[0], normal[1], normal[2]) x_vec = NXOpen.Vector3d(x_axis[0], x_axis[1], x_axis[2]) - y_axis = transform["y_axis"] - y_vec = NXOpen.Vector3d(y_axis[0], y_axis[1], y_axis[2]) - # Build Matrix3x3 from x_axis, y_axis, normal (row-major: Xx,Xy,Xz, Yx,Yy,Yz, Zx,Zy,Zz) - mtx = NXOpen.Matrix3x3() - mtx.Xx = x_axis[0]; mtx.Xy = x_axis[1]; mtx.Xz = x_axis[2] - mtx.Yx = y_axis[0]; mtx.Yy = y_axis[1]; mtx.Yz = y_axis[2] - mtx.Zx = normal[0]; mtx.Zy = normal[1]; mtx.Zz = normal[2] + # Create a Plane (SmartObject) — NOT a DatumPlane (DisplayableObject) + # PlaneCollection.CreatePlane(method, alternate, origin, normal, expr, flip, percent, geometry) + plane = part.Planes.CreatePlane( + NXOpen.PlaneTypes.MethodType.Fixed, # Fixed plane + NXOpen.PlaneTypes.AlternateType.One, + origin_pt, + normal_vec, + "", # expression + False, # flip + False, # percent + [], # geometry refs + ) + lister.WriteLine(f"[import] Created plane: {plane} (type={type(plane).__name__})") - # Create fixed datum plane - datum_plane = part.Datums.CreateFixedDatumPlane(origin_pt, mtx) - lister.WriteLine(f"[import] Created datum plane: {datum_plane}") + if plane is None: + # Fallback: try Distance method + plane = part.Planes.CreatePlane( + NXOpen.PlaneTypes.MethodType.Distance, + NXOpen.PlaneTypes.AlternateType.One, + origin_pt, normal_vec, "", False, False, [], + ) + lister.WriteLine(f"[import] Fallback plane: {plane}") + + if plane is None: + # Fallback 2: CreateFixedTypePlane + y_axis_t = transform["y_axis"] + mtx = NXOpen.Matrix3x3() + mtx.Xx = x_axis[0]; mtx.Xy = x_axis[1]; mtx.Xz = x_axis[2] + mtx.Yx = y_axis_t[0]; mtx.Yy = y_axis_t[1]; mtx.Yz = y_axis_t[2] + mtx.Zx = normal[0]; mtx.Zy = normal[1]; mtx.Zz = normal[2] + plane = part.Planes.CreateFixedTypePlane( + origin_pt, mtx, NXOpen.SmartObject.UpdateOption.WithinModeling, + ) + lister.WriteLine(f"[import] Fallback2 plane: {plane}") # Create sketch-in-place builder sketch_builder = part.Sketches.CreateSketchInPlaceBuilder2(NXOpen.Sketch.Null) - # Set plane — PlaneReference is a property setter - sketch_builder.PlaneReference = datum_plane + # These are method calls (verified from MCP .pyi stubs), not property setters + sketch_builder.PlaneReference(plane) - # Set sketch origin origin_point = part.Points.CreatePoint(origin_pt) - sketch_builder.SketchOrigin = origin_point + sketch_builder.SketchOrigin(origin_point) - # Set axis reference - axis_dir = part.Directions.CreateDirection(origin_pt, x_vec, NXOpen.SmartObject.UpdateOption.WithinModeling) - sketch_builder.AxisReference = axis_dir + axis_dir = part.Directions.CreateDirection( + origin_pt, x_vec, NXOpen.SmartObject.UpdateOption.WithinModeling, + ) + sketch_builder.AxisReference(axis_dir) # Commit to create the sketch sketch_feature = sketch_builder.CommitFeature()