Run a Standard in existing layer¶
Run a Standard in existing layer¶
1# This example shows how to create a standard in an existing layer
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 drawing
10ad = impact.active_drawing
11
12# Check there is an active drawing
13if ad.isNone():
14
15 # add a message to the output toolbox
16 ot.add("unable to continue: no active drawing")
17
18else:
19
20 # Create a local variable for the active database
21 db = impact.active_database
22
23 # Note: You should always assign impact.active_database.standard_creator
24 # to a local variable
25 sc = db.standard_creator
26
27 # Create a local variable for the name of the standard to create
28 standard_name = "FEFCO 0201"
29
30 # Set the standard name
31 sc.standard = standard_name
32
33 # Set the material
34 sc.material_mts = db.find_master_tool_setting("Corrugated|B Flute", ipMasterSettingType.mstMaterial)
35
36 # Check that the IStandardCreator.create() method can be called successfully
37 if sc.valid:
38
39 # add a message to the output toolbox
40 ot.add("Successfully loaded standard: " + str(sc.description))
41
42 # Set some of the variables
43 sc.variable_settings.variables.item("L").value = 100.00
44 sc.variable_settings.variables.item("W").value = 200.00
45 sc.variable_settings.variables.item("D").value = 150.00
46
47 # Set the layer in which to create the standard
48 sc.creation_layer = ad.active_layer
49
50 # Create the standard
51 drawing = sc.create()
52
53 # Check the standard was created
54 if not drawing.isNone():
55
56 # add a message to the output toolbox
57 ot.add("Successfully created new standard in '" + drawing.full_name + "'")
58
59 else:
60
61 # add an error message to the output toolbox
62 ot.add("Unable to create new standard")
63
64 else:
65
66 # add an error message to the output toolbox
67 ot.add("Unable to load the standard '" + str(standard_name) + "'")