OffsetSelected example (Python)

OffsetSelected example (Python)
 1# This example creates a line and offsets it
 2
 3# Create a local variable for the output toolbox
 4ot = impact.gui.output_toolbox
 5
 6# Clear the output toolbox
 7ot.clear()
 8
 9# Create a local variable for the active drawing
10ad = impact.active_drawing
11
12# Check there is an active drawing
13if ad.isNone():
14
15    # Display a message in the output toolbox
16    ot.add("Unable to continue: there is no active drawing")
17
18else:
19
20    # Create a local variable for the active block
21    ab = ad.active_layer.active_block
22
23    # Ensure no entities are selected
24    ab.select_none()
25
26    # Move to the origin of the active block
27    ab.move_ad(0, 0)
28
29    # Create a line
30    line1 = ab.line_ad( 100, 0 )
31
32    # Select the line
33    line1.selected = 1
34
35    # impact.creator local variable for the SideToOffset, OffsetDistance, etc. options
36    v = None
37    try:
38        v = impact.creator.vector( 10, 10 )
39    except Exception as exc:
40        pass
41    impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
42    offsetDistance = 100
43    leaveOriginal = 0
44    sharpCorners = 0
45
46    # Offset the selected line
47    ab.offset_selected(line1, v, offsetDistance, leaveOriginal, sharpCorners)