Reading Related Table Values for ActiveDrawing¶
Reading Related Table Values for ActiveDrawing¶
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
28
29def describe_status(status):
30 _result = None
31
32 if status == ipDatabaseTableRowStatus.dtrsUnmodified:
33 _result = "Unmodified"
34 return _result
35 elif status == ipDatabaseTableRowStatus.dtrsAdded:
36 describe_status = "Added"
37 elif status == ipDatabaseTableRowStatus.dtrsModified:
38 describe_status = "Modified"
39 elif status == ipDatabaseTableRowStatus.dtrsDeleted:
40 describe_status = "Deleted"
41
42def output_native_value(row, name):
43 v = row.load(name)
44
45 if is_empty(v):
46 ot.add(" " + str(name) + ":")
47 else:
48 ot.add(" " + str(name) + ": VarType=" + str(var_type(v)) + ", Value=" + str(v))
49
50def describe_row(r_index, row):
51
52 # each row can be identified by a GUID - but it transient and is not streamed with the drawing
53 # opening the same drawing again with stored related table data WILL produce different GUID's
54 ot.add(" Row " + str(r_index) + ", GUID: " + str(row.guid) + ", Status: " + str(describe_status(row.status)))
55
56 row.values_as_variants = True
57
58 for f_index in range(1, row.field_count + 1):
59 output_native_value(row, row.field_name(f_index))
60
61def describe_table(table):
62 relationship = table.table_relationship
63
64 ot.add("Relationship: " + str(relationship.formatted_name))
65 ot.add(" Table: " + str(table.table.name))
66 ot.add(" Row Count: " + str(table.count))
67 ot.add(" Rows Needing Update: " + str(table.needs_updating_count))
68 ot.add(" Deleted Rows: " + str(table.deleted_count))
69
70 for r_index in range(1, table.count + 1):
71 describe_row(r_index, table.item(r_index))
72
73 # alternative syntax
74 # r_index = 1
75 # for each row in table
76 # DescribeRow r_index, row
77 # r_index = r_index + 1
78 # next
79
80def describe_related_tables(data):
81 ot.add("Related Tables Data Count: " + str(data.count))
82 ot.add(" Tables Needing Update: " + str(data.needs_updating_count))
83
84 for t_index in range(1, data.count + 1):
85 describe_table(data.item(t_index))
86
87
88ot.clear()
89
90 # alternative syntax
91 # for each table in data
92 # DescribeTable table
93 # next
94
95if not ad.isNone():
96 ot.add("Related Tables for Drawing")
97 describe_related_tables(ad.database_values.related_table_values)
98
99 if ad.drawing_type == ipDrawingType.dtProject:
100 for layer in ad.layers:
101 ot.add("Related Tables for " + str(layer.layer_type) + " Layer '" + layer.full_name + "'")
102 describe_related_tables(layer.database_values.related_table_values)
103
104else:
105 ot.add("Requires an impact.active_drawing")