GetAreaAndLengthOfSelected example (Python)

GetAreaAndLengthOfSelected example (Python)
 1# this example displays the length and area of selected entities in the output
 2# 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    # select all visible entities in the active block
16    ab.select_all()
17
18    # create a local variable for the Recurse option
19    recurse = 1
20
21    # create local variables to store the results
22    outerArea = None
23    innerArea = None
24    outerPerimeter = None
25    innerPerimeter = None
26
27    # get the area and length of selected entities in the active block
28    ab.get_area_and_length_of_selected(outerArea, innerArea, outerPerimeter, innerPerimeter, recurse)
29
30    # create a local variable for the output toolbox
31    impact.output_toolbox = impact.gui.output_toolbox
32
33    # clear the output toolbox
34    impact.output_toolbox.clear()
35
36    # display the results in the output toolbox
37    impact.output_toolbox.add("Outer Area: " + outerArea)
38    impact.output_toolbox.add("Inner Area: " + innerArea)
39    impact.output_toolbox.add("Outer Perimeter: " + outerPerimeter)
40    impact.output_toolbox.add("Inner Perimeter: " + innerPerimeter)