I have renamed a configuration in and assembly. I created a derived configuration. Now I want to make my parent configuration my active configuration. Just can't get there from the derived configuration?

I tried a number of thing. Most of them commented out, ended up using the name to activate the configuration.

I am using SW2011.

There should be a way to get to the parent configuration from the derived configuration even if it means, just moving back up the ladder?

'Sets the active configuration to the named title

'MyConfigurationName = swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

'swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name = swApp.ActiveDoc.GetTitle() & " - Open"

Debug.Print swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

'Rename Active Configuration

swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name = swApp.ActiveDoc.GetTitle() & " - Open"   ', "", "", 1, swConf.Name, swApp.ActiveDoc.GetTitle())

                                                                '(swApp.ActiveDoc.GetTitle() + " - Closed", "", "", 1, swConf.Name, swApp.ActiveDoc.GetTitle())

'Get Active Configuration

Set swConfig = swModel.GetConfigurationByName(swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name)

MyConfigurationName = swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

Debug.Print "My Config :" & MyConfigurationName

'Set swDerivConf = swConfMgr.AddConfiguration(swConf.Name + " Config Name Addition", "Configuration Comment", "User Specified Name BOM", 1, swConf.Name[Parent Configuration], "Configuration Description")

'Add a Derived Configuration

Set swDerivConf = swConfMgr.AddConfiguration(swApp.ActiveDoc.GetTitle() + " - Closed", "", "", 1, swConfig.Name, swApp.ActiveDoc.GetTitle())

'

swModel.ShowConfiguration2 (MyConfigurationName)

Debug.Print swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

End Sub

SolidworksApi macros
Answers 6
SF
SF 2015-09-02 Best Answer

Dim instance As IConfiguration

Dim value As Configuration

value = instance.GetParent()

2011 api - GetParent Method (IConfiguration)

BP
BP 2015-09-03

Thanks Leon:

But I'm a little confused as to what goes where. Your tag to the program shows "Set parentConfig = config.GetParent"; Why would you want parentConfig if your trying to get config.GetParent? And in you example value and instance is which?

So your in the derived configuration and you want to get to it's parent, do you need to what the parent name is?

SF
SF 2015-09-03

     I'm sorry, but I'm not really understanding what you are trying to achieve.

     Are you on a child configuration and are trying to get to it's parent configuration?

     Check out this example:

2012 SOLIDWORKS API Help - Traverse Hierarchy of Configurations Example (VBA)

BP
BP 2015-09-03

Here is what I am trying to do.

In a blank assembly template.

I am trying to rename the first configuration. (i.e. to 'sample - open')

Create a derived configuration. (i.e. sample - closed).

And set it back to the first configuration, or parent (i.e. sample - open)

Shouldn't be that hard right?

The code works but, I have to change the configuration into a string and then show it.

swModel.ShowConfiguration2 (MyConfigurationName)

Code:

Sub AddConfiguration()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim vConfigNameArr As Variant

Dim vConfigName As Variant

Dim swActiveConf As SldWorks.Configuration

Dim swConfig As SldWorks.Configuration

Dim swCurrentConf As SldWorks.Configuration

Dim swConfMgr As SldWorks.ConfigurationManager

Dim swDerivConf As SldWorks.Configuration

Dim bRet As Boolean

Dim swParentConf As String

Dim MyConfigurationName As String

Dim swComp As SldWorks.Component2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swParentComp As SldWorks.Component2

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swConfMgr = swModel.ConfigurationManager

    Set swConfig = swConfMgr.ActiveConfiguration

   

    If swModel Is Nothing Then

            MsgBox "Sorry! Need an active part or assembly to function." & vbCrfLf & _

                    "Please open a part or assembly."

    End

    End If

    If swModel.GetType = swDocDRAWING Then

            MsgBox "Sorry! Need an active part or assembly to function." & vbCrfLf & _

                    "Please open a part or assembly."

    End

    End If

'Sets the active configuration to the named title

'MyConfigurationName = swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

'swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name = swApp.ActiveDoc.GetTitle() & " - Open"

Debug.Print swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

'Rename Active Configuration

swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name = swApp.ActiveDoc.GetTitle() & " - Open"   ', "", "", 1, swConf.Name, swApp.ActiveDoc.GetTitle())

                                                                '(swApp.ActiveDoc.GetTitle() + " - Closed", "", "", 1, swConf.Name, swApp.ActiveDoc.GetTitle())

'Get Active Configuration

Set swConfig = swModel.GetConfigurationByName(swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name)

MyConfigurationName = swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

Debug.Print "My Config :" & MyConfigurationName

'Set swDerivConf = swConfMgr.AddConfiguration(swConf.Name + " Config Name Addition", "Configuration Comment", "User Specified Name BOM", 1, swConf.Name[Parent Configuration], "Configuration Description")

'Add a Derived Configuration

Set swDerivConf = swConfMgr.AddConfiguration(swApp.ActiveDoc.GetTitle() + " - Closed", "", "", 1, swConfig.Name, swApp.ActiveDoc.GetTitle())

'

'swModel.ShowConfiguration2 (MyConfigurationName)

Debug.Print swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name

End Sub

'----------------------------------------------

SF
SF 2015-09-03

    But you already have the "Open" configuration name set in a string variable (MyConfigurationName), you should just use a command to show it:

<p><span style="color: #e23d39; font-family: 'courier new', courier;"> swModel.ShowConfiguration2 MyConfigurationName</span></p><p></p><p><span style="font-family: 'courier new', courier;">    Debug.Print swApp.ActiveDoc.ConfigurationManager.ActiveConfiguration.Name</span></p><p></p><p><span style="font-family: 'courier new', courier;">End Sub</span></p>
BP
BP 2015-09-03

Thanks I guess that just the way I’ll have to go. Was hope there was a way, not to have to fish out the name of the configuration, but guess not.

Thank you