Mirror example

Mirror example
 1# this example creates some lines in the active block and mirrors them, the
 2# extents of each entity created by the mirror operation are then displayed in
 3# the output toolbox
 4
 5# check there is an active drawing
 6if impact.active_drawing.isNone():
 7
 8    # display a message in the output toolbox
 9    impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
10
11else:
12
13    # create a local variable for the active block
14    ab = impact.active_drawing.active_layer.active_block
15
16    # move to a point in the active block
17    ab.move_ad(0, 50)
18
19    # create some lines
20    line1 = ab.line_ad(0, 0)
21    line2 = ab.line_ad(100, 0)
22    line3 = ab.line_ad(100, 50)
23
24    # check the lines were created
25    if not line1 is None and not line2 is None and not line3 is None:
26
27        # select only the lines created earlier
28        ab.select_none()
29        line1.selected = 1
30        line2.selected = 1
31        line3.selected = 1
32
33        # create some local variables for the entities returned, AxisStart,
34        # AxisEnd and Retain options
35        entities = None
36        axis_start = impact.creator.vector(0,50)
37        axis_end = impact.creator.vector(100,50)
38        retain = 1
39
40        # perform the mirror operation
41        entities = ab.mirror(axis_start, axis_end, retain)
42
43        # Wrap variant return items with Impact.py wrapper
44        if entities is not None:
45            entities = [IEntity(item) for item in entities]
46
47        # clear the output toolbox
48        impact.gui.output_toolbox.clear()
49
50        # check that some entities were returned
51        if entities:
52
53            # iterate all the created entities
54            for i in range(0, len(entities) - 1  + 1):
55
56                # display the extents of the entities in the output toolbox
57                impact.gui.output_toolbox.add(entities[i].extents.to_string())
58
59    # view the extents
60    impact.gui.active_window.view_extents()