AnsweredAssumed Answered

change component config in inactive assembly config

Question asked by jason van clark on Jan 16, 2019
Latest reply on Jan 17, 2019 by jason van clark

I am trying to write code that changes all instances of an assembly component when a user changes the configuration of one instance of the component.  I can do this fairly easily for the active assembly configuration, but I am having trouble doing it in inactive assembly configurations.  Does anyone have any advice? 

Here's my VB.Net code.  It runs whenever a components configuration is changed.  It also (annoyingly) runs whenever a new component is added to the assembly.  Sorry there are no colors, not sure how to paste to keep them


    Private Function assemblydoc_CompChangeNotify(componentName As String, oldConfigurationName As String, newConfigurationName As String) As Integer


          'need to evaluate all components to make sure the same config of each is used in each config

        'remove the handler so I don't keep firing this function when I change component configs

        RemoveHandler iAssembly.ComponentConfigurationChangeNotify, AddressOf assemblydoc_CompChangeNotify


        'get names of all assembly configurations

        Dim configNames As Object = Document.GetConfigurationNames

        Dim activeConfig As Configuration = Document.GetActiveConfiguration

        Dim swAssy As AssemblyDoc = Document

        'get a list of the components in the active configuration

        Dim activeCompList As Object = swAssy.GetComponents(True)


        If activeCompList IsNot Nothing Then

            'get the name of the selected component minus the instance count for comparison sakes

            Dim selectedCompName As String = Left(componentName, componentName.LastIndexOf("-"))

            Dim myModelView As ModelView = CType(Document.ActiveView, ModelView)

            'turn off screen updating

            myModelView.EnableGraphicsUpdate = False

            'loop through the configs and change the configurations of the component

            For Each name As String In configNames

                'change the active assembly configuration


                'loop through the component list, find the components and change the config

                For Each comp As Component2 In activeCompList

                    Dim compName As String = path.GetFileNameWithoutExtension(comp.GetPathName)

                    If compName = selectedCompName AndAlso comp.Name2 <> componentName Then

                        comp.ReferencedConfiguration = newConfigurationName

                    End If




            'turn off screen updating

            myModelView.EnableGraphicsUpdate = True


        End If


        AddHandler iAssembly.ComponentConfigurationChangeNotify, AddressOf assemblydoc_CompChangeNotify

    End Function