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

May 19, 2004 4 Replies

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


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)

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

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

Another way to do it

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

Jim

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required