Smoothing entities¶
Smoothing entities¶
1# This example deletes all entities in the active block,
2# creates some lines and smooths them
3
4# Create a local variable for the active drawing
5ad = impact.active_drawing
6
7# Create a local variable for the impact.gui
8g = impact.gui
9
10# Create a local variable for the output toolbox
11ot = g.output_toolbox
12
13# Clear the output toolbox
14ot.clear()
15
16# Check that there is an active drawing
17if not ad.isNone():
18
19 # Create a local variable for the active block
20 ab = ad.active_layer.active_block
21
22 # Select all visible entities in the active block
23 ab.select_all()
24
25 # Delete all the selected entities
26 ab.delete_selected()
27
28 # Move to the origin of the active block
29 ab.move_ad(0, 0)
30
31 # Create two lines
32 line1 = ab.line_ad(100, 10)
33 line2 = ab.line_ad(200, 0)
34 line3 = ab.line_ad(300, 10)
35 line4 = ab.line_ad(400, 0)
36
37 # Select the lines
38 line1.selected = True
39 line2.selected = True
40 line3.selected = True
41 line4.selected = True
42
43 # Create some smooth options
44 options = impact.creator.smooth_options()
45
46 # Define the options
47 options.mode = ipSmoothMode.smArcsAndLines
48 options.palette = ad.palettes.item("Cut") # set to None to use the current palette
49 options.retain_bridge_positions = True
50 options.leave_original = False
51 options.gap_tolerance = 1
52 options.max_deviation = 10
53 options.max_angle = 0
54
55 # Smooth the selected entities and store the new entities
56 # in a local variable
57 entity_variant = ab.smooth(options)
58
59 # Wrap variant return items with Impact.py wrapper
60 if entity_variant is not None:
61 entity_variant = [IEntity(item) for item in entity_variant]
62
63 # Convert the variant to a collection
64 entities = impact.creator.entities(entity_variant)
65
66 # Display a message in the output toolbox
67 ot.add("Created " + str(entities.count) + " entities")
68
69 # View the extents of the active window
70 g.active_window.view_extents()
71
72else:
73
74 # Display a message in the output toolbox
75 ot.add("unable to continue: no active drawing")