2 Replies Latest reply on Mar 16, 2017 3:53 PM by Brian Smith

    Edit Sub Assembly

    Brian Smith

      I've looked high and low in the API for a way to edit sub assembly. While probably not enough, hopefully one of you could make my search easier.

       

      I don't see an option to edit a sub assembly. The options I do see are:

      1. Editing a part from IAssembly.editpart2

      2. Editing the top level assembly from IAssembly.editassembly

       

      I do not see how to edit a sub assembly while in the context of a higher level size assembly. When you call editpart2 on a selected assembly it returns back -1, meaning failure.

       

      I am sure there is a way, but my 2 hour+ search for the function I want has provided no solution.

       

      Any help is appreciated.

        • Re: Edit Sub Assembly
          Amen Allah Jlili

          Oh, Brian!
          You could have saved yourself A LOT of time if you had recorded a macro.
          This is the ultimate way to see the solidworks api inner working.

          I've added an assembly to assembly and was able to edit it in context:

          ' ******************************************************************************
          ' WWW.CADHERO.COM
          ' ******************************************************************************
          Dim swApp As Object
          Dim Part As Object
          Dim boolstatus As Boolean
          Dim longstatus As Long, longwarnings As Long
          Sub main()
          Set swApp = _
          Application.SldWorks
          Set Part = swApp.ActiveDoc
          Dim myModelView As Object
          Set myModelView = Part.ActiveView
          myModelView.FrameState = swWindowState_e.swWindowMaximized
          boolstatus = Part.Extension.SelectByID2("Assem1-1@Assem2", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
          boolstatus = Part.Extension.SelectByID2("Assem1-1@Assem2", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
          Part.EditAssembly
          Part.ClearSelection2 True
          Part.EditAssembly
          End Sub
          

           

          The macro recorder tool is dirty and dangerous, isn't it?


          Cheers,
          Amen