Reading Related Table Values for IUser¶
Reading Related Table Values for IUser¶
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 user.
19# This scripts requires a USERINFO table linked to the USERS table (USERINFO.ui_userkey -> USERS.u_key)
20
21
22ui = impact.gui
23ot = ui.output_toolbox
24
25db = impact.active_database
26ad = impact.active_drawing
27
28user_id = "ADMIN"
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 (v is None or 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 if table is None:
65 ot.add("Unable to locate related table data for USERINFO table")
66 return
67
68 relationship = table.table_relationship
69
70 ot.add("Relationship: " + str(relationship.formatted_name))
71 ot.add(" Table: " + str(table.table.name))
72 ot.add(" Row Count: " + str(table.count))
73 ot.add(" Rows Needing Update: " + str(table.needs_updating_count))
74 ot.add(" Deleted Rows: " + str(table.deleted_count))
75
76 for r_index in range(1, table.count + 1):
77 describe_row(r_index, table.item(r_index))
78
79
80ot.clear()
81
82 # alternative syntax
83 # r_index = 1
84 # for each row in table
85 # DescribeRow r_index, row
86 # r_index = r_index + 1
87 # next
88
89user = db.users.item(user_id)
90
91if not user.isNone():
92 ot.add("Locating USERINFO table for User")
93
94 table_values = user.values.related_table_values
95
96 describe_table(table_values.item("USERINFO.UI_USERKEY->USERS.U_KEY"))
97
98else:
99 ot.add("Unable to locate IUser with ID " + str(user_id))
100