cancel
Showing results for 
Search instead for 
Did you mean: 

creating datum plane in python

Genius
Genius

I'm trying to create multiple datum planes in python. The code below works. Is there a more efficient way of writing the code?

 

Eventually, I'll add a while or for loop to create multiple planes.

 

### beginning of section curves

#using values from bounding box
xpt=min_corner[0]
ypt=min_corner[1]
zpt=min_corner[2]
plane_offset=1.0

#Create instance of datum plane builder class
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(NXOpen.Features.Feature.Null)

#call method
plane1 = datumPlaneBuilder1.GetPlane()

coordinates = NXOpen.Point3d(xorigin, yorigin, zorigin)
point = workPart.Points.CreatePoint(coordinates)

plane1.SetUpdateOption(NXOpen.SmartObject.UpdateOption.WithinModeling)

plane1.SetMethod(NXOpen.PlaneTypes.MethodType.Distance)
corner1_1 = NXOpen.Point3d(-xpt, -ypt, zpt)
corner2_1 = NXOpen.Point3d(xpt, -ypt, zpt)
corner3_1 = NXOpen.Point3d(xpt, ypt, zpt)
corner4_1 = NXOpen.Point3d(-xpt, ypt, zpt)
datumPlaneBuilder1.SetCornerPoints(corner1_1, corner2_1, corner3_1, corner4_1)

datumPlaneBuilder1.ResizeDuringUpdate = True

feature1 = datumPlaneBuilder1.CommitFeature()

datumPlaneFeature1 = feature1
datumPlane1 = datumPlaneFeature1.DatumPlane

datumPlane1.SetReverseSection(False)
4 REPLIES

Re: creating datum plane in python

Honored Contributor
Honored Contributor

Don't forget to call the DatumPlaneBuilder's .Destroy() method when you are done with the builder.

Re: creating datum plane in python

Genius
Genius

Here is a cleaner way of creating a datum plane in python. This works for creating one plane but I am trying to figure out how to use a for loop to create multiple planes with this code

 

global xpt, ypt, zpt, workPart, sectioncurveslist
#beginning of section
workPart = theSession.Parts.BaseWork
xpt=min_corner[0]
ypt=min_corner[1]
zpt=min_corner[2]
sectioncurveslist=[]
sectioncurveslist.append(workPart.Features.CreateDatumPlaneBuilder(NXOpen.Features.Feature.Null))

corner1 = NXOpen.Point3d(-xpt, -ypt, zpt)
corner2 = NXOpen.Point3d(xpt, -ypt, zpt)
corner3 = NXOpen.Point3d(xpt, ypt, zpt)
corner4= NXOpen.Point3d(-xpt, ypt, zpt)

sectioncurveslist[0].SetCornerPoints(corner1, corner2, corner3, corner4)

sectioncurvesfeature=sectioncurveslist[0].CommitFeature()

sectioncurveslist[0].Destroy()

 

Re: creating datum plane in python

Siemens Phenom Siemens Phenom
Siemens Phenom

Just encapsulate the code above in a function, with suitable inputs. You'll probably end up with something like the Snap.Create.DatumPlane functions. Then call this function inside your loop.

山田
yamada

Re: creating datum plane in python

Genius
Genius

this worked for me.

 

for zlayer in range(int(zmin),int(max_z), int(increment)):
global plane_origin, plane, geom
#create instance
datumPlaneBuilder = workPart.Features.CreateDatumPlaneBuilder(NXOpen.Features.Feature.Null)

#set methods
plane = datumPlaneBuilder.GetPlane()
plane.SetUpdateOption(NXOpen.SmartObject.UpdateOption.WithinModeling)
plane.SetMethod(NXOpen.PlaneTypes.MethodType.Coefficients)

#not sure what this is for
geom = []
plane.SetGeometry(geom)

#set origin of plane
plane_origin = NXOpen.Point3d(0.0, 0.0, zmin)
plane.Origin = plane_origin

#set normal of plane
normal = NXOpen.Vector3d(0.0, 0.0, 1.0)
plane.Normal = normal

#not sure what this is for
plane.SetAlternate(NXOpen.PlaneTypes.AlternateType.One)
coordinates = NXOpen.Point3d(0.0, 0.0, zmin)
point = workPart.Points.CreatePoint(coordinates)
plane.RemoveOffsetData()
plane.Evaluate()

#set corners of plane
corner1 = NXOpen.Point3d(xmin, ymin+distances[1], zmin)
corner2 = NXOpen.Point3d(xmin+distances[0], ymin+distances[1], zmin)
corner3 = NXOpen.Point3d(xmin+distances[0], ymin, zmin)
corner4= NXOpen.Point3d(xmin, ymin, zmin)
datumPlaneBuilder.SetCornerPoints(corner1, corner2, corner3, corner4)

datumPlaneBuilder.ResizeDuringUpdate = True
feature = datumPlaneBuilder.CommitFeature()
datumPlaneFeature = feature
datumPlane = datumPlaneFeature.DatumPlane
datumPlane.SetReverseSection(False)

datumPlaneBuilder.Destroy()

#increment index
zmin+=increment