Translate example¶
Translate example¶
1# this example creates a rectangle in the active block and transforms it twice
2# leaving the original entities
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 rectangle_size = 100
20
21 # create a line
22 line1 = ab.lined(rectangle_size, 0)
23 line2 = ab.lined(0, rectangle_size)
24 line3 = ab.lined(-rectangle_size, 0)
25 line4 = ab.lined(0, -rectangle_size)
26
27 # check the lines were created
28 if not line1.isNone() and not line2.isNone() and not line3.isNone() and not line4.isNone():
29
30 # select only the lines created earlier
31 ab.select_none()
32 line1.selected = 1
33 line2.selected = 1
34 line3.selected = 1
35 line4.selected = 1
36
37 # create local variables for the Offset, Retain and NumCopies options
38 offset = impact.creator.vector(200,200)
39 retain = 1
40 num_copies = 2
41
42 # perform the translation
43 ab.translate(offset, retain, num_copies)
44
45 # view the extents
46 impact.gui.active_window.view_extents()
47