Reading and Writing Values (Python)¶
Reading and Writing Values (Python)¶
1# Use the impact.gui.active_database_window when writing scripts that
2# work inside database windows. These can include scripts for buttons
3# on a database window to read/write values into the database.
4# Avoid using impact.active_drawing inside database windows because
5# the database values are sometimes cached when using database windows
6# and the impact.active_layer may not always be the layer the button belongs to
7
8# Create a local variable for the impact.gui
9g = impact.gui
10
11# Create a local variable for the output toolbox
12ot = g.output_toolbox
13
14# Clear the output toolbox
15ot.clear()
16
17# Create a local variable for the active database window
18w = g.active_database_window
19
20# Check there is an active database window
21if not w.isNone():
22
23 # Check the information being displayed is from the "ONE_UP" table
24 if w.table_name == "ONE_UP":
25
26 # load the "LENGTH" field
27 length = w.values.load( "LENGTH" )
28
29 # Display the value of the "LENGTH" field in the output toolbox
30 ot.add("Length: " + length)
31
32 # Save the OneUp area of the layer associated with the
33 # database window into the "OU_AREA" field
34 w.values.save("OU_AREA", w.layer.one_up_area)
35
36else:
37
38 # Add a message to the output toolbox
39 ot.add("There is no active database window")