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