如何在 OpenCASCADE 中导出 STEP 文件
我的 OCCUtils 库提供了将你的 TopoDS_Shape 导出为 STEP AP203 文件的超简单方法:
export_step_example.cpp
#include <occutils/STEPExport.hxx>
using namespace OCCUtils;
TopoDS_Shape myShape = /* ... */;
STEP::ExportSTEP(myShape, "myShape.step");如果你想手动操作,正确做要复杂得多,但这里是基本步骤:
export_manual.cpp
STEPControl_Writer writer;
writer.Transfer(shape, STEPControl_AsIs);
writer.Write(filename.c_str());OCCUtils 中完整的 STEP::ExportSTEP 代码是:
export_full.cpp
if (shape.IsNull () == true) {
throw new invalid_argument("Can't export null shape to STEP");
}
STEPControl_Writer writer;
Interface_Static::SetCVal ("xstep.cascade.unit", unit.c_str());
Interface_Static::SetCVal ("write.step.unit", unit.c_str ());
Interface_Static::SetIVal ("write.step.nonmanifold", 1);
// "Transfer" = 转换
IFSelect_ReturnStatus transferStatus = writer.Transfer(shape, STEPControl_AsIs);
if (transferStatus != IFSelect_RetDone) {
throw std::logic_error ("Error while transferring shape to STEP");
}
// 将转换的结构写入 STEP 文件
IFSelect_ReturnStatus writeStatus = writer.Write(filename.c_str());
// 返回之前的区域设置
if (writeStatus != IFSelect_RetDone)
{
throw std::logic_error ("Error while writing transferred shape to STEP file");
}Check out similar posts by category:
C/C++, OpenCASCADE
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow