Reading Related Table Values for IDatabaseItem¶
Reading Related Table Values for IDatabaseItem¶
1def var_type(value):
2 """VBScript VarType equivalent - returns numeric type code."""
3 if value is None:
4 return 1 # vbNull
5 elif isinstance(value, bool):
6 return 11 # vbBoolean
7 elif isinstance(value, int):
8 return 2 # vbInteger
9 elif isinstance(value, float):
10 return 5 # vbDouble
11 elif isinstance(value, str):
12 return 8 # vbString
13 elif isinstance(value, (datetime.date, datetime.datetime)):
14 return 7 # vbDate
15 else:
16 return 9 # vbObject
17
18# This script shows how to access addition data related to a project. This includes data in
19# child tables linked to the main drawing or layer tables.
20
21
22ui = impact.gui
23ot = ui.output_toolbox
24
25db = impact.active_database
26ad = impact.active_drawing
27
28proj_code = "P061893"
29
30
31def describe_status(status):
32 _result = None
33
34 if status == ipDatabaseTableRowStatus.dtrsUnmodified:
35 _result = "Unmodified"
36 return _result
37 elif status == ipDatabaseTableRowStatus.dtrsAdded:
38 describe_status = "Added"
39 elif status == ipDatabaseTableRowStatus.dtrsModified:
40 describe_status = "Modified"
41 elif status == ipDatabaseTableRowStatus.dtrsDeleted:
42 describe_status = "Deleted"
43
44def output_native_value(row, name):
45 v = row.load(name)
46
47 if is_empty(v):
48 ot.add(" " + str(name) + ":")
49 else:
50 ot.add(" " + str(name) + ": VarType=" + str(var_type(v)) + ", Value=" + str(v))
51
52def describe_row(r_index, row):
53
54 # each row can be identified by a GUID - but it transient and is not streamed with the drawing
55 # opening the same drawing again with stored related table data WILL produce different GUID's
56 ot.add(" Row " + str(r_index) + ", GUID: " + str(row.guid) + ", Status: " + str(describe_status(row.status)))
57
58 row.values_as_variants = True
59
60 for f_index in range(1, row.field_count + 1):
61 output_native_value(row, row.field_name(f_index))
62
63def describe_table(table):
64 relationship = table.table_relationship
65
66 ot.add("Relationship: " + str(relationship.formatted_name))
67 ot.add(" Table: " + str(table.table.name))
68 ot.add(" Row Count: " + str(table.count))
69 ot.add(" Rows Needing Update: " + str(table.needs_updating_count))
70 ot.add(" Deleted Rows: " + str(table.deleted_count))
71
72 for r_index in range(1, table.count + 1):
73 describe_row(r_index, table.item(r_index))
74
75 # alternative syntax
76 # r_index = 1
77 # for each row in table
78 # DescribeRow r_index, row
79 # r_index = r_index + 1
80 # next
81
82def describe_related_tables(data):
83 if data is None:
84 ot.add("No related data exists")
85 return
86
87 ot.add("Related Tables Data Count: " + str(data.count))
88 ot.add(" Tables Needing Update: " + str(data.needs_updating_count))
89
90 for t_index in range(1, data.count + 1):
91 describe_table(data.item(t_index))
92
93
94ot.clear()
95
96 # alternative syntax
97 # for each table in data
98 # DescribeTable table
99 # next
100
101db_item = db.find_item_by_code(ipDrawingType.dtProject, proj_code)
102
103if db_item is not None:
104 ot.add("Related Tables for Project")
105 describe_related_tables(db_item.values.related_table_values)
106
107 for layer in db_item.layers:
108 ot.add("Related Tables for " + str(layer.type) + " Layer '" + layer.name + "'")
109 describe_related_tables(layer.values.related_table_values)
110
111else:
112 ot.add("Unable to locate IDatabaseItem with code " + str(proj_code))