Creating a TDocStd_Document from a subassembly given a label

Hey,

I'm trying to export a subassembly of a step file. The way i have been doing this, is by creating a new doc, and shapetool, and then i use shapetool->newshape.

Handle(TDocStd_Application) app = new TDocStd_Application();
Handle(TDocStd_Document) newDoc;
app->NewDocument("NewDocumentFormat", newDoc);
TDF_Label emptyShape = newShapeTool->NewShape();
Handle(XCAFDoc_ShapeTool) newShapeTool = XCAFDoc_DocumentTool::ShapeTool(newDoc->Main());
newShapeTool->AddComponent(newDoc->Main(), label, trsf);

writer.Transfer(newDoc);
writer.Write(path);

This works, but it adds the subassembly one level under the emptyShape, which is as expected. Is there any way to create a step file where "label" is the root node of my assembly?

Dmitrii Pasukhin's picture

Hello,

I need more prehistory of your task. Whay you have as an input. What you awaiting as an output and more.

But for coping shapes from one document to another or copy within one document you can use XCAFDoc_Editor::CloneShapeLabel. It is growing tool. You need to have version 7.6.3 or upper.

Best regards, Dmitrii.

martijn db's picture

Hey, in the attachments is an example assembly where im trying to export the subassembly with the name '1' (just a part in this case). Since im adding the part to the emptyShape, the root level is "Open CASCADE STEP translator 7.6.1". I would like to export the part without this top level.

capture.png is the input
capture2.png is the output

Dmitrii Pasukhin's picture

You create an assembly and would like to avoid export assembly. I think you need to use just AddShape method to add simple shape into document w/o dummy root.

If are you talking about name, you be able to give your own name this assembly.

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

Moreover, you don't need to recreate a xcaf.

STEPCAFControl_Writer has methods to export just a single TDF_Label from your origin XCAF document.

  //! Method to transfer part of the document specified by label
  Standard_EXPORT Standard_Boolean Transfer (const TDF_Label& L,
                                             const STEPControl_StepModelType mode = STEPControl_AsIs,
                                             const Standard_CString multi = 0,
                                             const Message_ProgressRange& theProgress = Message_ProgressRange());

Best regards, Dmitrii.