Using hole finder with blocks

Using hole finder with blocks
 1# This example creates a block and an insert of the block,
 2# another insert of the block is then created. Another rectangle
 3# is then created. The HoleFinder method is then used with the
 4# replicate method parameter set to True to create offset entities
 5# in both the block inserts and in the second rectangle
 6
 7
 8# Create a local variable for the impact.gui
 9g = impact.gui
10
11# create a local variable for the output toolbox
12ot = g.output_toolbox
13
14
15# Define a subroutine to create a rectangle
16def create_rectangle(block, origin_x, origin_y, width, height):
17
18    # Create a rectangle at 0, 0
19    block.move_ad(origin_x, origin_y)
20    block.line_ad(origin_x + width, origin_y)
21    block.line_ad(origin_x + width, origin_y + height)
22    block.line_ad(origin_x, origin_y + height)
23    block.line_ad(origin_x, origin_y)
24
25
26# Clear the output toolbox
27ot.clear()
28
29# Create a local variable for the active drawing
30ad = impact.active_drawing
31
32# Check there is an active drawing
33if ad.isNone():
34
35    # Display an error message in the output toolbox
36    ot.add("Unable to continue: no active drawing")
37
38else:
39
40    # Attempt to find the settings to use
41    settings_name = "Steel|2mm inside"
42    settings = impact.active_database.find_master_tool_setting(settings_name, ipMasterSettingType.mstHoleFinder)
43
44    # Check the settings were found
45    if settings.isNone():
46        ot.add("Unable to continue: can't locate hole finder settings '" + str(settings_name) + "'")
47    else:
48
49        # Create a local variable for the active block
50        ab = ad.active_layer.active_block
51
52        # Create a rectangle at the origin
53        create_rectangle(ab, 0, 0, 100, 100)
54
55        # Select all the visible entities in the active block,
56        # (i.e. the rectangle just created)
57        ab.select_all()
58
59        # Create a new block from the selected entities
60        block_insert1 = ab.block("Rect", "", ipBlockPosition.bpLeft)
61
62        # Get the block that was created above
63        new_block = block_insert1.inserted_object
64
65        # Create a new insert of the block (to the right of the original block)
66        block_insert2 = ab.block_insert_ad(new_block, block_insert1.extents.right + 1, block_insert1.extents.bottom, 1, 0, 0, 0)
67
68        # Create another rectangle at 200, 200
69        create_rectangle(ab, 200, 200, 100, 100)
70
71        # create an array of vectors
72        points = [None] * 3
73
74        # Initialise the array
75        points[0] = block_insert1.extents.centre  # the centre of the first block insert
76        points[1] = impact.creator.vector(250,250)  # the centre of the second rectangle
77
78        # Use the hole finder method to create offset entities
79        g.tools.hole_finder2(points, True, settings)
80
81        # View the extents
82        g.active_window.view_extents()