Hello everyone,I am working on exporting STEP files based on OCCT. After using STEPCAFControl_Writer to export PMI data, the exported file only contains semantic PMI but no presentation PMI. Why is this happening? Could it be due to incorrect parameter settings, missing code for exporting presentation PMI, or an incomplete OCCT module? Below is a code example:
//1.create doc
Handle(TDocStd_Document) doc;
Handle(XCAFApp_Application) app = XCAFApp_Application::GetApplication();
app->NewDocument("MDTV-XCAF", doc);
// 2. get tools
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
Handle(XCAFDoc_DimTolTool) dimTolTool = XCAFDoc_DocumentTool::DimTolTool(doc->Main());
//STEPControl_Writer aWriter;
// 3.create writer
STEPCAFControl_Writer aWriter;
//IFSelect_ReturnStatus status;
Standard_Boolean status;
TopoDS_Shape aShape;
Standard_Integer ix,ic = 0;
STEPControl_StepModelType aModel;
ExportProgStat& expStat = GetExportProgStat();
int ierr = STEPEXP_SUCCESS,nFalied = 0;
Interface_Static::SetCVal("write.step.schema", "AP242DIS");
Interface_Static::SetIVal("write.stepcaf.annot", 1);
//4. set
aWriter.SetColorMode(true);
aWriter.SetNameMode(true);
aWriter.SetLayerMode(true);
aWriter.SetDimTolMode(true); // 关键:启用PMI写入
aWriter.SetMaterialMode(true);
aWriter.SetNameMode(Standard_True);
aWriter.SetSHUOMode(Standard_True);
//5.add shape
Standard_Real x, y, z;
x = 100;
y = 50;
z = 30;
BRepPrimAPI_MakeBox box(x,y,z);
TopoDS_Shape aShape = box.Shape();
TDF_Label shapeLabel = shapeTool->AddShape(aShape, false);
// 6.add dimension
TDF_Label dimLabel = dimTolTool->AddDimension();
Handle(XCAFDimTolObjects_DimensionObject) dimObj;
Handle(XCAFDoc_Dimension) dimension;
if (dimLabel.FindAttribute(XCAFDoc_Dimension::GetID(), dimension)) {
if (!dimension.IsNull())
{
dimObj = dimension->GetObject();
Handle(TCollection_HAsciiString) sematicName = new TCollection_HAsciiString("linear");
dimObj->SetSemanticName(sematicName);
dimObj->SetType(XCAFDimTolObjects_DimensionType_Location_LinearDistance);
gp_Pnt pnt1(0, 0, 0);
gp_Pnt pnt2(100, 0, 0);
dimObj->SetPoint(pnt1);
dimObj->SetPoint(pnt2);
gp_Dir dimDir(1, 0, 0);
dimObj->SetPlane(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1)));
dimObj->SetDirection(dimDir);
dimObj->SetValue(100.0); // 尺寸值
dimension->SetObject(dimObj);
TDF_Label facelable1, facelable2;
GetYZParallelFacesLabels(doc, aShape, facelable1, facelable2);
dimTolTool->SetDimension(facelable1, facelable2, dimLabel);
status = aWriter.Transfer(doc, STEPControl_AsIs);
status = aWriter.Write(astrPath.ToCString());