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?
Thanks,
Sean
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; "."
swApp.NewAssembly
Set swComponent = swAssy.AddComponent4(modPath, 0, 0, 0, 0)
End Sub
SolidworksApi macros
Try this one:
Deepak,
Using AddComponent2 produced much better results.
Do you use this, as opposed to the other comparable calls, due to its simplicity and ease of use?
Thanks,
Sean
Yes. Though it is obsolete now but worked fine.
I know Deepak provided an answer but I thought I might point out where your code may have gone wrong.
Perhaps you should of had:
Set swAssy = swApp.NewAssembly
Set swComponent = swAssy.AddComponent4(modPath, 0, 0, 0, 0)
I think that is why it failed. You never set the "swAssy" object to anything.
Matt,
Thank you! I missed that: you're right.