Various shape properties

Various shape properties
 1# The script assumes that the entities in the current block define one or more
 2# closed paths that can be used to define a shape. If there is just one closed path,
 3# then the shape will have SubShapeCount=1 and InternalCount=0. If there is more than one
 4# closed path and they are completely separate, then SubShapeCount will be greater than one.
 5# If some of the closed paths are completely within other paths, then these are treated
 6# as internals (voids within the shape) and InternalCount will be greater than zero.
 7
 8
 9def display_shape_properties(the_shape):
10    ot = impact.gui.output_toolbox
11    ot.open()
12    ot.clear()
13    ot.add("Shape properties: ")
14
15    conv = impact.system.convertor
16    ot.add("   The area of the shape is: " + str(conv.area_as_string(the_shape.area())))
17    ot.add("   The shape consists of " + str(the_shape.subshape_count) + " sub-shapes")
18
19    # Iterate through the sub-shapes and output their area
20    for count in range(0, the_shape.subshape_count - 1  + 1):
21        subshape = the_shape.subshape(count)
22        ot.add("      The area of sub-shape " + str(count) + " is: " + str(conv.area_as_string(subshape.area())))
23
24    ot.add("   The shape has " + str(the_shape.internal_count) + " internal shapes (voids)")
25
26    internals_shape = the_shape.internals()
27    ot.add("   The area of the internals (all the voids) is: " + str(conv.area_as_string(internals_shape.area())))
28
29    # Iterate through the internal shapes and output their area
30    for count in range(0, internals_shape.subshape_count - 1  + 1):
31        internal_shape = internals_shape.subshape(count)
32        ot.add("      The area of internal (void) shape " + str(count) + " is: " + str(conv.area_as_string(internal_shape.area())))
33
34    # Create another shape, the same as the original but without any voids
35    perimeter_shape = the_shape.remove_internals()
36    ot.add("   The area of the shape without internals is: " + str(conv.area_as_string(perimeter_shape.area())))
37
38    # Iterate through the sub-shapes and output their area
39    for count in range(0, perimeter_shape.subshape_count - 1  + 1):
40        perimeter_sub_shape = perimeter_shape.subshape(count)
41        ot.add("      The area of sub-shape " + str(count) + " without internals is: " + str(conv.area_as_string(perimeter_sub_shape.area())))
42
43
44if impact.active_drawing.isNone():
45    impact.gui.output_toolbox.add("Unable to continue: no active drawing")
46else:
47
48    # Create a shape using the entities from the active block
49    ShapeCreator = impact.creator.shape_creator()
50    ShapeCreator.entities = active_block.entities
51    shape = ShapeCreator.perform(ipShapeCreationType.sctEntities)
52
53    if shape.subshape_count == 0:
54        impact.gui.output_toolbox.add("The entities do not seem to form a closed shape")
55    else:
56        display_shape_properties(shape)