LineA example (Python)

LineA example (Python)
 1# this example creates a line in the active block and displays its length
 2# in the output toolbox
 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 the origin of the active block
16    ab.move_ad(0, 0)
17
18    # create a local variable for the position
19    position = None
20    try:
21        position = impact.creator.vector(100,100)
22    except Exception as exc:
23        pass
24    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
25
26    # create a line
27    line1 = ab.line_a( position )
28
29    # check the line was created
30    if not line1.isNone():
31
32        # display the length of the line in the output toolbox
33        impact.gui.output_toolbox.add(line1.length)