TopoDS_Compound
Archived discussion
How to combine a set of shapes into one shape
Hello guys, I want to export a Model to a STEP file. The model is consisted of several TopoDS_Shapes. How can I combine these shapes into one shape so that the STEP file opened as one model, not as many pieces?
Waiting for your answer...
Discussion
7 archived replies
Posts are displayed in their archived order.
Thanks for your answer, I've tried to Add all shapes to a TopoDS_Compund, then exported the Compound to STEP file. When openning the STEP file in Solidworks, there is still many parts. Moving any part, it will separate from the model.
I have exactly the same question.
If you want to export into Step as one single compaund you need to update parameter
STEPCAFControl_Controller::Init();
Interface_Static::SetCVal("write.step.assembly","Off"); Best regards, Commenter-3.
Hi Dmitrii. Thanks for your answer. However, it doesn't solve the problem in my case. Setting this parameter flattens the objects hierarchy tree - the resulting step file has one root compound and all solids/shells as its children, i.e. the tree depth is 1. I need the step file to have just one shape, i.e. a tree depth of 0. Do you any ideas how to achieve that?
In that case you need to perform Boolean operation - fuse. Your goal is not related with step format.
Best regards, Commenter-3.
I did try the fuse operation via BOPAlgo_Builder, but it completely preserves the hierarchy of objects. I didn't find an option to disable that.
Here's my code:
TDF_Label top_label;
char* path;
//...
BOPAlgo_Builder builder;
std::queue<TDF_Label> queue;
queue.push(top_label);
while (!queue.empty())
{
TDF_Label label = queue.front();
queue.pop();
if (TDF_LabelSequence children_labels; XCAFDoc_ShapeTool::GetComponents(label, children_labels))
{
for (const TDF_Label &child_label : children_labels)
{
queue.push(child_label);
}
}
else if (TopoDS_Shape shape; XCAFDoc_ShapeTool::GetShape(label, shape))
{
builder.AddArgument(shape);
}
}
builder.Perform();
STEPControl_Writer writer;
writer.Transfer(builder.Shape(), STEPControl_StepModelType::STEPControl_AsIs);
writer.Write(path);
Here's the result: