5 Replies Latest reply on May 14, 2014 8:12 AM by Sean O'Neill

    Auto-Insert Active Part into New Assembly

    Sean O'Neill

      Hey guys,


      I'm trying to write a simple macro that, when run, takes the active document and places it 'origin-on-origin' as the base component in a newly created assembly.


      I think I'm calling AddComponent4 improperly. When I run this, I get 'Object variable ... not set' message.


      Any idea what I may be doing wrong here?






      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swAssy As AssemblyDoc

      Dim modPath As String

      Dim swComponent As SldWorks.Component2




      Sub main()

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc


          modPath = swModel.GetTitle


          Debug.Print "Path name equals " & modPath; "."



          Set swComponent = swAssy.AddComponent4(modPath, 0, 0, 0, 0)



      End Sub