Writing Layer Values (Python)

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