Liam Cottrell
Liam Cottrell

Reputation: 11

How can I retrieve step file entity by ID with python-occ?

I have a step file that I am ingesting using python-occ. I want to retrieve all shapes that match a specific name. Currently I am reading the step as raw text and using regex to get the entity id of the shape, i.e the number at the start of the line like: #761616=OPEN_SHELL('my_name', ('761613')) ;

I am using this code to try and get the entity as an occ TopoDS_Shape, but TransferOne always returns status=False and fails to transfer the entity. Same thing happens if I use TransferList. What am I doing wrong here?

Happy to receive answers in C++, and can convert it to python code myself.

reader = STEPControl_Reader()
tr = reader.WS().TransferReader()
status = reader.ReadFile(step_file_path)
model = reader.StepModel()

if status != 1:
    raise Exception("Error reading STEP file")

document = TDocStd_Document("Doc")
shape_tool = XCAFDoc_DocumentTool.ShapeTool(document.Main())

sequence_of_transient = reader.GiveList("761616")

num_of_list = sequence_of_transient.Length()
for i in range(1, num_of_list + 1):
    entity = sequence_of_transient.Value(i)
    rank = model.IdentLabel(entity)
    status = reader.TransferOne(rank)

aTP = tr.TransientProcess()

# to get TopoDS obj from entity
aBinder = aTP.Find(entity)
aShape: TopoDS_Shape = transferbrep().ShapeResult(aBinder)

Which resulted in aShape == None, and status == False

Upvotes: 1

Views: 57

Answers (0)

Related Questions