Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Macro to change configuration info

Status
Not open for further replies.

DesignerGuy16

Mechanical
Jun 18, 2008
303
0
0
US
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

James Spisich
Design Engineer, CSWP
 
Replies continue below

Recommended for you

CurrentDoc.GetConfigurationByName (ConfigName)

should be

Set swConfig = CurrentDoc.GetConfigurationByName(ConfigName)

-handleman, CSWP (The new, easy test)
 
That makes sense, but it still isn't working right.

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
 
I think you need to activate the configuration you want to play with. The rather bizzarre command for this (at least the only one I have found) is
partfile.showconfiguration configurationname

partfile is a modeldoc2, configurationname is a string

John
 
Here's the oddity with that, I have tried the same code using that, but it reacts the same way, it will step through and change each configuration, but not change the property. If I preselect (just click, not activate) a configuration, the macro will work using either:

Code:
Set swConfig = CurrentDoc.GetConfigurationByName(ConfigName)
or
Code:
CurrentDoc.ShowConfiguration2 (ConfigName)

There has to be something I'm missing in the hierarchy of selections using API.

James Spisich
Design Engineer, CSWP
 
Ok, I am dense.

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
 
I have the macro doing all sorts of custom properties already. This section of my macro is specifically to change the configuration "Bill of Material Options" to "User Specified Name" (that's the swConfig.UseAlternateNameInBOM), and to set that name to a variable using:
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
 
Ok, I think I get it. My stuff has fastener files which, for a lot of reasons that appeared good at the time, are labeled 1,2,3... I ran into the same problem, really wanted to know what it was by just looking at the config labels.

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
 
I was using editconfiguration3 before, and it worked for what it was doing. The downside is, if you change the configuration description to anything that isn't the configuration name, and run editconfiguration3 on it, it will rename the configuration description to the configuration name.

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
 
Found a work-around for it. Ended up having to do the recursive selection and setting three times consecutively for it to propagate properly. Not pretty, but it works.

James Spisich
Design Engineer, CSWP
 
Status
Not open for further replies.
Back
Top