Lined example (Python)¶
Lined 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 offset
19 offsetX = 100
20 offsetY = 100
21
22 # create a line
23 line1 = None
24 try:
25 line1 = ab.lined( offsetX, offsetY )
26 except Exception as exc:
27 pass
28 impact.gui.output_toolbox.add(f"Failed to create object via ab.lined(): {exc}")
29
30 # check the line was created
31 if not line1.isNone():
32
33 # display the length of the line in the output toolbox
34 impact.gui.output_toolbox.add(line1.length)