Metric-Imperial Standard

Metric-Imperial Standard
 1def input_box(prompt, title=None, default=None):
 2    """VBScript InputBox equivalent: single-field modal Impact dialog."""
 3    dlg = impact.gui.make_dialog(title if title else "Input")
 4    field = dlg.fields.add_text(default if default else "", prompt)
 5    dlg.add_button(ipDialogButtonType.dbtOk)
 6    dlg.add_button(ipDialogButtonType.dbtCancel)
 7    if dlg.show_modal(None) == ipDialogButtonType.dbtOk:
 8        return field.value
 9    return ""
10
11# This example shows how to create both a Metric and Imperial standard
12# This example will work regardless of the user setting for
13# Measurements and impact.units.
14
15# Create a local variable for the output toolbox
16ot = impact.gui.output_toolbox
17
18# Clear the output toolbox
19ot.clear()
20
21# Create a local variable for the active database
22db = impact.active_database
23
24# Note: You should always assign impact.active_database.standard_creator
25# to a local variable
26sc = db.standard_creator
27
28# Create a local variable for the name of the standard to create
29standard_name = "Imperial Test"
30
31# Set the standard to create
32sc.standard = standard_name
33
34# Metric will default to the user setting but you can override it
35# variables are automatically recalculated after setting Metric
36msg = None
37
38msg = input_box("Enter M(etric) or I(mperial):")
39
40if msg == "M":
41
42    # Create a Metric standard without rounding
43    sc.metric = True
44    sc.use_rounding_threshold = False
45
46else:
47    if msg == "I":
48
49        # Create an Imperial standard with rounding
50        sc.metric = False
51        sc.use_rounding_threshold = True
52        sc.rounding_threshold = "2/16in"
53
54# Display the default values for L, W, D
55ot.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))
56
57ot.add("Metric: " + str(sc.metric))
58ot.add("UseRoundingThreshold: " + str(sc.use_rounding_threshold))
59ot.add("RoundingThreshold: " + str(sc.rounding_threshold))
60
61# Set the material
62sc.material_mts = db.find_master_tool_setting("Corrugated (Imperial)|B Flute (US)", ipMasterSettingType.mstMaterial)
63
64# Check that the IStandardCreator.create() method can be called successfully
65if sc.valid:
66
67    # Add a message to the output toolbox
68    ot.add("Successfully loaded standard: " + str(sc.description))
69
70    # Create the standard
71    drawing = sc.create()
72
73    if not drawing.isNone():
74
75        # Add a message to the output toolbox
76        ot.add("Successfully created new project '" + drawing.full_name + "'")
77
78    else:
79
80        # Add an error message to the output toolbox
81        ot.add("Unable to create new project from standard")
82
83else:
84
85    # add an error message to the output toolbox
86    ot.add("Unable to load the standard '" + str(standard_name) + "'")