Creating a layout (Python)¶
Creating a layout (Python)¶
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 # create a local variable for the active database
15 db = impact.active_database
16
17 # these are the settings to be used, so check they all exist before continuing
18 layoutMachineSheet = db.find_master_tool_setting( "Bobst|Bobst COMMERCIAL 106", ipMasterSettingType.mstLayoutMachineSheet )
19 layoutPattern = db.find_master_tool_setting( "Sleeve", ipMasterSettingType.mstLayoutPattern )
20 layoutPalette = db.find_master_tool_setting( "Fitted only", ipMasterSettingType.mstLayoutPalette )
21 layoutLabelling = db.find_master_tool_setting( "<Default>", ipMasterSettingType.mstLayoutLabelling )
22
23 if (layoutMachineSheet.isNone()) or (layoutPattern.isNone()) or (layoutPalette.isNone()) or (layoutLabelling.isNone()):
24 impact.gui.output_toolbox.add('Failed to find the specified layout settings')
25 else:
26
27 # define the options to be used
28 options = impact.creator.layout_options()
29 options.sheet_mts = layoutMachineSheet
30 options.pattern_mts = layoutPattern
31 options.palette_mts = layoutPalette
32 options.labelling_mts = layoutLabelling
33 options.fill_method = ipLayoutFillMethod.lfmFillSheet
34
35 # by default layouts will be created even if the nest
36 # or placement is invalid, set this property to False to
37 # prevent creating the layout in this situation
38 options.create_layout_if_invalid = ipBoolean.bTrue
39
40 # create an ILayoutResults object
41 results = impact.creator.layout_results()
42
43 # call the ILayer.layout method to create the layout
44 if ad.active_layer.layout( options, results ):
45
46 # display the results in the output toolbox
47 ot.add( "Successfully created layout" )
48 ot.add( "Minimum Sheet X: " + options.sheet_x_minimum )
49 ot.add( "Minimum Sheet Y: " + options.sheet_y_minimum )
50 ot.add( "Layout: " + results.layout.full_name )
51 ot.add( "Number Up: " + results.number_up )
52 ot.add( "Fitted Sheet X: " + results.fitted_sheet_x )
53 ot.add( "Fitted Sheet Y: " + results.fitted_sheet_y )
54 ot.add( "Rule X: " + results.rule_x )
55 ot.add( "Rule Y: " + results.rule_y )
56 ot.add( "Fitted Sheet (%): " + results.fitted_sheet_percent )
57 ot.add( "Stock Sheet (%): " + results.stock_sheet_percent )
58 ot.add( "Stock Sheet X: " + results.stock_sheet_x )
59 ot.add( "Stock Sheet Y: " + results.stock_sheet_y )
60 ot.add( "Used Area: " + results.used_area )
61 ot.add( "Generated Rows: " + results.generated_rows )
62 ot.add( "Generated Columns: " + results.generated_columns )
63
64 # Set the active layer to be the new layout layer
65 ad.active_layer = results.layout
66
67 else:
68
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" )