Metric-Imperial Standard

Metric-Imperial Standard
 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()
10
11# Create a local variable for the active database
12db = impact.active_database
13
14# Note: You should always assign impact.active_database.standard_creator
15# to a local variable
16sc = db.standard_creator
17
18# Create a local variable for the name of the standard to create
19standard_name = "Imperial Test"
20
21# Set the standard to create
22sc.standard = standard_name
23
24# Metric will default to the user setting but you can override it
25# variables are automatically recalculated after setting Metric
26msg = None
27
28msg = VBSCRIPT_FUNCTION_InputBox("Enter M(etric) or I(mperial):")
29
30if msg == "M":
31
32    # Create a Metric standard without rounding
33    sc.metric = True
34    sc.use_rounding_threshold = False
35
36else:
37    if msg == "I":
38
39        # Create an Imperial standard with rounding
40        sc.metric = False
41        sc.use_rounding_threshold = True
42        sc.rounding_threshold = "2/16in"
43
44# Display the default values for L, W, D
45ot.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))
46
47ot.add("Metric: " + str(sc.metric))
48ot.add("UseRoundingThreshold: " + str(sc.use_rounding_threshold))
49ot.add("RoundingThreshold: " + str(sc.rounding_threshold))
50
51# Set the material
52sc.material_mts = db.find_master_tool_setting("Corrugated (Imperial)|B Flute (US)", ipMasterSettingType.mstMaterial)
53
54# Check that the IStandardCreator.create() method can be called successfully
55if sc.valid:
56
57    # Add a message to the output toolbox
58    ot.add("Successfully loaded standard: " + str(sc.description))
59
60    # Create the standard
61    drawing = sc.create()
62
63    if not drawing.isNone():
64
65        # Add a message to the output toolbox
66        ot.add("Successfully created new project '" + drawing.full_name + "'")
67
68    else:
69
70        # Add an error message to the output toolbox
71        ot.add("Unable to create new project from standard")
72
73else:
74
75    # add an error message to the output toolbox
76    ot.add("Unable to load the standard '" + str(standard_name) + "'")