Document Custom Columns (Python)

Document Custom Columns (Python)
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4ot.clear()
 5d = impact.active_drawing
 6
 7if (not d.isNone()):
 8    docs = d.database_item.documents
 9
10    if docs.isNone():
11        ot.add("No project document support in the database")
12    else:
13        ot.add("Project document support is enabled in this database")
14
15        count = docs.count
16        ot.add(str(count) + " documents for '" + d.full_name + "' currently in the database")
17
18        ot.add("Iterate using Item property")
19        for i in range(1, count + 1):
20            doc = None
21            try:
22                doc = docs.item(i)
23            except Exception as exc:
24                pass
25            impact.gui.output_toolbox.add(f"Failed to create object via docs.item(): {exc}")
26            ot.add("Document: '" + doc.name + "', impact.creator: " + doc.added_by.login_id + ", Size: " + doc.size + " bytes")
27            values = doc.values
28
29            for j in range(1, values.field_count + 1):
30                ot.add("Column: " + values.field_name(j) + " Value:'" + values.load(values.field_name(j)) + "'")
31            if i == 1:
32                values.save("DC_PRINTER", "My Printer")
33                values.do_update()
34        ot.add("Iterate using for each")
35        for doc in docs:
36            ot.add("Document: '" + doc.name + "', impact.creator: " + doc.added_by.login_id + ", Size: " + doc.size + " bytes")
37            values = doc.values
38
39            for j in range(1, values.field_count + 1):
40                ot.add("Column: " + values.field_name(j) + " Value:'" + values.load(values.field_name(j)) + "'")
41else:
42    ot.add("No active project")