Quick Mirror

Quick Mirror
 1# This script allows the user to mirror the selected entities about a picked point
 2# in either the X or Y axis.
 3# The mirror axis placement is determined by the location of the picked point,
 4# whereas, its orientation is determined by whether the point is further away
 5# in the horizontal or vertical from the selected extent's centre position or vice-versa
 6
 7# check there is an active drawing
 8if impact.active_drawing.isNone():
 9
10    # display a message in the output toolbox
11    impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
12
13else:
14
15    # create a local variable for the active block
16    ab = impact.active_drawing.active_layer.active_block
17
18    # get the extents of the selected entities
19    selected_extents = ab.get_selected_extents()
20
21    # prompt the user to pick a
22    picked_point = impact.gui.picker.get_point("Pick a point to mirror about")
23
24    # check if a valid point was selected
25    if not picked_point.isNone():
26
27        # check if the picked point is a greater distance in the X or Y
28        x_diff = abs(picked_point.x -selected_extents.centre.x)
29        y_diff = abs(picked_point.y -selected_extents.centre.y)
30
31        # set a start point for the mirror axis at the picked point
32        mir_axis_strt = impact.creator.vector(picked_point.x, picked_point.y)
33
34        # set an end point for the mirror axis in either the X or Y (horzontal or vertical) axis
35        # if picked point was further in the x direction than y, assume the mirror should
36        # be about the vertical axis and vice versa
37        if x_diff > y_diff:
38            mir_axis_end = impact.creator.vector(picked_point.x, picked_point.y + 1)
39        else:
40            mir_axis_end = impact.creator.vector(picked_point.x + 1, picked_point.y)
41
42        # create some local variables for the entities returned and Retain option
43        entities = None
44        retain = 0
45
46        # perform the mirror operation
47        entities = ab.mirror(mir_axis_strt, mir_axis_end, retain)
48
49        # Wrap variant return items with Impact.py wrapper
50        if entities is not None:
51            entities = [IEntity(item) for item in entities]
52
53        # deselect entities
54        # ab.select_none()