Uniting multiple shapes

Uniting multiple shapes
 1# This example creates a sausage around every entity in the active block,
 2# and amalgamates all these shapes together in a single call to Shapes.union()
 3
 4ad = impact.active_drawing
 5
 6if not ad.isNone():
 7
 8    # Create the Shape impact.creator
 9    ShapeCreator = impact.creator.shape_creator()
10    Shapes = ShapeCreator.shapes()
11
12    # Create a local variable for the entities in the active block
13    entities = ad.active_layer.active_block.entities
14    united_shape = None
15
16    for entity in entities:
17
18        # It would be easy here to check any properties of the entities, and
19        # for example process only lines, or only crease entities.
20        if entity.geometric:
21
22            # Set the properties and create a shape for this entity
23            ShapeCreator.entity = entity
24            ShapeCreator.sausage_distance = 5
25            ShapeCreator.sausage_end_mode = ipSausageEndMode.semRoundEnds
26            this_shape = ShapeCreator.perform(ipShapeCreationType.sctSausage)
27
28            # Reset the properties, ready for the next time
29            ShapeCreator.reset()
30
31            Shapes.add(this_shape)
32
33    united_shape = Shapes.union()
34
35    # Now create new entities from this shape. Note that the entities' palette
36    # will be what was the current palette when the Perform method was used, not the
37    # current palette now.
38    united_shape.copy_to_block(active_block)