Manually assigning areas

Manually assigning areas
  1# This example creates a border plot for the active drawing. It uses the
  2# settings 'Two Page Layout + All layers', and manually assigns the layers
  3# from the active drawing. It displays the matched layers in the output
  4# toolbox. Then runs the border plot, you could also use this method to
  5# preassign layer matches before displaying the border plot dialog.
  6
  7
  8# Create a local variable for the database
  9db = impact.active_database
 10
 11# Create a local variable for the output toolbox
 12ot = impact.gui.output_toolbox
 13
 14
 15def display_page_info(page):
 16    ot.add("Template: " + str(page.template.reference))
 17    ot.add("Areas: " + str(page.areas.count))
 18
 19    for j in range(1, page.areas.count  + 1):
 20        area = page.areas.item(j)
 21        ot.add("Area: " + str(area.name))
 22
 23        layers = area.layers
 24
 25        if len(layers) - 1 == -1:
 26            ot.add("  <No Assigned layers>")
 27
 28        else:
 29            for k in range(0, len(layers) - 1  + 1):
 30                ot.add("  Layer " + str(k) + ": " + str(layers[k].full_name))
 31
 32
 33# Clear the output toolbox
 34ot.clear()
 35
 36    # alternative syntax
 37    # for each area in page.areas
 38    # ot.add() "Area: " + area.name
 39    # next
 40
 41if not impact.active_drawing.isNone():
 42
 43    # get a border plot impact.creator
 44    bp = db.border_plot_creator
 45
 46    bp.display_dialog = False
 47
 48    # assign a border plot settings to use
 49    bp.settings = db.find_master_tool_setting("Examples|Multi Page|Two Page Layout + All Oneups", ipMasterSettingType.mstBorderPlot)
 50
 51    # assign the source drawing
 52    bp.source_drawing = impact.active_drawing
 53
 54    if bp.settings is not None:
 55        ot.add("Successfully loaded settings '" + bp.settings.full_name + "'")
 56        ot.add("Pages: " + str(bp.pages.count))
 57
 58        # display the pages and area matches
 59        for i in range(1, bp.pages.count  + 1):
 60            ot.add("--- Page " + str(i) + " ---")
 61            display_page_info(bp.pages.item(i))
 62
 63        page1 = bp.pages.item(1)
 64
 65        # assigning a layer name to an area
 66        page1.areas.item(1).layers = "LayoutB"
 67
 68        # assigning an ILayer interface to an area
 69        page1.areas.item(1).layers = impact.active_drawing.layers.item("LayoutB")
 70
 71        page2 = bp.pages.item(2)
 72
 73        # assigning an array of ILayers to an area
 74        new_layers = [None] * 3
 75
 76        new_layers[0] = impact.active_drawing.layers.item("A")
 77        new_layers[1] = impact.active_drawing.layers.item("C")
 78
 79        page2.areas.item("Main").layers = new_layers
 80
 81        # display the pages and area matches
 82        for i in range(1, bp.pages.count  + 1):
 83            ot.add("--- Page " + str(i) + " ---")
 84            display_page_info(bp.pages.item(i))
 85
 86        # check the all areas assigned
 87        if bp.valid:
 88
 89            # create the border plot
 90            if bp.create():
 91                ot.add("Successfully created border plot '" + bp.settings.full_name + "'")
 92
 93            else:
 94                ot.add("Unable to create the border plot '" + bp.settings.full_name + "'")
 95
 96        else:
 97            ot.add("Unable to load the border plot settings")
 98
 99
100    else:
101        ot.add("Unable to load border plot settings")
102
103else:
104    ot.add("No Active Drawing")