For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Export multi Shapes into single STEP file

Malcolm Revenge's picture
Forums: 

Guys, i'm new in OCC :-) Is here any way to export, for example, 100 shapes in single STEP file?

qa qa's picture

Hello, Malcolm

Yes, you can put all your shapes in TopoDS_Compound shape which is a container shape. After that you can dump it to a single file

qa qa

Malcolm Revenge's picture

Thank you again, but can you show me a little bit of code? :-) Just simple examaple for exporting two shapes? :-)

qa qa's picture

Hello,

Here it is:

  // Input shapes.
  TopoDS_Shape aShape1 = ...;
  TopoDS_Shape aShape2 = ...;

  // Create new compound and make it valid.
  BRep_Builder aB;
  TopoDS_Compound aResComp;
  aB.MakeCompound(aResComp);

  // The arguments order is: where to add, what to add.
  aB.Add(aResComp, aShape1);
  aB.Add(aResComp, aShape2);

  // Write resulting compound to the file.
  STEPControl_Writer aWriter;
  IFSelect_ReturnStatus aStat = aWriter.Transfer(aResComp,STEPControl_AsIs);
  aStat = aWriter.Write("D:/res.stp");
  if(aStat != IFSelect_RetDone)
    cout << "Writing error" << endl;

qa qa

Malcolm Revenge's picture

Thanks body, I already found the right section of code on the Internet...And understood how this is done, but for some reason, nothing works)) If the shape is one, then everything is OK, if there are several shapes and the vertices of these figures in global coordinates are not a distance from each other - an error of SolidWorks import...

Malcolm Revenge's picture

Dear qa qa, I wrote a small piece of test code for testing the export to STEP, I tried all the transfer modes, nothing could help me. When I open this file in SolidWorks, I see a blank screen ... I want to see in Solidvorks a model with two solid bodies, that is, with two cubes ... Yes, I do not care, that it would be solid bodies, maybe even surface ... What do I do wrong so damn it? :-)

BRepPrimAPI_MakeBox boxMaker1(gp_Pnt(-10, 0, -10), gp_Pnt(-5, 10, -5));
TopoDS_Shape box1 = boxMaker1.Shape();

BRepPrimAPI_MakeBox boxMaker2(gp_Pnt(10, 0, 10), gp_Pnt(5, 10, 5));
TopoDS_Shape box2 = boxMaker2.Shape();

BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
builder.Add(compound, box1);
builder.Add(compound, box2);

STEPCAFControl_Writer writer;
Handle(TDocStd_Document) document;
document = new TDocStd_Document("Demo STEP");
Handle(XCAFDoc_ShapeTool) shapeTool;
shapeTool = XCAFDoc_DocumentTool::ShapeTool(document->Main());
shapeTool->AddShape(compound, Standard_True);
writer.Transfer(document, STEPControl_AsIs);
writer.Write("C:/000-demo/demo1.stp");

Malcolm Revenge's picture

I also tried to make an export without a document, as you said, also does not work, in SolidWorks a blank screen, what could be the problem? :(

BRepPrimAPI_MakeBox boxMaker1(gp_Pnt(-10, 0, -10), gp_Pnt(-5, 10, -5));
TopoDS_Shape box1 = boxMaker1.Shape();

BRepPrimAPI_MakeBox boxMaker2(gp_Pnt(10, 0, 10), gp_Pnt(5, 10, 5));
TopoDS_Shape box2 = boxMaker2.Shape();

BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
builder.Add(compound, box1);
builder.Add(compound, box2);

STEPControl_Writer writer;
writer.Transfer(compound,STEPControl_AsIs);
writer.Write("C:/000-demo/demo1.stp");

Qr Qr's picture

Have you had a look inside the produced STEP file? Is there something in it? Can you check it with CAD Assistant (https://www.opencascade.com/content/cad-assistant)?

qa qa's picture

Hello Malcolm,

I don't have SolidWorks. I can say only that everything is OK from OCCT point of view.

qa qa

Malcolm Revenge's picture

Have you had a look inside the produced STEP file? Is there something in it?

Yes, of course, I looked inside the file, it's big, there's a lot of everything :-) Look, this code generates this STEP file, which I attached to the attachment of this post, what's wrong with it?

BRepPrimAPI_MakeBox boxMaker1(gp_Pnt(-10, 0, -10), gp_Pnt(-5, 10, -5));
TopoDS_Shape box1 = boxMaker1.Shape();

BRepPrimAPI_MakeBox boxMaker2(gp_Pnt(10, 0, 10), gp_Pnt(5, 10, 5));
TopoDS_Shape box2 = boxMaker2.Shape();

BRep_Builder builder;
TopoDS_Compound compound;
builder.MakeCompound(compound);
builder.Add(compound, box1);
builder.Add(compound, box2);

STEPControl_Writer writer;
writer.Transfer(compound,STEPControl_AsIs);
writer.Write("C:/000-demo/demo1.stp");

I don't have SolidWorks. I can say only that everything is OK from OCCT point of view.

I checked this file with this CAD Assistant, yes, that's right, it opens normally, but I think it's only because CAD Assistant uses the same Open Cascade tehneque for import, that is, he's like a native to cascade, that's why he opens it , But the third-party software can't open it unfortunately ... I think that there must be some correct structure in the STEP file, maybe some meta data, that it would open correctly ... Any ideas?

P.S.: IGES files from OCC opening normal in SolidWorks, porblems with STEP files only...

In SolidWorks there is a module of viewing of files of various types, called eDrawigns, well and so, it opens normally, does not open only itself SolidWorks. I think that the STEP file should be as it is correctly designed, perhaps these shapes should be represented as solid bodies or surfaces ... How i can export the shape to STEP as solid body?

Attachments: 
qa qa's picture

Malcolm,

I have successfully opened attached shape in "onShape" system.  Everything is OK with this file. Only one thing that I can say: please, use licensed software. It seems you use cracked software.

qa qa

Malcolm Revenge's picture

 It seems you use cracked software.

:-)  

Hacked software for nothing worse than licensing, I tell you this as a hacker)))