×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

ReplaceComponents Macro

ReplaceComponents Macro

ReplaceComponents Macro

(OP)
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:

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.

RE: ReplaceComponents Macro

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

Good and evil: wrap them up and disguise it as people.

RE: ReplaceComponents Macro

(OP)
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.

RE: ReplaceComponents Macro

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.

RE: ReplaceComponents Macro

(OP)
There we go!  Thanks, I don't understand why SolidWorks added the 5th condition, but it works now.  Thanks for your help/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources