-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_doc.py
More file actions
44 lines (38 loc) · 1.38 KB
/
load_doc.py
File metadata and controls
44 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
#
# Copyright 2022 Doug Blanding (dblanding@gmail.com)
#
# This file contains the PythonOCC code for loading an OCAF document
# previously saved to file by save_doc.py
#
# Together, these two files show how to save and load an OCAF
# document from file using PythonOCC rather than C++.
# :-)
from OCC.Core.TCollection import (TCollection_AsciiString,
TCollection_ExtendedString)
from OCC.Core.TDF import TDF_Tool, TDF_ChildIterator
from OCC.Core.TDataStd import TDataStd_Integer
from OCC.Core.TDocStd import TDocStd_Application, TDocStd_Document
from OCC.Core.BinDrivers import bindrivers_DefineFormat
def get_entry(label):
"""Return entry of label"""
entry_str = TCollection_AsciiString()
TDF_Tool.Entry(label, entry_str)
entry = entry_str.ToCString()
return entry
app = TDocStd_Application()
bindrivers_DefineFormat(app)
doc = TDocStd_Document(TCollection_ExtendedString("BinOcaf"))
app.Open(TCollection_ExtendedString("/home/doug/Desktop/test.cbf"), doc)
# An integer was saved as an attribute on the root label.
root = doc.Main()
print(f"root label has entry [{get_entry(root)}]")
# Retrieve children of root
itl = TDF_ChildIterator()
itl.Initialize(root)
while itl.More():
a_child = itl.Value()
print(f"\t{get_name(a_child)} [{get_entry(a_child)}]")
itl.Next()
else:
print("No child labels were found under root")