Recalculate Variables¶
Recalculate Variables¶
1# This example shows how to create a standard in a new project
2
3# Create a local variable for the output toolbox
4ot = impact.gui.output_toolbox
5
6# Clear the output toolbox
7ot.clear()
8
9# Create a local variable for the active database
10db = impact.active_database
11
12# Note: You should always assign impact.active_database.standard_creator
13# to a local variable
14sc = db.standard_creator
15
16# Create a local variable for the name of the standard to create
17standard_name = "FEFCO 0201"
18
19# Set the standard to create
20sc.standard = standard_name
21
22# Set the material
23sc.material_mts = db.find_master_tool_setting("Corrugated|B Flute", ipMasterSettingType.mstMaterial)
24
25# Check that the IStandardCreator.create() method can be called successfully
26if sc.valid:
27
28 # Add a message to the output toolbox
29 ot.add("Successfully loaded standard: " + str(sc.description))
30
31 # Display the values of various dependant variables
32 ot.add("P1: " + str(sc.variable_settings.variables.item("P1").value))
33 ot.add("P2: " + str(sc.variable_settings.variables.item("P2").value))
34 ot.add("P3: " + str(sc.variable_settings.variables.item("P3").value))
35 ot.add("P4: " + str(sc.variable_settings.variables.item("P4").value))
36
37 # Modify some of the variables
38 sc.variable_settings.variables.item("L").value = 100.00
39 sc.variable_settings.variables.item("W").value = 200.00
40 sc.variable_settings.variables.item("D").value = 150.00
41
42 # Add a message to the output toolbox
43 ot.add("Recalculating dependant variables")
44
45 # Now recalculate the dependant variables
46 sc.variable_settings.variables.recalculate()
47
48 # Display the values of various dependant variables
49 ot.add("P1: " + str(sc.variable_settings.variables.item("P1").value))
50 ot.add("P2: " + str(sc.variable_settings.variables.item("P2").value))
51 ot.add("P3: " + str(sc.variable_settings.variables.item("P3").value))
52 ot.add("P4: " + str(sc.variable_settings.variables.item("P4").value))
53
54 # Create the standard
55 drawing = sc.create()
56
57 if not drawing.isNone():
58
59 # Add a message to the output toolbox
60 ot.add("Successfully created new project '" + drawing.full_name + "'")
61
62 else:
63
64 # Add an error message to the output toolbox
65 ot.add("Unable to create new project from standard")
66
67else:
68
69 # add an error message to the output toolbox
70 ot.add("Unable to load the standard '" + str(standard_name) + "'")