ReplaceComponents Macro

Aug 11, 2003 1 Replies

I am simply trying to replace components in an assembly using the following code:



Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main()



Set swApp = Application.SldWorks



Set Part = swApp.OpenDoc4("C:\Program Files\SolidWorks\data\Templates\DMAssembly.sldasm", 2, 0, "", longstatus) Set Part = swApp.ActivateDoc("DMAssembly")



Set swApp = Application.SldWorks



Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID("DM1-1@DMAssembly", "COMPONENT", 0, 0, 0, False, 0, Nothing) Part.ClearSelection Part.ClearSelection boolstatus = Part.Extension.SelectByID("DM1-1@DMAssembly", "COMPONENT", 0, 0, 0, False, 0, Nothing) Part.ClearSelection Part.ReplaceComponents "C:\Program Files\SolidWorks\data\Templates\DM4.sldprt", "", False, 0, True End Sub



I got this by recording a macro and I am getting an error saying "Wrong number of arguments or invalid property assigment." I dont understand why I am getting this error since I recorded the macro from SolidWorks. Thanks in advance for any help.


Remove the Part.ClearSelection staements after the SelectByID statements. You also need to change the second SelectByID statement to append this selection to the selection list. This is done by one of the parameters.

Hope this helps,

-- Bob Hanson CEO Custom Programming Unlimited LLC SolidWorks Solution Partner in two categories (SW API training/consulting and SW PDM provider)

formatting link
website (Home of SW API Public Code snippets)

SolidWorks 2003 World User Conference Exhibitor Booth #407

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required