Macro to change configuration info
Macro to change configuration info
(OP)
This macro is to change the BOM options on all configurations to "User Specified Name" and set that name as a variable (custom property in the part). Trying to get this to work. Problem is the code only works if you have a configuration selected before starting the macro. If you have nothing selected, it will select the other configurations visibly, and change the setting on the active configuration. I've even tried using CurrentDoc.ShowConfiguration2 (ConfigName), it does change the active configuration, but will still only update the active configuration when the macro is ran.
CODE
Sub ConfigSetup()
Set swApp = CreateObject("SldWorks.Application")
Set CurrentDoc = swApp.ActiveDoc
Set SelMgr = CurrentDoc.SelectionManager
Set swConfMgr = CurrentDoc.ConfigurationManager
Set swConfig = swConfMgr.ActiveConfiguration
' Set Config Specific name to $PRP:"PartShtSize"$PRP:"PartBase"
PartNumber1 = "$PRP:" & """" & "PartShtSize" & """" & "$PRP:" & """" & "PartBase" & """"
ConfigCount = CurrentDoc.GetConfigurationCount
ConfigNames = CurrentDoc.GetConfigurationNames
For i = 0 To ConfigCount - 1
ConfigName = ConfigNames(i)
boolstatus = CurrentDoc.Extension.SelectByID2(ConfigName, "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
CurrentDoc.GetConfigurationByName (ConfigName)
swConfig.UseAlternateNameInBOM = True
swConfig.AlternateName = PartNumber1
Next i
End Sub
Set swApp = CreateObject("SldWorks.Application")
Set CurrentDoc = swApp.ActiveDoc
Set SelMgr = CurrentDoc.SelectionManager
Set swConfMgr = CurrentDoc.ConfigurationManager
Set swConfig = swConfMgr.ActiveConfiguration
' Set Config Specific name to $PRP:"PartShtSize"$PRP:"PartBase"
PartNumber1 = "$PRP:" & """" & "PartShtSize" & """" & "$PRP:" & """" & "PartBase" & """"
ConfigCount = CurrentDoc.GetConfigurationCount
ConfigNames = CurrentDoc.GetConfigurationNames
For i = 0 To ConfigCount - 1
ConfigName = ConfigNames(i)
boolstatus = CurrentDoc.Extension.SelectByID2(ConfigName, "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
CurrentDoc.GetConfigurationByName (ConfigName)
swConfig.UseAlternateNameInBOM = True
swConfig.AlternateName = PartNumber1
Next i
End Sub
James Spisich
Design Engineer, CSWP






RE: Macro to change configuration info
should be
Set swConfig = CurrentDoc.GetConfigurationByName(ConfigName)
-handleman, CSWP (The new, easy test)
RE: Macro to change configuration info
If I preselect a configuration then run the macro it works.
If nothing is selected, the macro will tab through the configurations as they are entered, but doesn't change anything. Immediately starting the macro after the first ran (while it now has one of the configurations selected), and it works.
Macro needs to work with nothing selected. Am I missing something with the selection object?
James Spisich
Design Engineer, CSWP
RE: Macro to change configuration info
partfile.showconfiguration configurationname
partfile is a modeldoc2, configurationname is a string
John
RE: Macro to change configuration info
CODE
CODE
There has to be something I'm missing in the hierarchy of selections using API.
James Spisich
Design Engineer, CSWP
RE: Macro to change configuration info
I think you are missing the following
Set prop = partfle.extension.customproperty manager_("configuration name" or "" for the root)
long=prop.set("prp name",prp value)
or
long=prop.add2("prp name",swcustominfotext,prpvalue)
John
RE: Macro to change configuration info
swConfig.AlternateName = PartNumber1
The calls themselves to change the property work, just only when a configuration is preselected. I'm trying to figure out why that is, and code around it. The call I was using before to set this "modeldoc2.editconfiguration" didn't need any configuration selected as it just referenced the configuration you told it to, but it would automatically rename the description to the configuration name. For part of our group, they need those descriptions for clarity, so I need to find a work-around.
James Spisich
Design Engineer, CSWP
RE: Macro to change configuration info
The think is a $PARTNUMBER.
My code activates the configuration to be edited:
bol = showconfiguration2("config name")
and then alters the $PARTNUMBER:
bol = partfle.editconfiguration3("config name","config name","","new partnumber",true)
or the help file:
Function EditConfiguration3( _
ByVal Name As String, _
ByVal NewName As String, _
ByVal Comment As String, _
ByVal AlternateName As String, _
ByVal Options As Integer _
) As Boolean
This returns configuration part numbers that are visible on the configuration feature manager and the verbage is, at least in my opinion, far less wacko than what comes with the system.
Probably am solving the wrong problem again, but its been fun.
John
RE: Macro to change configuration info
I've had the request to fix the macro so it will allow custom configuration descriptions to stay. I can see the value in why my co-worker wants the request too, I just don't know why editconfiguration3 strips the description everytime. I can understand the want for a configuration tool that will easily change the name of the configuration, but why would it touch the descriptions even if the name doesn't change?
James Spisich
Design Engineer, CSWP
RE: Macro to change configuration info
James Spisich
Design Engineer, CSWP