Writing Layer Values

Writing Layer Values
 1# This example shows how to update values in the database directly for a
 2# database item layer. 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 layer in a working project
 6# then use ILayer.database_values instead.
 7
 8
 9db = impact.active_database
10
11
12def describe_item(db_item):
13    if db_item is None:
14        return
15
16    # Use the first layer a project always has at least one
17    layer = db_item.layers(1)
18
19    # Note: It is important to assign layer.values to a local
20    # variable because otherwise we would get a new interface everytime
21    # we used layer.values which would return to stored values
22    values = layer.values
23
24    # You can write extra layer columns directly
25    values.save("HEIGHT", 100.00)
26
27    # You must qualify LAYERS columns
28    values.save("LAYERS.L_DESCRP", "A new layer description")
29
30    # The values are upated in the database when DoUpdate is called
31    if values.do_update():
32        impact.gui.output_toolbox.add("Successfully updated layer '" + layer.name + "'")
33    else:
34        impact.gui.output_toolbox.add("Error: Unable to update drawing layer")
35
36
37impact.gui.output_toolbox.clear()
38
39impact.gui.output_toolbox.add("**** Finding Project by Name 'DB Mac Test 1' ****")
40describe_item(db.find_item_by_name(ipDrawingType.dtProject, "DB Mac Test 1"))