Fill Area (Python)¶
Fill Area (Python)¶
1# Check there is an active drawing
2ad = impact.active_drawing
3if ad.isNone():
4 impact.gui.output_toolbox.add('Unable to continue: no active drawing')
5else:
6 settingsName = "Fill Area 1mm"
7
8 # Check that the settings exist
9 settings = impact.active_database.find_master_tool_setting( settingsName, ipMasterSettingType.mstFillArea )
10 if settings.isNone():
11 impact.gui.output_toolbox.add("Unable to continue: can't locate hole finder settings '" + str(settingsName) + "'")
12 else:
13 ab = ad.active_layer.active_block
14
15 # define the extents of the rectangle
16 r = None
17 try:
18 r = impact.creator.rect()
19 except Exception as exc:
20 pass
21 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.rect(): {exc}")
22 r.bottom_left.X = 0
23 r.bottom_left.Y = 0
24 r.top_right.X = 100
25 r.top_right.Y = 100
26
27 # delete all visible entities in the active block
28 ab.select_all()
29 ab.delete_selected()
30
31 # draw a rectangle
32 ab.move_ad(r.bottom_left.X, r.bottom_left.Y)
33 ab.line_ad(r.top_right.X, r.bottom_left.Y)
34 ab.line_ad(r.top_right.X, r.top_right.Y)
35 ab.line_ad(r.bottom_left.X, r.top_right.Y)
36 ab.line_ad(r.bottom_left.X, r.bottom_left.Y)
37
38 # Define the points to use (equivalent to the user picking points in the interactive tool)
39 point = None
40 try:
41 point = impact.creator.vector( 50, 50 )
42 except Exception as exc:
43 pass
44 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
45
46 # Call Fill Area and get the entities that are created
47 entities = impact.gui.tools.fill_area( Array(point), settings)
48
49 # now select each of the new entities
50 for entity in entities :
51 entity.selected = True