diff --git a/tools/adaptive-isogrid/src/nx/import_profile.py b/tools/adaptive-isogrid/src/nx/import_profile.py index f925b206..4a32eb45 100644 --- a/tools/adaptive-isogrid/src/nx/import_profile.py +++ b/tools/adaptive-isogrid/src/nx/import_profile.py @@ -115,30 +115,57 @@ def _find_or_create_sketch( normal = transform["normal"] x_axis = transform["x_axis"] - # Create datum plane at the sandbox location - sketch_builder = part.Sketches.CreateNewSketchInPlaceBuilder(NXOpen.Sketch.Null) - - # Set the plane 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]) - # Create a datum plane for the sketch - plane = part.Datums.CreateFixedDatumPlane(origin_pt, normal_vec) - sketch_builder.PlaneReference(plane) - - # Set sketch origin - sketch_builder.SketchOrigin(origin_pt) - sketch_builder.AxisReference( - part.Datums.CreateFixedDatumAxis(origin_pt, x_vec) + # Create a Plane object using the normal vector + plane = part.Planes.CreatePlane( + NXOpen.PlaneTypes.MethodType.Distance, # method + NXOpen.PlaneTypes.AlternateType.One, # alternate + origin_pt, # origin + normal_vec, # normal + "", # expression + False, # flip + False, # percent + [], # geometry refs ) - # Commit + # Create sketch-in-place builder + sketch_builder = part.Sketches.CreateNewSketchInPlaceBuilder(NXOpen.Sketch.Null) + sketch_builder.PlaneReference(plane) + + # Set sketch origin as a Point object + origin_point = part.Points.CreatePoint(origin_pt) + sketch_builder.SketchOrigin(origin_point) + + # Set axis reference as Direction + 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() sketch_builder.Destroy() - # Get the sketch object - sketch = sketch_feature.GetEntities()[0] + # Get the sketch object from the feature + sketch = None + try: + entities = sketch_feature.GetEntities() + for e in entities: + if isinstance(e, NXOpen.Sketch): + sketch = e + break + if sketch is None and entities: + sketch = entities[0] + except Exception: + # Try alternate: find sketch by feature + try: + sketch = sketch_feature.Sketch + except Exception: + pass + + if sketch is None: + raise RuntimeError("Could not get Sketch object from feature") # Rename the feature try: