Reading Simple Database Values¶
Reading Simple Database Values¶
1# This script demonstrates how simple database values (strings, doubles) may be read
2# from the current drawing and the current layer.
3
4# The results will be written to the Output Toolbox
5ot = impact.gui.output_toolbox
6
7# First check that there is a drawing open
8if impact.active_drawing.isNone():
9 ot.add("There is no drawing open")
10
11else:
12
13 # D_NOTES is a memo field, so we will always get a string value
14 notes = impact.active_drawing.database_values.load("D_NOTES")
15 ot.add("Notes: " + str(notes))
16
17 # Here we explicitly use an object to help us read the layer values because
18 # we are going to read multiple values, so this is more efficient.
19 layer_vals = impact.active_drawing.active_layer.database_values
20
21 # We are going to read one-up values, so we need to check we have a
22 # suitable layer first, otherwise we will get an error.
23 if impact.active_drawing.active_layer.layer_type == "ONE_UP":
24
25 # From impact 11.0 onward, we can request appropriate data types (like integers, doubles, booleans).
26 # Otherwise all values would be returned as strings, which is often not ideal.
27 layer_vals.values_as_variants = True
28
29 blank_x = layer_vals.load("BLANKX")
30 ot.add("BlankX: " + str(blank_x))
31
32 blank_y = layer_vals.load("BLANKY")
33 ot.add("BlankY: " + str(blank_y))
34
35 # If we are not sure what data type we have been given, we can use the
36 # VBScript VarType or TypeName functions to check what we have.
37 ot.add("The data type is: " + str(type(blank_y)))
38
39 else:
40 ot.add("This layer is not a one-up")
41
42 # Return to the earlier pre-11.0 behaviour
43 layer_vals.values_as_variants = False
44
45 # L_VERSION is an integer value, but now we will get a string value.
46 # Also note that we have to include "LAYERS." in the field name because this field
47 # is in the LAYERS table, not ONE_UP or MULTI_UP tables.
48 layer_version = layer_vals.load("LAYERS.L_VERSION")
49 ot.add("version: " + str(layer_version))
50 ot.add("The data type is: " + str(type(layer_version)))