-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson10_load_doc.py
More file actions
56 lines (48 loc) · 1.72 KB
/
lesson10_load_doc.py
File metadata and controls
56 lines (48 loc) · 1.72 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
45
46
47
48
49
50
51
52
53
54
55
56
#!/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"))
reader_status = app.Open(TCollection_ExtendedString("/home/doug/Desktop/test.cbf"), doc)
print(f"{reader_status = }")
# An integer was saved as an attribute on the root label.
root = doc.Main()
print(f"root label has entry [{get_entry(root)}]")
# Any attributes attached to root?
nb_att = root.NbAttributes()
print(f"Label root has {nb_att} attribute(s) attached")
# Retrieve an attribute from a label
INT = TDataStd_Integer()
if root.FindAttribute(TDataStd_Integer.GetID(), INT):
print("Found it")
else:
print("Didn't find it")
# Retrieve children of root
itl = TDF_ChildIterator()
itl.Initialize(root)
while itl.More():
a_child = itl.Value()
print(f"\t{get_entry(a_child)} [{get_entry(a_child)}]")
itl.Next()
else:
print("No child labels were found under root")