Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Changing a config with a macro

Status
Not open for further replies.

krywarick6

Automotive
Jun 9, 2003
138
0
0
CA
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
 
Replies continue below

Recommended for you

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.
 
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.
 
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
 
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.
 
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.
 
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
 
You wont have to put parentheses around the parameter ("Configname") unless you also want to return a value:

ShowConfiguration2 "ConfigName"

success = ShowConfiguration2("ConfigName")
 
Status
Not open for further replies.
Back
Top