Creating a layout

Creating a layout
 1# This example creates a layout of the active layer in the active drawing
 2
 3# create a local variable for the output toolbox
 4ot = impact.gui.output_toolbox
 5ot.clear()
 6
 7# Create a local variable for the active drawing
 8ad = impact.active_drawing
 9
10# check there is an active drawing
11if ad.isNone():
12    impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
13else:
14
15    # create a local variable for the active database
16    db = impact.active_database
17
18    # these are the settings to be used, so check they all exist before continuing
19    layout_machine_sheet = db.find_master_tool_setting("Bobst|Bobst COMMERCIAL 106", ipMasterSettingType.mstLayoutMachineSheet)
20    layout_pattern = db.find_master_tool_setting("Sleeve", ipMasterSettingType.mstLayoutPattern)
21    layout_palette = db.find_master_tool_setting("Fitted only", ipMasterSettingType.mstLayoutPalette)
22    layout_labelling = db.find_master_tool_setting("<Default>", ipMasterSettingType.mstLayoutLabelling)
23
24    if (layout_machine_sheet is None) or (layout_pattern is None) or (layout_palette is None) or (layout_labelling is None):
25        impact.gui.output_toolbox.add("Failed to find the specified layout settings")
26    else:
27
28        # define the options to be used
29        options = impact.creator.layout_options()
30        options.sheet_mts = layout_machine_sheet
31        options.pattern_mts = layout_pattern
32        options.palette_mts = layout_palette
33        options.labelling_mts = layout_labelling
34        options.fill_method = ipLayoutFillMethod.lfmFillSheet
35
36        # by default layouts will be created even if the nest
37        # or placement is invalid, set this property to False to
38        # prevent creating the layout in this situation
39        options.create_layout_if_invalid = ipBoolean.bTrue
40
41        # create an ILayoutResults object
42        results = impact.creator.layout_results()
43
44        # call the ILayer.layout() method to create the layout
45        if ad.active_layer.layout(options, results):
46
47            # display the results in the output toolbox
48            ot.add("Successfully created layout")
49            ot.add("Minimum Sheet X: " + str(options.sheet_x_minimum))
50            ot.add("Minimum Sheet Y: " + str(options.sheet_y_minimum))
51            ot.add("Layout: " + results.layout().full_name)
52            ot.add("Number Up: " + str(results.number_up))
53            ot.add("Fitted Sheet X: " + str(results.fitted_sheet_x))
54            ot.add("Fitted Sheet Y: " + str(results.fitted_sheet_y))
55            ot.add("Rule X: " + str(results.rule_x))
56            ot.add("Rule Y: " + str(results.rule_y))
57            ot.add("Fitted Sheet (%): " + str(results.fitted_sheet_percent))
58            ot.add("Stock Sheet (%): " + str(results.stock_sheet_percent))
59            ot.add("Stock Sheet X: " + str(results.stock_sheet_x))
60            ot.add("Stock Sheet Y: " + str(results.stock_sheet_y))
61            ot.add("Used Area: " + str(results.used_area))
62            ot.add("Generated Rows: " + str(results.generated_rows))
63            ot.add("Generated Columns: " + str(results.generated_columns))
64
65            # Set the active layer to be the new layout layer
66            ad.active_layer = results.layout()
67
68        else:
69            impact.gui.output_toolbox.add("Failed to create layout")
70
71            if results.result == ipLayoutResult.lrFailure:
72                ot.add("The layout failed for an unknown reason")
73            elif results.result == ipLayoutResult.lrInvalidSettings:
74                ot.add("The settings were invalid")
75            elif results.result == ipLayoutResult.lrInvalidEntities:
76                ot.add("There are no valid entities")
77            elif results.result == ipLayoutResult.lrInvalidNest:
78                ot.add("The nest was invalid")
79            elif results.result == ipLayoutResult.lrInvalidPlacement:
80                ot.add("The placement was invalid")