Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReplaceComponents Macro

Status
Not open for further replies.

Creigbm

Mechanical
Aug 1, 2003
161
I am simply trying to write a macro that will replace components in an assembly. I tried recording a macro and doing some 'reverse engineering' on it but I keep on getting an error. Here is the code I am using:

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

boolstatus = Part.Extension.SelectByID("DM1-1@DMAssembly", "COMPONENT", 0, 0, 0, False, 0, Nothing)
Part.ClearSelection
Part.ReplaceComponents "Some File Name", "", False, 0, True

Thanks in advance for any help.
 
Replies continue below

Recommended for you

OpenDoc6: you need to have defined variables in place in the last two options to catch errors.

No need to "Set Part = swApp.ActiveDoc" is you already have the part object from using OpenDoc6

Try selecting using AssemblyDoc::FeatureByName

[bat]Good and evil: wrap them up and disguise it as people.[bat]
 
I tried that and it gave me the same error. Ignore the opendoc6 for now, try to record a macro that will replace a component in an assembly (if you dont mind!). I keep on getting that same error which tells me that i have the worng number of arguments, but it is a direct recording from SolidWorks so I dont understand. Thanks for your help.
 
From the Help, I only see 4 arguments. You are passing 5.

retval = AssemblyDoc.ReplaceComponents ( fileName, configName, replaceAllInstance, reAttachMates )



DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
There we go! Thanks, I don't understand why SolidWorks added the 5th condition, but it works now. Thanks for your help/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor