How to write an "annotation"/name to a step entity

jianbaoxia

CAD community veteran
Hi Bros, I get a face's annotation of a step entity.

Just like this:
#17 = ADVANCED_FACE('233',(#18),#32,.F.);
I get the "annotation ": 233. (I don't know it's term, and just call it "annotation ")

I get the annotation through class StepRepr_RepresentationItem.
And there is my code:


Code:
    std::string filepath = "C:\\Users\\14656\\Desktop\\Program\\Open Cascade\\Demo_LRH\\build\\box_hole.step";

    //! 1、
    STEPControl_Reader reader;
    //! 2、
    reader.ReadFile(filepath.c_str());
    //! 3、
    reader.TransferRoots();
    //! 4、
    TopoDS_Shape shape = reader.OneShape();

    Handle(XSControl_TransferReader) treader = reader.WS()->TransferReader();
    for (TopExp_Explorer exp(shape, TopAbs_FACE); exp.More(); exp.Next())
    {
        TopoDS_Shape face = exp.Current();
        Handle(Standard_Transient) entity = treader->EntityFromShapeResult(face, 1);
        Handle(StepRepr_RepresentationItem) repre = Handle(StepRepr_RepresentationItem)::DownCast(entity);
        if (!repre.IsNull())
        {
            if (!repre->Name().IsNull())
            {
                
                std::string name = repre->Name()->ToCString();
                std::cout << name<< std::endl;
            }
        }
    }

Now, there is my question, how to set the annotation and save it in .step file.
Actually, I can use the StepRepr_RepresentationItem.SetName() to set the annotation, however, it didn't saved in .step file.

The scenes is that I make a box through BRepPrimAPI_MakeBox, so I get the box's TopoDS_Shape, and then I will save it to box.step.
Meanwhile, I want to set the annotation for every face, I have no idea how to complete it.
 

Quaoar

Administrator
Staff member
Have you checked the PMI (AP242) support in OpenCascade? Does it have something to do with what you're trying to achieve?
 

jianbaoxia

CAD community veteran
@Quaoar @JSlyadne Hey, Thanks for your advices, it's helpful, I achieved it by StepRepr_RepresentationItem.SetName(),
There is my code:
Code:
STEPControl_Writer writer;
Interface_Static::SetCVal("write.step.schema", "AP203");
IFSelect_ReturnStatus status = writer.Transfer(shape_cuted, STEPControl_AsIs);
Handle(StepRepr_RepresentationItem) entityOfShape = STEPConstruct::FindEntity(writer.WS()->TransferWriter()->FinderProcess(), face);
Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString(int(hashcode_featureMap[hashcode]));
entityOfShape->SetName(name); //
Thanks for your help.
 
  • Like
Reactions: eue

jianbaoxia

CAD community veteran
@Quaoar @JSlyadne Hey, Thanks for your advices, it's helpful, I achieved it by StepRepr_RepresentationItem.SetName(),
There is my code:
Code:
STEPControl_Writer writer;
Interface_Static::SetCVal("write.step.schema", "AP203");
IFSelect_ReturnStatus status = writer.Transfer(shape_cuted, STEPControl_AsIs);
Handle(StepRepr_RepresentationItem) entityOfShape = STEPConstruct::FindEntity(writer.WS()->TransferWriter()->FinderProcess(), face);
Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString(int(hashcode_featureMap[hashcode]));
entityOfShape->SetName(name); //
Thanks for your help.
This is not best way, using XDE can be easier. 😁
 
Top