AnsweredAssumed Answered

Get Child Component

Question asked by Di Anne on Sep 2, 2016
Latest reply on Feb 12, 2019 by Keith Rice

Hi SW Community,


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.