×
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

Changing a config with a macro

Changing a config with a macro

Changing a config with a macro

(OP)
My programming experience in minimal, but I’m writing a macro in Excel.  I’m learning as I go.

The macro calls a model and changes designated values.  The value that the feature belongs to is irrelevant.

Upon calling the model, I’m trying to activate a given/named configuration, change a value, rebuild, activate the next given/named configuration and change another value and rebuild.

I’m getting stuck on ShowConfiguration2 (“config name”).  I think this is the command that I’m looking for, but how to get it to work is my problem.

Here’s a generic copy of what I’ve written in Excel.

All of the Part.Parameter stuff works fine otherwise.

I get stuck at the ‘Activate Config1 part.  What do I put in this section?

Any help would be greatful.  Simple too, for the learner, please.


Sub Macro()

    Dim swApp As Object
    Dim Part As Object
    
    Set swApp = CreateObject("SldWorks.Application")
    swApp.Visible = True
    Set Part = swApp.ActiveDoc
    
' Load model and expand window
    Set Part = swApp.OpenDoc("path\part.SLDPRT", 1)
    Set Part = swApp.ActivateDoc("part.SLDPRT")
    swApp.ActiveDoc.ActiveView.FrameLeft = 0
    swApp.ActiveDoc.ActiveView.FrameTop = 0
    swApp.ActiveDoc.ActiveView.FrameState = 1
    swApp.ActiveDoc.ActiveView.FrameState = 1
    
'Activate Config1
        
    ' Set values for Config 1 and rebuild model
    Part.Parameter("D1@Helix1@part.SLDPRT").SystemValue = Range("C12").Value / 1000
    Part.EditRebuild

'Activate Config2
        
    ' Set values for Config 1 and rebuild model
    Part.Parameter("D1@Helix1@part.SLDPRT").SystemValue = Range("C12").Value / 1000
    Part.EditRebuild

End Sub

Regards,

Christopher Zona
Litens Automotive Partnership
Concord, Ontario, Canada

RE: Changing a config with a macro

I'm not at my workstation so I can only throw you this quick bit...

To work with configs, you need to start with the Configuration Manager object.

RE: Changing a config with a macro

First of all change

"Dim Part As object"  to "Dim Part As ModelDoc2"

This will make all ModelDoc funcitons and properties available to you.

Next use    Part.ShowConfiguration2(ConfigName)

This will change your configuration to "ConfigName" where ConfigName is Name of the configuraiton you want to show. ConfigName is a string, so you should decalre as

Dim ConfigName As string

You can also use Solidworks API help. Go to Help, API help topics, click on search (3rd tab), in the text box type Showconfiguration and click List Topics.

You will see the API function call for showconfiguration and there is also an example.

Good luck.

jevakil@mapdi.com

One nuclear bomb can ruin your whole day.

RE: Changing a config with a macro

(OP)
I changed "Part" from object to Modeldoc2.  I get a debug error.  It this because the macro is being written within Excel?

Christopher Zona
Litens Automotive Partnership
Concord, Ontario, Canada

RE: Changing a config with a macro

Hey, I think we're on to something!

Do you have your macro references set to include the SW library?  In the VB editor, go to "Tools --> References" and make sure the "SldWorks 2003 Type Library" (or 2001 or 2004 or whatever) is selected.

RE: Changing a config with a macro

sTUPID vba TRICKS...

Have you discovered "ctrl-J" yet?  Hit "ctrl-J" in a code window in the VB editor to get a list of all available objects, variables, methods, etc.

RE: Changing a config with a macro

(OP)
Tick:
Thanks for the library tip. It solved that problem.

Jevakil:
I changed from "Object" to "ModelDoc2", but I found that I didn't have to dim any strings. Instead of "ShowConfiguration2(ConfigName)", what I found to work was "ShowConfiguration "ConfigName".  For some reason, maybe on my part, "ShowConfiguration2" wasn't changing the cofigurations.  In the end I have achieved the end goals.

Thanks all for the input.


Regards,

Christopher Zona
Litens Automotive Partnership
Concord, Ontario, Canada

RE: Changing a config with a macro

You wont have to put parentheses around the parameter ("Configname") unless you also want to return a value:

ShowConfiguration2 "ConfigName"

success = ShowConfiguration2("ConfigName")

RE: Changing a config with a macro

In which SW version did "ShowConfiguration2" replace "ShowConfiguration"?

Which version of SW are you writing for, krywarick6 ?

RE: Changing a config with a macro

(OP)
I'm using 2004 SP3.

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