Arrange Optional 2

Arrange Optional 2
 1# this example creates a rectangle and sorts the entities
 2
 3# check there is an active drawing
 4if impact.active_drawing.isNone():
 5
 6    # display a message in the output toolbox
 7    impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
 8
 9else:
10
11    # create a local variable for the active block
12    ab = impact.active_drawing.active_layer.active_block
13
14    # move to the origin of the active block
15    ab.move_ad(0, 0)
16
17    # create local variables for the size of rectangle
18    rectangle_width = 100
19    rectangle_height = 50
20
21    # create a rectangle
22    line1 = ab.line_ad(rectangle_width, 0)
23    line2 = ab.line_ad(rectangle_width, rectangle_height)
24    line3 = ab.line_ad(0, rectangle_height)
25    line4 = ab.line_ad(0, 0)
26
27    # Select all visible entities in the active block
28    ab.select_all()
29
30    # sort the entities starting from the top right corner
31    point = impact.creator.vector(rectangle_width, rectangle_height)
32    ab.arrange_optimal_path2(point, line3)