Get entity names from a STEP file

Quaoar

Administrator
Staff member
An interesting question was posted by one of our subscribers under Lesson 12:
Is there any way to find the name of the solids for example I want to find Body1 and Body2.
#41=MANIFOLD_SOLID_BREP('Body1',#97);
#42=MANIFOLD_SOLID_BREP('Body2',#98);
This thread is to elaborate a bit on this subject. I think I had a code snippet somewhere doing that thing, but I need to double-check it.

Here's a related question from the "official" forum:

I'm currently using "STEPCAFControl_reader" with the translation parameter "read.stepcaf.subshapes.name" set to 1 (otherwise XDE doesn't expand to sub-shapes).

I can find the names of the "MANIFOLD_SOLID_BREP" entities with ShapeTool "FindSubShape", but it returns 0 whenever there is only one sub-shape/solid body.

If there are multiple sub-shapes/solid bodies it does read the "MANIFOLD_SOLID_BREP" entity name. The only problem I have is that whenever there is only one solid body in the shape, I can only get the "CLOSED_SHELL" entity name, but not the "MANIFOLD_SOLID_BREP" entity name. I can also get the shape name buy that is not what I'm looking for.

The only thing I can think of is that if there is only one sub-shape/solid body it is not considered as a sub-shape. So my question is then how do you get the MANIFOLD_SOLID_BREP entity name.

Is there any way to find the name of the solids for example I want to find "Boss-Extrude1" and "Boss-Extrude2".

#23=MANIFOLD_SOLID_BREP('Boss-Extrude1',#45);
#78=MANIFOLD_SOLID_BREP('Boss-Extrude2',#66);
 

Quaoar

Administrator
Staff member
@Quaoar
isn't this achived using the TNaming_NamedShape attribute?
That would be true if you use the XDE reader to read a STEP file into OCAF. However, if you just need to find some entities in the file without translating them into XDE (or before doing that), there's a lower-level control over that.

Here are the full sources of a program that iterates STEP file's contents using the so-called Entity Iterator: https://gitlab.com/ssv/lessons/-/blob/master/extras_EntityNames/main.cpp

The main piece of it is as follows:

C++:
// Get STEP model.
Handle(StepData_StepModel) stepModel = reader.StepModel();
Interface_EntityIterator entIt = stepModel->Entities();

// Iterate all entities.
for ( ; entIt.More(); entIt.Next() )
{
  const Handle(Standard_Transient)& ent = entIt.Value();

  if ( ent->IsKind( STANDARD_TYPE(StepShape_ManifoldSolidBrep) ) )
  {
    Handle(StepShape_ManifoldSolidBrep)
      msb = Handle(StepShape_ManifoldSolidBrep)::DownCast(ent);

    std::cout << "Found Manifold Solid BREP with name '"
              << msb->Name()->ToCString()
              << "'" << std::endl;
  }
}

Imagine you have a STEP file with a named entity, e.g., like this:

1628708451471.png

Here is the output of the program.

1628708517152.png

Therefore, if we are looking for the shapes or other STEP entities by their specific names, we can use that Entity Iterator to perform some filtering.
 

Alex Gorbatovsky

Looking around for some CAD
Handle(StepShape_ManifoldSolidBrep) msb = Handle(StepShape_ManifoldSolidBrep):: DownCast(ent);

This code works for me, thanks.
I want to access the surfaces of this solid ( StepShape_ManifoldSolidBrep ).

Or get TopoDS_Shape from StepShape_ManifoldSolidBrep.

I found StepToTopoDS_Builder, and made code

Code:
C++:
bool ImportStep::ImportSolid(const Handle(StepShape_ManifoldSolidBrep)& msb, const Handle(Transfer_TransientProcess)& ent)
{
    StepToTopoDS_Builder StepToShape;
    StepToShape.Init(msb, ent);

    const TopoDS_Shape&  shape = StepToShape.Value();
    return true;
}

How to get Transfer_TransientProcess& ent.
 
Last edited by a moderator:

JSlyadne

Administrator
Staff member
This code works for me, thanks.
I want to access the surfaces of this solid ( StepShape_ManifoldSolidBrep ).

Or get TopoDS_Shape from StepShape_ManifoldSolidBrep.

I found StepToTopoDS_Builder, and made code

Code:
C++:
bool ImportStep::ImportSolid(const Handle(StepShape_ManifoldSolidBrep)& msb, const Handle(Transfer_TransientProcess)& ent)
{
    StepToTopoDS_Builder StepToShape;
    StepToShape.Init(msb, ent);

    const TopoDS_Shape&  shape = StepToShape.Value();
    return true;
}

How to get Transfer_TransientProcess& ent.
Hi Alex, could you please elaborate on why do you might need this Transfer_TransientProcess?
 

Alex Gorbatovsky

Looking around for some CAD
Hi Alex, could you please elaborate on why do you might need this Transfer_TransientProcess?
Thank you. I have already done the import.

void ImportCADFile::DoImportStep(cStr filePath) { Handle(TopTools_HSequenceOfShape) aSeqOfShape = new TopTools_HSequenceOfShape(); const Standard_CString aFileName = filePath; Standard_Integer status = CImportExport::ReadSTEP(aFileName, aSeqOfShape); for (int i = 1; i <= aSeqOfShape->Length(); i++) { TopoDS_Shape sh = aSeqOfShape->Value(i); TopAbs_ShapeEnum type = sh.ShapeType(); if (type == TopAbs_ShapeEnum::TopAbs_SOLID) { TopoDS_Solid sol = TopoDS::Solid(sh); ImportSolid(sol); } if (type == TopAbs_ShapeEnum::TopAbs_FACE) { TopoDS_Face curFace = TopoDS::Face(sh); ImportSurface(curFace); } if (type == TopAbs_ShapeEnum::TopAbs_COMPOUND || type == TopAbs_ShapeEnum::TopAbs_SHELL) ImportCOMPOUND(sh); } }
 
Top