Metric-Imperial Standard (Python)

Metric-Imperial Standard (Python)
 1# This example shows how to create both a Metric and Imperial standard
 2# This example will work regardless of the user setting for
 3# Measurements and impact.units.
 4
 5# Create a local variable for the output toolbox
 6ot = impact.gui.output_toolbox
 7
 8# Clear the output toolbox
 9ot.clear()  # 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
17standardName = "Imperial Test"
18
19# Set the standard to create
20sc.standard = standardName
21
22# Metric will default to the user setting but you can override it
23# variables are automatically recalculated after setting Metric
24msg = None
25
26msg = InputBox("Enter M(etric) or I(mperial):")
27
28if msg == "M":
29
30    # Create a Metric standard without rounding
31    sc.metric = True
32    sc.use_rounding_threshold = False
33
34else:
35
36    if msg == "I":
37
38        # Create an Imperial standard with rounding
39        sc.metric = False
40        sc.use_rounding_threshold = True
41        sc.rounding_threshold = "2/16in"
42
43# Display the default values for L, W, D
44ot.add("L: " + str(sc.variable_settings.variables.item("L").value) + ", W: " + str(sc.variable_settings.variables.item("W").value) + ", D: " + str(sc.variable_settings.variables.item("D").value))
45
46ot.add("Metric: " + str(sc.metric))
47ot.add("UseRoundingThreshold: " + str(sc.use_rounding_threshold))
48ot.add("RoundingThreshold: " + str(sc.rounding_threshold))
49
50# Set the material
51sc.material_mts = db.find_master_tool_setting( "Corrugated (Imperial)|B Flute (US)", ipMasterSettingType.mstMaterial )
52
53# Check that the IStandardCreator.create method can be called successfully
54if sc.valid:
55
56    # Add a message to the output toolbox
57    ot.add("Successfully loaded standard: " + sc.description)
58
59    # Create the standard
60    drawing = sc.create()
61
62    if not drawing.isNone():
63
64        # Add a message to the output toolbox
65        ot.add("Successfully created new project '" + drawing.full_name + "'")
66
67    else:
68
69        # Add an error message to the output toolbox
70        ot.add("Unable to create new project from standard")
71
72else:
73
74    # add an error message to the output toolbox
75    ot.add("Unable to load the standard '" + standardName + "'")