DimensionAligned example (Python)¶
DimensionAligned example (Python)¶
1# this example creates 4 aligned dimensions
2
3# check there is an active drawing
4if impact.active_drawing.isNone():
5
6 # display a message in the output toolbox
7 impact.gui.output_toolbox.add("Unable to continue: there is no active drawing")
8
9else:
10
11 # create a local variable for the active block
12 ab = impact.active_drawing.active_layer.active_block
13
14 # create some local variables for point1, point2 and the projectionlength
15 p1 = None
16 try:
17 p1 = impact.creator.vector(0,0)
18 except Exception as exc:
19 pass
20 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
21 p2 = None
22 try:
23 p2 = impact.creator.vector(0,100)
24 except Exception as exc:
25 pass
26 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
27 projectionLength = 20
28
29 # create an aligned dimension projecting to the left and the dimension
30 # text on the inside
31 ab.dimension_aligned(p1, p2, projectionLength, ipProjectionSide.psLeft, ipDimensionTextMode.dtmInside)
32
33 # create an aligned dimension projecting to the right and the dimension
34 # text on the inside
35 ab.dimension_aligned(p1, p2, projectionLength, ipProjectionSide.psRight, ipDimensionTextMode.dtmInside)
36
37 # move the projection points along the X axis
38 p1.X = p1.X + 50
39 p2.X = p2.X + 50
40
41 # create an aligned dimension projecting to the left and the dimension
42 # text on the outside
43 ab.dimension_aligned(p1, p2, projectionLength, ipProjectionSide.psLeft, ipDimensionTextMode.dtmOutside)
44
45 # create an aligned dimension projecting to the right and the dimension
46 # text on the outside
47 ab.dimension_aligned(p1, p2, projectionLength, ipProjectionSide.psRight, ipDimensionTextMode.dtmOutside)
48
49 # view the extents
50 impact.gui.active_window.view_extents()