Using the hole finder (Python)

Using the hole finder (Python)
 1# This example creates a rectangle in the active block and uses
 2# ITools.hole_finder to create geometry offsetting inside from the rectangle
 3
 4# Check there is an active drawing
 5ad = impact.active_drawing
 6if ad.isNone():
 7    impact.gui.output_toolbox.add('Unable to continue: no active drawing')
 8else:
 9
10    # the name (including path) of the hole-finder master tool settings to use
11    settingsName = "Matrix|Matrix Vacuum Hole"
12
13    # Check that the settings exist
14    settings = impact.active_database.find_master_tool_setting( settingsName, ipMasterSettingType.mstHoleFinder )
15    if settings.isNone():
16        impact.gui.output_toolbox.add("Unable to continue: can't locate hole finder settings '" + str(settingsName) + "'")
17    else:
18        ab = ad.active_layer.active_block
19
20        # define the extents of the rectangle
21        r = None
22        try:
23            r = impact.creator.rect()
24        except Exception as exc:
25            pass
26        impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.rect(): {exc}")
27        r.bottom_left.X = 0
28        r.bottom_left.Y = 0
29        r.top_right.X = 100
30        r.top_right.Y = 100
31
32        # delete all visible entities in the active block
33        ab.select_all()
34        ab.delete_selected()
35
36        # draw a rectangle
37        ab.move_ad(r.bottom_left.X, r.bottom_left.Y)
38        ab.line_ad(r.top_right.X, r.bottom_left.Y)
39        ab.line_ad(r.top_right.X, r.top_right.Y)
40        ab.line_ad(r.bottom_left.X, r.top_right.Y)
41        ab.line_ad(r.bottom_left.X, r.bottom_left.Y)
42
43        # set up the array of points to use (equivalent to the user picking points in the interactive tool)
44        points = [None] * 2
45        points[0] = impact.creator.vector( 50, 50 )
46
47        # check for holes
48        result = impact.gui.tools.hole_finder2( points, False, settings )
49        impact.gui.output_toolbox.add('Hole found: ' + str(result))