AnsweredAssumed Answered

I can get my macro for inserting parts into a new assembly to work

Question asked by Joe Pickens on Feb 11, 2016
Latest reply on Feb 12, 2016 by Joe Pickens

I am running this macro and all it does is open a new assembly. i can get it to insert a part. can anyone tell me what i am doing wrong?


Dim SWApp       As New SldWorks.SldWorks

Dim SWModel     As SldWorks.ModelDoc2

Dim SWAsm       As SldWorks.AssemblyDoc

Dim SWComp      As Component2

Dim SWAddComp     As SldWorks.ModelDoc2



Dim TLAsmTemp   As String

Dim SWPrtFile(0)   As String

Dim SWAsmTitle  As String

Dim Str         As Variant

Dim SWAsmName   As String

Dim Errors      As Long

Dim Warnings    As Long



Sub main()



Set SWApp = CreateObject("sldworks.application")



TLAsmTemp = "C:\Users\pickensj\Documents\Templets\JOE'S MO ASSY.asmdot"



Set SWModel = SWApp.NewDocument(TLAsmTemp, 0, 0, 0)

SWModel.Visible = True



SWAsmTitle = SWModel.GetTitle

Str = Split(SWAsmTitle, ".")

SWAsmName = Str(0)





SWPrtFile(0) = "C:\Temp\158045403.SLDPRT"



Set SWAddComp = SWApp.OpenDoc6(SWPrtFile(0), swdocprt, 0, "", Errors, Warnings)

Set SWModel = SWApp.ActivateDoc3(SWAsmTitle, True, swUserDecision, Errors)

Set SWAsm = SWModel

Set SWComp = SWAsm.AddComponent5(SWPrtFile(0), swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", 0, 0, 0)



End Sub