DiscussionsIssue archiveData Exchange and Application Framework

Archived discussion

How to extract entity names using XCAF

Data Exchange and Application FrameworkThu, 05/15/2025 - 09:282 replies

Browse this forum
QuestionAuthor

It is a Vertex in OCC
I need to traverse it with Document. Which API should I use to get the string I selected in the image? I need to extract it

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

Maybe this can help you: https://unlimited3d.wordpress.com/2022/09/09/colored-step-model-in-occt-...
and then under the header "Exploring assembly structure"

02Commenter-2

Hello. OCC vertex do keep the entity name from STP model. To extract the name of Vertex, you need to extract the name from StepData_Model and TransferProcess.

Keeping name of vertexes is expensive operation, that is why if you need that - you need to extract it manually. Just XBF result of import is not enough.

To extract the STP entity - you need to detect TopoDS_Vertex which is your target, then extract the entity and extract all the details from that entity. But you will not take "\x06...." because it is a specific ISO coding, which we convert to UTF-8 automatically.

TopoDS_Shape Shape = ...;
const Handle(XSControl_TransferReader)& TR = WS()->TransferReader();
Standard_Integer           modrec = 1;
Handle(Standard_Transient) ent    = TR->EntityFromShapeResult(Shape, modrec);
if (ent.IsNull())
{
  modrec = -1;
  ent    = TR->EntityFromShapeResult(Shape, modrec);
}
if (ent.IsNull())
{
      modrec                               = 2;
      Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
      if (TP.IsNull())
      {
        if (silent)
          sout << "Shape " << arg1 << " : ";
        sout << "no map" << std::endl;
      }
      else
      {
        TopoDS_Shape    S0 = Shape;
        TopLoc_Location L;
        S0.Location(L);
        Standard_Integer i, nb = TP->NbMapped();
        if (!silent)
          sout << "searching in map among " << nb << " ...";
        for (i = 1; i <= nb; i++)
        {
          ent             = TP->Mapped(i);
          TopoDS_Shape sh = TransferBRep::ShapeResult(TP, ent);
          if (sh.IsNull())
          {
            ent.Nullify();
            continue;
          }
          if (XSControl_IsEqualSubShape(Shape, sh, aLevel))
            break;
          modrec = -2;
          sh.Location(L);
          if (XSControl_IsEqualSubShape(S0, sh, aLevel))
            break;
          ent.Nullify();
          modrec = 2;
        }
      }
}

Best regards, Commenter-2.