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