Example use of path-finder object

Example use of path-finder object
 1# This example shows how to use the PathFinder and Path Options functionality.
 2# To use, draw any geometric path with at least four lines/arcs (a rectangle will do).
 3
 4if active_drawing.isNone():
 5    impact.gui.output_toolbox.add("Unable to continue: no active drawing")
 6else:
 7
 8    # Get a hold of the PathFinder Object and create some PathOptions
 9    path_finder = impact.creator.path_finder()
10    path_options = path_finder.create_hole_path_options()
11
12    # This allows the Path Options to match an existing master tool setting
13    db = impact.active_database
14    ms = db.find_master_tool_setting("<<Default>>", ipMasterSettingType.mstHoleFinder)
15    if not ms.isNone():
16        path_options.apply_master_setting(ms)
17
18    # You can then adjust the settings as well
19    path_options.leave_original = True
20    path_options.original_sub_block = True
21    path_options.original_block_name = "OriginalBlock"
22    path_options.original_use_palette = True
23    path_options.original_palette = "Cut"
24    path_options.original_leave_selected = True
25    path_options.original_merge_entities = False
26
27    path_options.do_left_out_offset = True
28    path_options.left_out_sub_block = True
29    path_options.left_out_block_name = "LeftOutBlock"
30    path_options.left_out_use_palette = True
31    path_options.left_out_palette = "Cut"
32    path_options.left_out_offset_dist = 5.0
33    path_options.left_out_number = 2
34    path_options.left_out_sharp_corners = False
35    path_options.left_out_leave_selected = False
36    path_options.left_out_initial_offset_dist = 1.0
37    path_options.left_out_use_initial_offset = True
38    path_options.left_out_offset_deadends = 4.0
39    path_options.left_out_merge_entities = False
40
41    path_options.do_right_in_offset = True
42    path_options.right_in_sub_block = True
43    path_options.right_in_block_name = "RightInBlock"
44    path_options.right_in_use_palette = True
45    path_options.right_in_palette = "Cut"
46    path_options.right_in_offset_dist = 2.0
47    path_options.right_in_number = 1
48    path_options.right_in_auto_fill = True
49    path_options.right_in_sharp_corners = False
50    path_options.right_in_leave_selected = True
51    path_options.right_in_initial_offset_dist = 1.0
52    path_options.right_in_use_initial_offset = False
53    path_options.right_in_offset_deadends = 4.0
54    path_options.right_in_merge_entities = True
55
56    path_options.do_interiors = True
57    path_options.do_interior_holes = False
58    path_options.leave_interior_original_hole = True
59    path_options.offset_interior_holes_inside = False
60    path_options.offset_dist_interior_holes_inside = 2.0
61    path_options.offset_interior_holes_outside = True
62    path_options.offset_dist_interior_holes_outside = 3.0
63    path_options.do_interior_paths = True
64    path_options.leave_interior_original_paths = True
65    path_options.pocket_interior_paths = True
66    path_options.pocket_dist_interior_paths = 2.0
67    path_options.interior_into_blocks = True
68    path_options.interior_block_name = "InteriorBlockName"
69    path_options.interior_use_palette = False
70    path_options.interior_palette = "Cut"
71    path_options.interior_merge_entities = True
72    path_options.interior_sharp_corners = False
73
74    path_finder.hole_path_options = path_options
75
76    # Set the rest of the PathFinder parameters
77    # (We need at least 4 entities for this example, all geometric)
78    ab = active_drawing.active_layer.active_block
79    if ab.entities.count < 4:
80        impact.gui.output_toolbox.add("Fewer than four entities")
81    else:
82        start_entity = ab.entities.item(1)
83        end_entity = ab.entities.item(4)
84        position = start_entity.get_along(1.0)
85
86        path_finder.start_entity = start_entity
87        path_finder.end_entity = end_entity
88        path_finder.position = position
89        path_finder.replicate = True
90        path_finder.left_on_junction = True
91        path_finder.continue_past_deadends = True
92
93        # Perform the PathFinder operation
94        result = path_finder.perform()
95
96        impact.gui.output_toolbox.add("PathFinder result=" + str(result))
97