SelectAll example (Python)¶
SelectAll example (Python)¶
1# this example creates a rectangle in the active block and ensures that they are
2# deselected. all entities in the active block are then selected
3
4# check there is an active drawing
5if impact.active_drawing.isNone():
6
7 # display a message in the output toolbox
8 impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
9
10else:
11
12 # create a local variable for the active block
13 ab = impact.active_drawing.active_layer.active_block
14
15 # move to a position in the active block
16 ab.move_ad(0, 0)
17
18 # create a local variable for the rectangle size
19 rectangleSize = 100
20
21 # create a line
22 line1 = None
23 try:
24 line1 = ab.lined( rectangleSize, 0 )
25 except Exception as exc:
26 pass
27 impact.gui.output_toolbox.add(f"Failed to create object via ab.lined(): {exc}")
28 line2 = None
29 try:
30 line2 = ab.lined( 0, rectangleSize )
31 except Exception as exc:
32 pass
33 impact.gui.output_toolbox.add(f"Failed to create object via ab.lined(): {exc}")
34 line3 = None
35 try:
36 line3 = ab.lined( -rectangleSize, 0 )
37 except Exception as exc:
38 pass
39 impact.gui.output_toolbox.add(f"Failed to create object via ab.lined(): {exc}")
40 line4 = None
41 try:
42 line4 = ab.lined( 0, -rectangleSize )
43 except Exception as exc:
44 pass
45 impact.gui.output_toolbox.add(f"Failed to create object via ab.lined(): {exc}")
46
47 # check the lines were created
48 if not line1.isNone() and not line2.isNone() and not line3.isNone() and not line4.isNone():
49
50 # ensure that all the lines are deselected
51 line1.selected = 0
52 line2.selected = 0
53 line3.selected = 0
54 line4.selected = 0
55
56 # select all visible entities in the active block
57 ab.select_all()