How to merge two TopoDS_Shape

I have several TopoDS_Shape, some of them read from step files, other programaticaly built, and I need to save the drawing as a step file. The problem I have is that the program which will use that file needs a step file containing one shape.
I cannot user TopoDS_Builder::Add(shape1, shape2), because the constructor is protected. I have extended the class TopoDS_Builder with a public constructor, and used it something like this:

Handle(TopTools_HSequenceOfShape) shape_list
My_TopoDS_Builder aBuilder;
TopoDS_Shape shape1 = shape_list->Value(1);

IFSelect_ReturnStatus status;
Standard_Integer n = shape_list->Length();
for (Standard_Integer i=2; i TopoDS_Shape aShape = shape_list->Value(i);
aBuilder.Add(shape1, aShape);
status = aWriter.Transfer(shape1, STEPControl_ManifoldSolidBrep);

but at the last line, the processor jumps in 100% and stays there for an indefinite period of time (I left it over a half hour).

I think I've taken the wrong aproach, but I've run out of ideas. Can you give me an advice?

Francois Lauzon's picture

you might try to regroup all your shapes into a TopoDS_Compound (it's kind of a topological group), you can do something like this:

TopoDS_Compound aCompound;
BRepBuilder aBuilder;

// then add all your shape

// then used the compound to write your step file
STEPControl_Writer aWriter;
IFSelect_ReturnStatus retStatus=aWriter.Transfer(aCompound,STEPControl_AsIs);
Standard_Boolean ok=aWriter.Write(aFilename);

That how we do it here,
good luck,

mihaim's picture

Thank you, that was exactly what I needed.

mamadou sy's picture


I am having an error:
error C2065: 'testmamadou' : undeclared identifier
Could you please assist:

Here is my sample code:

TopoDS_Compound aCompound;
BRep_Builder aBuilder;
STEPControl_Writer aWriter;
IFSelect_ReturnStatus retStatus=aWriter.Transfer(aCompound,STEPControl_AsIs);
Standard_Boolean ok=aWriter.Write(testmamadou);

File name is 'testmamadou'

m-aronsson's picture

No we cannot assist, the problem is that the variable 'testmamadou' is not declared or defined in the code snippet you posted, if that is all the code then that is the reason for the error, otheriwse you have to include the rest of the code also.