Iterating Pages and Areas¶
Iterating Pages and Areas¶
1# This example creates a border plot for the active drawing. It uses the
2# settings 'Two Page Layout + All layers', and auto matches the layers
3# from the active drawing. It finally displays the matched layers in the
4# output toolbox.
5
6
7# Create a local variable for the database
8db = impact.active_database
9
10# Create a local variable for the output toolbox
11ot = impact.gui.output_toolbox
12
13
14def display_page_info(page):
15 ot.add("Template: " + str(page.template.reference))
16 ot.add("Areas: " + str(page.areas.count))
17
18 for j in range(1, page.areas.count + 1):
19 area = page.areas.item(j)
20 ot.add("Area: " + str(area.name))
21
22 layers = area.layers
23
24 for k in range(0, len(layers) - 1 + 1):
25 ot.add(" Layer " + str(k) + ": " + str(layers[k].full_name))
26
27
28# Clear the output toolbox
29ot.clear()
30
31 # alternative syntax
32 # for each area in page.areas
33 # ot.add() "Area: " + area.name
34 # next
35
36if not impact.active_drawing.isNone():
37
38 # get a border plot impact.creator
39 bp = db.border_plot_creator
40
41 bp.display_dialog = False
42
43 # assign a border plot settings to use
44 bp.settings = db.find_master_tool_setting("Examples|Multi Page|Two Page Layout + All Oneups", ipMasterSettingType.mstBorderPlot)
45
46 # assign the source drawing
47 bp.source_drawing = impact.active_drawing
48
49 if bp.settings is not None:
50 ot.add("Successfully loaded settings '" + bp.settings.full_name + "'")
51 ot.add("Pages: " + str(bp.pages.count))
52
53 # try and automatically match layers
54 if bp.auto_match_layers():
55 ot.add("Successfully auto matched all border plot areas")
56 else:
57 ot.add("Failed to match one or more border plot areas")
58
59 # display the pages and area matches
60 for i in range(1, bp.pages.count + 1):
61 ot.add("--- Page " + str(i) + " ---")
62 display_page_info(bp.pages.item(i))
63
64 # alternative syntax
65 # for each page in bp.pages
66 # DisplayPageInfo(page)
67 # next
68
69 else:
70 ot.add("Unable to load border plot settings")
71
72else:
73 ot.add("No Active Drawing")