Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Reference Key doesn't work on Parts

0 REPLIES 0
Reply
Message 1 of 1
Naoufel_EMW
63 Views, 0 Replies

Get Reference Key doesn't work on Parts

Hi,
How do I get the reference key from Part root component when imported a part as geometry?


The method below is for parsing the bodies items for part document when imported a part as geometry , the objective is getting the reference key of the part document and the surfaces bodies that belongs to this geometry and writing an xml file that contains the part document composition:

 

-to do that we need to call the predefined method GetReferenceKey, this function works fine for any entity (such as SurfaceBody, Edge, Faces, componentoccurrence ..), but does not works when I apply it to Part Document root component ,  

I try to cast it to Componentoccurrence and apply the function to the partComponentDefinition, but nothing changes.

 

 

C# code below:

 

 

void ParseDesignBodiesForPartDoc()
        {
            byte[] abRefKey = new byte[] { };
            string PartRefKey = string.Empty;
            PartDocument PartDoc = default(PartDocument);
            PartComponentDefinition PartDocDef = null;

            PartDoc = (PartDocument)docObject;

            if (PartDoc == null)
                return;

            PartDocDef = PartDoc.ComponentDefinition;

            if (PartDocDef == null)
                return;

            ComponentOccurrences CompOccurences = PartDocDef.Occurrences;

            if (CompOccurences == null)
                return;

            //Cast part document to ComponentOccurrence to get the reference key 
            ComponentOccurrence CompOcc = (ComponentOccurrence)PartDoc; //Can raise an exception 

            if (CompOcc != null)
            {
                CompOcc.GetReferenceKey(ref abRefKey, GetContextkey()); //this method gets the reference key of entity – But doesn’t work for Part Document

                ReferenceKeyManager RefKeyManager = null;

                RefKeyManager = docObject.ReferenceKeyManager;
                PartRefKey = RefKeyManager.KeyToString(ref abRefKey);  
            }

            SurfaceBodies surfaceBodies;            

            surfaceBodies = PartDocDef.SurfaceBodies;

            int Count = surfaceBodies.Count;
         
            for (int i = 1; i <= Count; i++)
            {
                SurfaceBody surfaceBody;

                surfaceBody = surfaceBodies[i];

                string SurfaceName = surfaceBody.Name;
                string SurfaceKey = GetObjectReferecenceKey(surfaceBody); //in this case the method GetReferenceKey works fine .
            }            
        }

 

 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report