Application globals

Application globals
 1# this example adds (or replaces) some application impact.globals
 2# and displays them in the output toolbox
 3
 4# create a local variable for the application impact.globals
 5application_globals = impact.globals
 6
 7# create a local variable for the output toolbox
 8ot = impact.gui.output_toolbox
 9
10# add (or replace) some impact.globals
11
12# use an integer
13application_globals.add("Carl", 27)
14
15# use a real number
16application_globals.add("Dan", 3.14)
17
18# use a string
19application_globals.add("John", "jv")
20
21# use an object
22application_globals.add("Chris", impact.active_drawing)
23
24# note - not case sensitive, modify the earlier "Carl" global
25application_globals.add("carl", 9)
26
27# clear the output toolbox
28ot.clear()
29
30# iterate all the impact.globals and display them in the output toolbox
31for g in application_globals:
32
33    # can only display the value of the global if it is not an object
34    if isinstance(g.value, (int, float, str, bool, type(None))):
35        ot.add(g.name + ": " + str(g.value))
36
37    else:
38        d = g.value
39
40        if d is not None:
41            ot.add(g.name + ": " + d.full_name)  # expected to be an IDrawing