Writing Values (Python)

Writing Values (Python)
 1# This example shows how to update values in the database directly for a
 2# database item. It should be used only by developers who are happy modifying
 3# the impact database tables directly. This technique should be used with
 4# extreme care because it could result in invalid database records.
 5# If you wish to store database values for a working project or other open
 6# item then use IDrawing.database_values instead.
 7
 8db = impact.active_database
 9
10def DescribeItem(dbItem):
11    if dbItem.isNone():
12        return
13
14    # Note: It is important to assign dbItem.values to a local
15    # variable because otherwise we would get a new interface everytime
16    # we used dbItem.values which would return to stored values
17    values = dbItem.values
18
19    values.save("D_NOTES", "Some Notes")
20
21    # The values are upated in the database when DoUpdate is called
22    if values.do_update():
23        impact.gui.output_toolbox.add("Successfully updated drawing '" + dbItem.name + "'")
24    else:
25        impact.gui.output_toolbox.add("Error: Unable to update drawing")
26
27impact.gui.output_toolbox.clear()
28
29impact.gui.output_toolbox.add("**** Finding Project by Name 'DB Mac Test 1' ****")
30DescribeItem(db.find_item_by_name(ipDrawingType.dtProject, "DB Mac Test 1"))