How to add names to STEP or IGES file?

Does anyone have an example or hints on how to add names/labels to parts of a STEP and/or IGES file (e.g. TopoDS_Shape elements)? I wasn't able to find an example with a forum search.

I've been able to read them (as shown in code below), but I don't know how to associate names with shapes when writing a STEP/IGES file.

////////////////////////////////////////////////////////////////////////////////
// Dump labels of STEP model.
void dumpStepLabels(STEPControl_Reader reader)
{
const Handle(XSControl_WorkSession) & theSession = reader.WS();
const Handle(Interface_InterfaceModel) & theModel = theSession->Model();

Standard_Integer nb = theModel->NbEntities();
for(Standard_Integer i=1; i {
Handle(StepRepr_Representation) entity = Handle(StepRepr_Representation)::DownCast(theModel->Value(i));
if(entity.IsNull())
{
continue;
}
if(entity->Name().IsNull())
{
continue;
}
cout Name()->ToCString() }
}

////////////////////////////////////////////////////////////////////////////////
// Dump labels of IGES model.
void dumpIgesLabels(IGESControl_Reader reader)
{
const Handle(XSControl_WorkSession) & theSession = reader.WS();
const Handle(Interface_InterfaceModel) & theModel = theSession->Model();

Standard_Integer nb = theModel->NbEntities();
for(Standard_Integer i=1; i {
Handle(IGESData_IGESEntity) entity = Handle(IGESData_IGESEntity)::DownCast(theModel->Value(i));
if(entity.IsNull())
{
cout }
if(entity->HasName())
{
cout NameValue()->String().ToCString() }
}
}

Forum supervisor's picture

Hi Ben,

The high level API to translate shapes with attached attributes (such as names, colors etc.) is called XDE (eXtended Data Exchange), and it is a part of Open CASCADE Technology. XDE uses OCAF documents to store the complete model that includes shapes and the attached attributes. You can read more about XDE in the corresponding Users Guide available as %CASROOT%\doc\pdf\user_guides\occt_xde.pdf.

Since you only need a small sub-set of XDE functionality (to only deal with names), you might also work directly with the standard level of the interfaces, attaching the names directly to the entities in the model, prior to writing it to the resulting IGES or STEP file. You may consult the source code of the classes IGESCAFControl_Writer and STEPCAFControl_Writer, in particular, the methods:

IGESCAFControl_Writer::WriteNames
STEPCAFControl_Writer::WriteNames

to get an idea of how to implement that.

Best regards,
Forum Supervisor

Ben Cain's picture

As seen in the attache image, I was able to properly name parts for STEP and IGES format files.

See:

TDocStd_Document
XCAFApp_Application
XCAFDoc_ShapeTool

TDF_Label XCAFDoc_ShapeTool::AddShape(const TopoDS_Shape & S, const Standard_Boolean makeAssembly=Standard_True, const Standard_Boolean makePrepare=Standard_True);

Handle_TDataStd_Name TDataStd_Name::Set(const TDF_Label & label, const TCollection_ExtendedString & string);

Attachments: 
Rolf Bronstering's picture

Has anybody ever succeeded in creating IGES files with names longer than 8 chars? The only approach to this I've found so far

IGESCAFControl_Writer writer;

....

TopoDS_Shape shape = ...

Handle(Transfer_FinderProcess) fp = writer.TransferProcess();
Handle(IGESData_IGESEntity) igsent;
Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(fp, shape);
if (fp->FindTypedTransient (mapper, STANDARD_TYPE(IGESData_IGESEntity), igsent)) {
          //Add name
          Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString("a_longer_name");
          Handle(IGESBasic_Name) nameEntity = new IGESBasic_Name();
          nameEntity->Init(1, name);
          igsent->AddProperty(nameEntity);

 }

...

writer.Write("file.igs);

does not produce any name in the written IGES file.

Forum supervisor's picture

Hello Rolf,

The current implementation of Open CASCADE IGES interface allows 8-character names, according to IGES standard version 5.3.

Best regards,

Forum supervisor

Martin Siggel's picture

Dear Rolf,

I found a way to add long IGES names (406 entities) to the export. Your code is correct but missing a small piece:

TopoDS_Shape shape = ...

Handle(Transfer_FinderProcess) fp = writer.TransferProcess();
Handle(IGESData_IGESEntity) igsent;
Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper(fp, shape);
if (fp->FindTypedTransient (mapper, STANDARD_TYPE(IGESData_IGESEntity), igsent)) {
          // Set short name (max 8 chars)
          igesent->SetLabel(new TCollection_HAsciiString("SHRTNAME"));

          //Add long name
          Handle(IGESBasic_Name) nameEntity = new IGESBasic_Name();
          nameEntity->Init(1, new TCollection_HAsciiString("a_longer_name"));
          igsent->AddProperty(nameEntity);
          // THIS LINE is important, else the names won't be written
          writer.Model()->AddEntity(nameEntity);

 }

...

writer.Write("file.igs);

It took me quite long to figure this out by my own. I hope this helps everyone struggeling with IGES names.

Best regards,

Martin

Chetan Jois's picture

Hi Ben,

I just want to know which CAD viewer you are using to visualize the IGES CAD file in the image you uploaded. I am able to add labels manually to IGES files but commercial software ignores it. I am very new to Open Cascade and C++ in general and do not know how to use Open Cascade properly. It would be really helpful if you told me about labeling entities in IGES in any software.

It might be too much to ask but if possible can you upload a cube with all faces labeled.

PS I tried searching for labels in IGES but somehow this was the only thread that came up. I have attached your CAD image for reference and also a cube in case you choose to name the faces.

Thank You