I found an demo with chatgpt, but he has no color and the assembly structure is not correct.
If someone can share a demo with me, I'd really appreciate it !
If someone can share a demo with me, I'd really appreciate it !
C++:
#include <iostream>
#include <fstream>
#include <BRep_Builder.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <gp_Trsf.hxx>
#include <gp_Ax1.hxx>
#include <BRepBuilderAPI_Transform.hxx>
int main(int argc, char* argv[])
{
const char* input_file1 = "22.step";
const char* input_file2 = "23.step";
const char* output_file = "test.step";
STEPControl_Reader reader1, reader2;
IFSelect_ReturnStatus status1 = reader1.ReadFile(input_file1);
IFSelect_ReturnStatus status2 = reader2.ReadFile(input_file2);
if (status1 != IFSelect_RetDone || status2 != IFSelect_RetDone) {
std::cerr << "Error reading input STEP files" << std::endl;
return 1;
}
reader1.TransferRoots();
reader2.TransferRoots();
TopoDS_Shape shape1 = reader1.OneShape();
TopoDS_Shape shape2 = reader2.OneShape();
gp_Trsf trsf;
trsf.SetTranslation(gp_Vec(100, 0, 0));
trsf.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), M_PI / 4);
BRepBuilderAPI_Transform transform(shape2, trsf);
shape2 = transform.Shape();
BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
builder.Add(compound, shape1);
builder.Add(compound, shape2);
STEPControl_Writer writer;
writer.Transfer(compound, STEPControl_AsIs);
writer.Write(output_file);
std::cout << "Merged STEP file written to: " << output_file << std::endl;
return 0;
}