Removing a part from an assembly

Flare

Looking around for some CAD
Hello,

I am writing a program that is supposed to read a Step file of an assembly, remove a part from that assembly and then write separate Step files for the removed part and the original assembly but with that part removed.

I use the following code snippet to remove the part from the original assembly:

Code:
if(!ShapeTool->RemoveShape(removeL, false)){
  ShapeTool->RemoveComponent(removeL);
}
ShapeTool->UpdateAssemblies();

removeL is the label of the location of the part in the assembly.
When I write the document to a Step file however, it is still the entire assembly without the part being removed.

I have verified that ShapeTool->GetShape(removeL) is the correct shape that I want.

I would greatly appreciate any help. Thank you!

Best regards, Kaiwen

Link to same question in occt forum as reference: https://dev.opencascade.org/content/removing-part-assembly
 

Quaoar

Administrator
Staff member
Our experience with XDE was so overwhelmingly frustrating that we finally abstracted all the OCAF/XDE business to a specific "facade" class (named "Document" in Analysis Situs or "Model" in some other commercial projects we did for OCC). Here is our implementation of the part removal logic: https://gitlab.com/ssv/AnalysisSitus/-/blob/master/src/asiAsm/xde/asiAsm_XdeDoc.cpp#L2342

In this code, the PartId type is nothing but a string like "0:1:1:1" representing the entry of the corresponding part's label (you can access it with TDF_Tool::Entry()). Please note that in order to kill the part entirely, you would normally have to clean up its corresponding "original" label, not the label of the corresponding component (instance). And then, yes, you need to call this UpdateAssemblies() thingy as otherwise the corresponding part's shape would not be cleaned up from upstream compounds used by the STEP writer (you see how coupled this thing is).

This is how it works from the console of Analysis Situs:

> set workdir [pwd]; puts $workdir
> asm-xde-load -model M -filename $workdir/../data/cad/as1-oc-214.stp
> asm-xde-browse -model M
> asm-xde-remove-parts -model M -items 0:1:1:3

1682696039313.png
 
Last edited:

Flare

Looking around for some CAD
When I change my code to the following, it seemingly works:
Code:
removeL.ForgetAllAttributes();
ShapeTool->UpdateAssemblies();
Is this a valid solution? Do I need to do some cleanup to the document so it does not lead to some undefined behavior?
 

Quaoar

Administrator
Staff member
Sorry for late response. In our implementation (Analysis Situs), this "forget attributes" is used as well, so I would assume it's a legal solution.
 
Top