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

Discussion in 'SolidWorks' started by Mike, May 19, 2004.

  1. Mike

    Mike Guest

    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
     
    Mike, May 19, 2004
    #1
  2. Mike

    rocheey Guest

    The code below doesnt work because the current selection is plane1
    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)
     
    rocheey, May 19, 2004
    #2
  3. Mike

    TheTick Guest

    the "Set Model" and "Set SelMgr" should be done before you enter the loop.
     
    TheTick, May 19, 2004
    #3
  4. 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

    selected)
     
    Corey Scheich, May 19, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.