8 Replies Latest reply on Sep 7, 2016 10:24 AM by Keith Rice

    Get Child Component

    Di Anne

      Hi SW Community, Artem Taturevich, Deepak Gupta, Keith Rice


      Im am currently working on a macro that will get all the components inside a sub-assembly..

      But I need to get them on how they are arranged in the assembly.

      So I used the Feature function, but when I get the component inside the sub assembly I cannot

      cast it to component even though I already check if its component or not.


      Here's my code.

      Feature swFeat = (Feature)swModel.FirstFeature();


      while((swFeat != null)\
           Entity entity = (Entity)swFeat;
           // check if component
           if (entity.GetType() == (int)swSelectType_e.swSelCOMPONENTS)
                Component2 comp = (Component2)swFeat.GetSpecificFeature2();
                if (!comp.ExcludeFromBOM & !comp.IsSuppressed())
                     Feature swSubFeat =  (Feature)((ModelDoc2)comp.GetModelDoc2()).FirstFeature();
                     while ((swSubFeat!= null))
                          if (((Entity)swSubFeat).GetType() == (int)swSelectType_e.swSelCOMPONENTS)
                               /// I have a problem in casting the swSubFeat into component
                               Component2 subComp = (Component2)swSubFeat.GetSpecificFeature2();
                          swSubFeat= (Feature)swSubFeat.GetNextSubFeature();
           swFeat = (Feature)swFeat.GetNextFeature();



      Does anyone know why I cant cast the swSubFeat into component even though I already checked if the feature is component or not?



      Thanks in advance.