Need API help- how to change name of plane just created?

Hello,

I'm trying to set the name of each plane I create. The code below doesnt work because the current selection is plane1 (I thought when you created a plane it would automatically be selected). How do I set the name of a plane I just created?

For i = 1 To layers Part.CreatePlaneAtOffset3 layerPitch * (i - 1), False, True Set Model = swApp.ActiveDoc Set SelMgr = Model.SelectionManager Set feature = SelMgr.GetSelectedObject5(1) feature.Name = "test" & i Next i

Reply to
Mike
Loading thread data ...

From the help:

"This method does not select the reference plane after it is created. Objects that are selected before running this API are still selected when the method is completed, not the newly created reference plane."

If you Dim the refplane up front, you can use this to store the return from the createplane call, ie;

Dim MyPlane As refPlane Set MyPlane=Part.CreatePlaneAtOffset3( layerPitch * (i - 1), False, True)

You can now select it this way (remembering the previous objects are still selected)

Reply to
rocheey

the "Set Model" and "Set SelMgr" should be done before you enter the loop.

Reply to
TheTick

Also it seems that it would be unnecessary to set your model object, and selection manager "layers" times. If you set them before your For statement there is less to do in the loop. Less is better and faster. You may be running into naming conflict with feature since feature is used by SW.

Dim MyNewPlane As SldWorks.refPlane Dim Feat as SldWorks.feature

Set Model = swApp.ActiveDoc Set SelMgr = Model.SelectionManager

For i = 1 To layers Set MyNewPlane = Part.CreatePlaneAtOffset3 layerPitch * (i - 1), False, True Set Feat = MyNewPlane Feat.Name = "test" & i Next i

Corey Scheich

Reply to
Corey Scheich

Another way to do it

Part.CreatePlaneAtOffset 0, 0 Part.SelectedFeatureProperties 0, 0, 0, 0, 0, 0, 0, 1, 0,"MatingPlane"

Jim

Reply to
jim

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.