fix: use Matrix3x3 for datum plane, property assignment for SketchInPlaceBuilder2
This commit is contained in:
@@ -118,30 +118,32 @@ def _find_or_create_sketch(
|
|||||||
origin_pt = NXOpen.Point3d(origin[0], origin[1], origin[2])
|
origin_pt = NXOpen.Point3d(origin[0], origin[1], origin[2])
|
||||||
normal_vec = NXOpen.Vector3d(normal[0], normal[1], normal[2])
|
normal_vec = NXOpen.Vector3d(normal[0], normal[1], normal[2])
|
||||||
x_vec = NXOpen.Vector3d(x_axis[0], x_axis[1], x_axis[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])
|
||||||
|
|
||||||
# Create a Plane object using the normal vector
|
# Build Matrix3x3 from x_axis, y_axis, normal (row-major: Xx,Xy,Xz, Yx,Yy,Yz, Zx,Zy,Zz)
|
||||||
plane = part.Planes.CreatePlane(
|
mtx = NXOpen.Matrix3x3()
|
||||||
NXOpen.PlaneTypes.MethodType.Distance, # method
|
mtx.Xx = x_axis[0]; mtx.Xy = x_axis[1]; mtx.Xz = x_axis[2]
|
||||||
NXOpen.PlaneTypes.AlternateType.One, # alternate
|
mtx.Yx = y_axis[0]; mtx.Yy = y_axis[1]; mtx.Yz = y_axis[2]
|
||||||
origin_pt, # origin
|
mtx.Zx = normal[0]; mtx.Zy = normal[1]; mtx.Zz = normal[2]
|
||||||
normal_vec, # normal
|
|
||||||
"", # expression
|
# Create fixed datum plane
|
||||||
False, # flip
|
datum_plane = part.Datums.CreateFixedDatumPlane(origin_pt, mtx)
|
||||||
False, # percent
|
lister.WriteLine(f"[import] Created datum plane: {datum_plane}")
|
||||||
[], # geometry refs
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create sketch-in-place builder
|
# Create sketch-in-place builder
|
||||||
sketch_builder = part.Sketches.CreateNewSketchInPlaceBuilder(NXOpen.Sketch.Null)
|
sketch_builder = part.Sketches.CreateSketchInPlaceBuilder2(NXOpen.Sketch.Null)
|
||||||
sketch_builder.PlaneReference(plane)
|
|
||||||
|
|
||||||
# Set sketch origin as a Point object
|
# Set plane — PlaneReference is a property setter
|
||||||
|
sketch_builder.PlaneReference = datum_plane
|
||||||
|
|
||||||
|
# Set sketch origin
|
||||||
origin_point = part.Points.CreatePoint(origin_pt)
|
origin_point = part.Points.CreatePoint(origin_pt)
|
||||||
sketch_builder.SketchOrigin(origin_point)
|
sketch_builder.SketchOrigin = origin_point
|
||||||
|
|
||||||
# Set axis reference as Direction
|
# Set axis reference
|
||||||
axis_dir = part.Directions.CreateDirection(origin_pt, x_vec, NXOpen.SmartObject.UpdateOption.WithinModeling)
|
axis_dir = part.Directions.CreateDirection(origin_pt, x_vec, NXOpen.SmartObject.UpdateOption.WithinModeling)
|
||||||
sketch_builder.AxisReference(axis_dir)
|
sketch_builder.AxisReference = axis_dir
|
||||||
|
|
||||||
# Commit to create the sketch
|
# Commit to create the sketch
|
||||||
sketch_feature = sketch_builder.CommitFeature()
|
sketch_feature = sketch_builder.CommitFeature()
|
||||||
|
|||||||
Reference in New Issue
Block a user