I'm struggling to read presentation layer assignments out of an AP214 STEP CAD file with pythonocc. The file will read in, but I only get 1 shape and I'm not sure how to access any other attributes of the OCC.TopoDS.TopoDS_Shape object. I tried to go through the c++ from OCE but unfortunately my c++ is rusty and I failed to find anything helpful
I have lines at the end of the file like the following that assign the properties I'd like to use:
#27092=PRESENTATION_LAYER_ASSIGNMENT('PROPERTY001','PROPERTY001|ANSA_Thick=1.',(#587));
#27093=PRESENTATION_LAYER_ASSIGNMENT('PROPERTY002','PROPERTY002|ANSA_Thick=1.',(#24235));
Where PROPERTY001 and PROPERTY002 are the names of the properties I need to keep.
Ultimately what I'm looking to do is read in a STEP file, apply a mesh to the surface, and output an STL file while maintaining the property definitions such that the output STL file has multiple solids that correspond to each presentation_layer_assignment property from the input STEP file.
I'm using pythonocc-0.6a and OCEv11
Does anyone have any experience with this or suggestions? Thanks
In modern PythonOCC the correct way to read a STEP file is using STEPCAFControl_Reader instead of the basic reader:
from OCC.Core.XCAFApp import XCAFApp_Application
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.TCollection import TCollection_ExtendedString
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool_ShapeTool
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
from OCC.Core.TDF import TDF_LabelSequence
from OCC.Core.IFSelect import IFSelect_RetDone
app = XCAFApp_Application.GetApplication()
doc = TDocStd_Document(TCollection_ExtendedString("MDTV-XCAF"))
app.InitDocument(doc)
reader = STEPCAFControl_Reader()
reader.SetColorMode(True)
reader.SetNameMode(True)
reader.SetLayerMode(True) # enables layer reading
reader.ReadFile("your_file.step")
reader.Transfer(doc)
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
free_shapes = TDF_LabelSequence()
shape_tool.GetFreeShapes(free_shapes)
for i in range(1, free_shapes.Length() + 1):
label = free_shapes.Value(i)
print(label.GetLabelName()) # prints part/assembly name
Note: This is modern PythonOCC syntax, your version pythonocc-0.6a is very old so some APIs may differ.
Tested with pythonocc-core 7.4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With