Looping over components inside an assembly in C#

Top  Previous  Next

Here's an example of how to do it, assuming you already have an ASM doc:

 

 

           AssemblyComponentDefinition Definition = InvIAMDoc.ComponentDefinition;

           ComponentOccurrences Occurences = Definition.Occurrences;

 

           Debug.WriteLine ("There are " + Occurences.Count.ToString() +  " occurrences") ;

 

           foreach (ComponentOccurrence ThisOcc in Occurences)

           {

               ComponentDefinition ThisDef = ThisOcc.Definition;

               Debug.WriteLine("Found something ");

               if (ThisDef.Type == ObjectTypeEnum.kAssemblyComponentDefinitionObject)

               {

                   AssemblyComponentDefinition AsmDef = (AssemblyComponentDefinition)ThisDef;

                   Material Mat = AsmDef.DefaultMaterial;

                   AssemblyDocument AsmDoc = AsmDef.Document;

                   Debug.WriteLine("Found an assembly of " + Mat.Name + " " + AsmDoc.FullDocumentName);

               }

               if (ThisDef.Type == ObjectTypeEnum.kPartComponentDefinitionObject)

               {

                   PartComponentDefinition PartDef = (PartComponentDefinition)ThisDef;

                   PartDocument PartDoc = PartDef.Document;

 

                   Debug.WriteLine("Found an part " + PartDef.Material.Name + " " + PartDoc.FullDocumentName) ;

               }

           }

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)