Finding the name of an assembly part from a STEP file using XDE

I'm using XDE to read and translate the attached STEP file. The STEP file has a single assembly with 6 parts as components of the assembly. One of the pieces of information I'd like to get is the name of each part and I've attempted the following:

// Initialize the document
Handle(TDocStd_Document) doc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", doc);

// Read STEP data
STEPCAFControl_Reader reader;
TCollection_AsciiString path("Sample Model.STEP");
reader.ReadFile(path.ToCString());
reader.Transfer(doc);

Handle(XCAFDoc_ShapeTool) assembly = XCAFDoc_DocumentTool::ShapeTool(doc->Main());

TDF_LabelSequence freeShapes;
assembly->GetFreeShapes(freeShapes);

for (Standard_Integer freeShapeIndex = 1; freeShapeIndex <= freeShapes.Length(); ++freeShapeIndex)
{
    TDF_Label freeShape = freeShapes.Value(freeShapeIndex);

    TDF_LabelSequence components;
    assembly->GetComponents(freeShape, components, Standard_True);

    for (Standard_Integer compIndex = 1; compIndex <= components.Length(); ++compIndex)
    {
        TDF_Label compLabel = components.Value(compIndex);
        Handle(TDataStd_Name) name;
        TCollection_ExtendedString nameText;
        if (compLabel.FindAttribute(TDataStd_Name::GetID(), name))
        {
            nameText = name->Get();

            // nameText is the name of the NEXT_ASSEMBLY_USAGE_OCCURRENCE entity 
            // in the STEP file instead of the SHAPE_REPRESENTATION entity
        }
    }
}

As the comment says, the code above gets me the name of the NEXT_ASSEMBLY_USAGE_OCCURRENCE entity in the STEP file (named "NAUO1", "NAUO2", etc.), whereas I'm interested in finding the name of the SHAPE_REPRESENTATION entity for each part in the assembly. Is there another attribute or label that I need to inspect for this? I haven't been able to figure out a solution to this from looking at the documentation and the API reference for XDE and any help would be appreciated.

Attachments: 
Kirill Gavrilov's picture

The code retrieves an Instance name, while Part might have also a Product name - you can see both in CAD Assistant.
Take a look at method XCAFDoc_ShapeTool::GetReferredShape().

Ajith Subramanian's picture

Thanks for that information. I was able to get the product name by using XCAFDoc_ShapeTool::GetReferredShape()​ as you suggested.

ANIKET ANTRE's picture

Hi Ajith Subramanian,
"As the comment says, the code above gets me the name of the NEXT_ASSEMBLY_USAGE_OCCURRENCE entity in the STEP file (named "NAUO1", "NAUO2", etc.), whereas I'm interested in finding the name of the SHAPE_REPRESENTATION entity for each part in the assembly. Is there another attribute or label that I need to inspect for this? I haven't been able to figure out a solution to this from looking at the documentation and the API reference for XDE and any help would be appreciated."

I'm facing the same problem, can you please post the code snippet if you solved the problem