Edit: This post is not up to date. The updated questions can be found here:
http://analysissitus.org/forum/index.php?threads/removing-a-part-from-an-assembly.259/
http://analysissitus.org/forum/inde...ncollection_vector’-does-not-name-a-type.258/
Hello,
I am a beginner to OCCT and programming in general and I am trying to write a cpp script that reads a STEP file, splits off a part from the model and writes two step files. One for the split off part and one for the rest of the model. Your Youtube tutorials have been very helpful for that and I am using the WriteStepWithMeta() function from Lesson 15 and the ReadStepWithMeta() function from Lesson 12.
My program looks similar to the following:
I have also attached the entire script as a file.
I encounter two problems:
-When executing the script I get the following Terminal output:
so the program does not get past the first time WriteStepWithMeta() is called.
My second problem is that although the STEP file is written, it is simply just the original STEP file I read in the first place, without the part being removed. Currently this snippet is for removing the part:
I assume this doesn't work correctly. How do I do it right?
I am on Ubuntu and using CMake to compile.
Please bear with me if my code is hard to read. As I have mentioned I am a beginner. If I can provide any more information that might be helpful , I am happy to do so.
Thank you for your responses.
http://analysissitus.org/forum/index.php?threads/removing-a-part-from-an-assembly.259/
http://analysissitus.org/forum/inde...ncollection_vector’-does-not-name-a-type.258/
Hello,
I am a beginner to OCCT and programming in general and I am trying to write a cpp script that reads a STEP file, splits off a part from the model and writes two step files. One for the split off part and one for the rest of the model. Your Youtube tutorials have been very helpful for that and I am using the WriteStepWithMeta() function from Lesson 15 and the ReadStepWithMeta() function from Lesson 12.
My program looks similar to the following:
C++:
int main(){
// Read Step file
Handle(TDocStd_Document) doc = ::ReadStepWithMeta("../cad/excavator.STEP");
// Get XDE tools
Handle(XCAFDoc_ShapeTool) ShapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
// Get root labels (shapes, colors, layers, ...)
TDF_LabelSequence roots;
ShapeTool->GetFreeShapes(roots);
// Get label of part I want to split off (this is a placeholder for illustration purpose)
TDF_label removeL = getLabelPartX();
// create new set of document and tool for the part to be split off
Handle(TDocStd_Application) appSplit = new TDocStd_Application;
BinXCAFDrivers:efineFormat(appSplit);
//
Handle(TDocStd_Document) docSplit;
appSplit->NewDocument("BinXCAF", docSplit);
//
Handle(XCAFDoc_ShapeTool) ShapeToolSplit= XCAFDoc_DocumentTool::ShapeTool( docSplit->Main() );
// Get shape from label
TopoDS_Shape shapeSplit = ShapeTool->GetShape(removeL);
// Add to document
ShapeToolSplit->AddShape(shapeSplit);
ShapeToolSplit->UpdateAssemblies();
// remove part from orignal document
if(!ShapeTool->RemoveShape(removeL)){
ShapeTool->RemoveComponent(removeL);
}
ShapeTool->UpdateAssemblies();
// Write rest parts to Step
if(!::WriteStepWithMeta(doc, "../solutions/restPart.stp")){
std::cout << "Failed to write rest part XDE document to a STEp file \n";
return 1;
}
// Write split off part to Step
if(!::WriteStepWithMeta(docSplit, "../solutions/splitPart.stp")){
std::cout << "Failed to write split part XDE document to a STEP file \n";
return 1;
}
return 0;
}
I have also attached the entire script as a file.
I encounter two problems:
-When executing the script I get the following Terminal output:
*******************************************************************
****** Statistics on Transfer (Write) ******
*******************************************************************
****** Transfer Mode = 0 I.E. As Is ******
****** Transferring Shape, ShapeType = 0 ******
** WorkSession : Sending all data
Step File Name : ../solutions/restPart.stp(30008 ents) Write Done
Segmentation fault (core dumped)
so the program does not get past the first time WriteStepWithMeta() is called.
My second problem is that although the STEP file is written, it is simply just the original STEP file I read in the first place, without the part being removed. Currently this snippet is for removing the part:
C++:
// remove part from orignal document
if(!ShapeTool->RemoveShape(removeL)){
ShapeTool->RemoveComponent(removeL);
}
ShapeTool->UpdateAssemblies();
I assume this doesn't work correctly. How do I do it right?
I am on Ubuntu and using CMake to compile.
Please bear with me if my code is hard to read. As I have mentioned I am a beginner. If I can provide any more information that might be helpful , I am happy to do so.
Thank you for your responses.
Attachments
Last edited: