Creating a layout - the old method

Creating a layout - the old method
 1# This example creates a layout of the active layer in the active drawing
 2# Note that is often better to use ILayer.layout(), rather than ITools.layout() as used here.
 3
 4# create a local variable for the output toolbox
 5ot = impact.gui.output_toolbox
 6ot.clear()
 7
 8# Create a local variable for the active drawing
 9ad = impact.active_drawing
10
11# check there is an active drawing
12if ad.isNone():
13    ot.add("Unable to continue: there is no active drawing")
14else:
15
16    # create a local variable for the active database
17    db = impact.active_database
18
19    # these are the settings to be used, so check they all exist before continuing
20    layout_machine_sheet = db.find_master_tool_setting("b3 LG", ipMasterSettingType.mstLayoutMachineSheet)
21    layout_stock_sheet = db.find_master_tool_setting("LG Stock Sheet", ipMasterSettingType.mstLayoutStockSheet)
22    layout_pattern = db.find_master_tool_setting("Sleeve", ipMasterSettingType.mstLayoutPattern)
23    layout_palette = db.find_master_tool_setting("None", ipMasterSettingType.mstLayoutPalette)
24
25    if (layout_machine_sheet is None) or (layout_pattern is None) or (layout_palette is None) or (layout_stock_sheet is None):
26        ot.add("Failed to find the specified layout settings")
27
28    else:
29
30        # define the options to be used
31        options = impact.creator.layout_options()
32        options.one_up = impact.active_drawing.active_layer
33        options.sheet_mts = layout_machine_sheet
34        options.pattern_mts = layout_pattern
35        options.palette_mts = layout_palette
36        options.fill_method = ipLayoutFillMethod.lfmFillSheet
37
38        # by default layouts will be created even if the nest
39        # or placement is invalid, set this property to False to
40        # prevent creating the layout in this situation
41        options.create_layout_if_invalid = ipBoolean.bTrue
42
43        ot.add("Default Sheet X: " + str(options.sheet_x))
44        ot.add("Default Sheet Y: " + str(options.sheet_y))
45
46        options.stock_sheet_mts = layout_stock_sheet
47
48        # create an ILayoutResults object
49        results = impact.creator.layout_results()
50
51        # call the ITools.layout() method to create the layout
52        if impact.gui.tools.layout(options, results):
53
54            # display the results in the output toolbox
55            ot.add("Successfully created layout")
56            ot.add("Layout: " + str(results.layout().full_name))
57            ot.add("Number Up: " + str(results.number_up))
58            ot.add("Fitted Sheet X: " + str(results.fitted_sheet_x))
59            ot.add("Fitted Sheet Y: " + str(results.fitted_sheet_y))
60            ot.add("Rule X: " + str(results.rule_x))
61            ot.add("Rule Y: " + str(results.rule_y))
62            ot.add("Fitted Sheet (%): " + str(results.fitted_sheet_percent))
63            ot.add("Stock Sheet (%): " + str(results.stock_sheet_percent))
64            ot.add("Stock Sheet X: " + str(results.stock_sheet_x))
65            ot.add("Stock Sheet Y: " + str(results.stock_sheet_y))
66            ot.add("Used Area: " + str(results.used_area))
67            ot.add("Generated Rows: " + str(results.generated_rows))
68            ot.add("Generated Columns: " + str(results.generated_columns))
69
70            # Set the active layer to be the new layout layer
71            ad.active_layer = results.layout()
72
73        else:
74
75            # display an error message in the output toolbox
76            ot.add("Failed to create layout")