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,
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
To work with configs, you need to start with the Configuration Manager object.
RE: Changing a config with a macro
"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
Christopher Zona
Litens Automotive Partnership
Concord, Ontario, Canada
RE: Changing a config with a macro
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
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
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
RE: Changing a config with a macro
ShowConfiguration2 "ConfigName"
success = ShowConfiguration2("ConfigName")
RE: Changing a config with a macro
Which version of SW are you writing for, krywarick6 ?
RE: Changing a config with a macro