AnsweredAssumed Answered

Change part configuration in all assembly configurations

Question asked by Chris Griffith on Jul 7, 2020

I have a macro for editing HSS files within an assembly.  It has an HSS virtual file within an assembly and when there is only one assembly configuration it works great.  However, I'm trying to make it so that if you change the HSS part configuration with the macro that it will change it in all of the assembly configurations.  


I have a test assembly that has 3 different configurations (Test1, Test2, Test3).  What I want the code to do is get the components that you are clicked on, assign them to an array, get all the configuration names within the assembly, then go into each assembly configuration and change the components to a new configuration.  The odd thing is that the code runs and whatever assembly configuration you are in when the macro is run is the only one where the parts change configurations.  All the other ones do nothing.  Can someone help?


Set swApp = Application.SldWorks
Set SwModel = swApp.ActiveDoc
Set swSelMgr = SwModel.SelectionManager

Set swCompModel = swComp.GetModelDoc
Set swConfigMgr = SwModel.ConfigurationManager

objectCount = swSelMgr.GetSelectedObjectCount

'Making it apply it to all the assembly configurations
AssemblyName = SwModel.GetPathName
configNames = swApp.GetConfigurationNames(AssemblyName)

ReDim swComponent(objectCount)

'Gets all components and assigns them to an array.
For i = 1 To objectCount
Set swComponent(i) = swSelMgr.GetSelectedObjectsComponent3(i, 0)

'Loops through each assembly configuration to change the component configurations.
For c = 0 To UBound(configNames)
configName = configNames(c)
SwModel.ShowConfiguration2 (configName)

For i = 1 To objectCount
'Debug.Print swComponent(i).ReferencedConfiguration
swComponent(i).ReferencedConfiguration = NewConfig
'Debug.Print configName & " " & swComponent(i).Name2