4 Replies Latest reply on Jan 30, 2017 8:33 AM by Jana Fischer

    Get configurations of child components relative to configuration of parent

    Jana Fischer

      I am looking for a way to retrieve the data that tells me how the configuration of a component influences the configurations of its child components.

       

      For better understanding consider the following assembly:

       

      a2Hierarchy.png

       

      The components a2 and a3 have two configurations each:

      a2 has "a2high" and "a2low",

      a3 has "a3high" and "a3low".

       

      I created the assembly in such a way that

      1. if a2 is set to "a2high" then a3 gets set to "a3high" (left picture),

      2. if a2 is set to "a2low" then a3 gets set to "a3low" (right picture),

       

      If a2 had a design table (it doesn't!), it would contain the column marked red:

      a2designTable.png

      That is the information I am looking for.

      How do I get it?

       

      IMPORTANT: I want to retrieve that information without needing to activate a configuration. I also want to avoid doing rebuilds. (Performance issues!)

       

       

      Since the data is stored in a design table (if the model has a design table), one would assume that it can be gotten via Configuration.GetParameters. But this is not the case.

       

      I attached the assembly a2, its subpart a3 and a macro that retrieves and outputs some configuration data. If you run it on a2, you can see that GetParameters (or ConfigurationManager.GetConfigurationParams, which yields the same) does not give the desired information.

        • Re: Get configurations of child components relative to configuration of parent
          Jim Sculley

          I think that simply traversing the component tree will get you what you want:

           

          public void Main()
                  {
                      AssemblyDoc aDoc = swApp.ActiveDoc as AssemblyDoc;
                      ModelDoc2 mDoc = swApp.ActiveDoc as ModelDoc2;
                      string[] configNames = mDoc.GetConfigurationNames() as string[];
                      foreach (string s in configNames)
                      {
                          Configuration c = mDoc.GetConfigurationByName(s) as Configuration;
                          Component2 rootComp = c.GetRootComponent3(true);
                          Debug.Print("------------Processing config: " + c.Name + "------------");
                          traverseComponent(rootComp);
                      }
                  }
                  private void traverseComponent(Component2 comp)
                  {
                      object[] childCompsObj = comp.GetChildren() as object[];
                      if (childCompsObj.Length > 0)
                      {
                          Debug.Print("Referenced config for " + comp.Name2 + " is: " + comp.ReferencedConfiguration);
                          foreach (object obj in childCompsObj)
                          {
                              Component2 c = obj as Component2;
                              traverseComponent(c);
                          }
                      }
                      else
                      {
                          Debug.Print("Referenced config for " + comp.Name2 + " is: " + comp.ReferencedConfiguration);
                      }
                  }
          
            • Re: Get configurations of child components relative to configuration of parent
              Jana Fischer

              No, it doesn't help me. This way, I can only get the info regarding CURRENT configurations - but I want to get info about all configurations, not just the active ones.

                • Re: Get configurations of child components relative to configuration of parent
                  Jim Sculley

                  I created a simple assembly containing three parts: CUBE.SLDPRT, SPHERE.SLDPRT and PYRAMID.SLDPRT.  Each part has two configurations: SMALL and LARGE.  The assembly itself has two configurations: SMALL and LARGE which each point at the appropriate configurations of the parts.  The output from my code above is:

                   

                  -----------------Processing config: LARGE----------------

                  Referenced config for CONFIG TEST is:

                  Referenced config for CUBE-1 is: LARGE

                  Referenced config for SPHERE-1 is: LARGE

                  Referenced config for PYRAMID-1 is: LARGE

                  -----------------Processing config: SMALL----------------

                  Referenced config for CONFIG TEST is:

                  Referenced config for PYRAMID-1 is: SMALL

                  Referenced config for CUBE-1 is: SMALL

                  Referenced config for SPHERE-1 is: SMALL

                  Both assembly configurations are processed, and the appropriate information is returned.  The output returned when using your test files is:

                   

                  -----------------Processing config: a2high----------------

                  Referenced config for a2 is:

                  Referenced config for a3-1 is: a3high

                  -----------------Processing config: a2low----------------

                  Referenced config for a2 is:

                  Referenced config for a3-1 is: a3low

                  If this is not the output you expect, you will have to explain more clearly what you want.

                    • Re: Get configurations of child components relative to configuration of parent
                      Jana Fischer

                      I am sorry - you are right, this gives me exactly what I want. Thank you.

                       

                      When I saw your answer, I just skimmed through your code and saw that you used "Component2.ReferencedConfiguration". I had tried working with "ReferencedConfiguration" before and had no success (I did not think of getting different root components for different configurations). So I immediately thought "Tried that, doesn't work!" and wrote my answer without actually reading your code.

                       

                      So thank you again, this really helps!