Arrange Optional 2 (Python)

Arrange Optional 2 (Python)
 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    rectangleWidth = 100
19    rectangleHeight = 50
20
21    # create a rectangle
22    line1 = ab.line_ad( rectangleWidth, 0 )
23    line2 = ab.line_ad( rectangleWidth, rectangleHeight )
24    line3 = ab.line_ad( 0, rectangleHeight )
25    line4 = ab.line_ad( 0, 0 )
26
27    # Select all visible entities in the active block
28    ab.select_all()  # sort the entities starting from the top right corner
29    point = None
30    try:
31        point = impact.creator.vector( rectangleWidth, rectangleHeight )
32    except Exception as exc:
33        pass
34    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
35    ab.arrange_optimal_path2(point, line3)