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 .
}
}