Tidy Gaps Example (Python)

Tidy Gaps Example (Python)
 1# This example tidies any gaps in the selected entities
 2
 3# Create a local variable for the impact.gui
 4g = impact.gui
 5
 6# Create a local variable for the output toolbox
 7ot = g.output_toolbox
 8
 9# Clear the output toolbox
10ot.clear()
11
12# Create a local variable for the active drawing
13ad = impact.active_drawing
14
15# Check there is an active drawing
16if ad.isNone():
17
18    # Display a message in the output toolbox
19    ot.add("Unable to continue: there is no active drawing")
20
21else:
22
23    # Create a local variable for the active block
24    ab = ad.active_layer.active_block
25
26    if ab.selection.count == 0:
27
28        # The tool only modifies selected entities
29        ot.add("There are no selected entities")
30
31    else:
32        # Define some local variables for the method parameters
33        tolerance = 0.02
34        recurse = True
35
36        # Tidy the gaps
37        ab.tidy_gaps(tolerance, recurse)
38
39        # View the extents
40        g.active_window.view_extents()