DimensionBetweenPoints example

DimensionBetweenPoints example
 1# this example creates some lines and dimensions some of them
 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 a local variable for the length of the lines
15    line_length = 20
16
17    # move to the origin
18    ab.move_ad(0, 0)
19
20    # draw a vertical line
21    ab.line_ad(0, line_length)
22
23    # move in the x direction
24    ab.move_ad(10, 0)
25
26    # draw a vertical line
27    ab.line_ad(10, line_length)
28
29    # move in the x direction
30    ab.move_ad(20, 0)
31
32    # draw a vertical line
33    ab.line_ad(20, line_length)
34
35    # move in the x direction
36    ab.move_ad(30, 0)
37
38    # draw a vertical line
39    ab.line_ad(30, line_length)
40
41    # move in the x direction
42    ab.move_ad(40, 0)
43
44    # draw a vertical line
45    ab.line_ad(40, line_length)
46
47    # create some local variables for the dimensions returned, the points to
48    # dimension between (which are chosen such that the centre three lines of
49    # those created are dimensioned), offset, projection length, etc.
50    dimensions = None
51    v1 = impact.creator.vector(5,10)
52    v2 = impact.creator.vector(35,10)
53    offset = 5
54    projection_length = 10
55    projection_side = ipProjectionSide.psLeft
56    dimension_mode = ipDimensionMode.dmSingle
57
58    # create the dimensions between the points
59    dimensions = ab.dimension_between_points(v1, v2, offset, projection_length, projection_side, dimension_mode)
60
61    # Wrap variant return items with Impact.py wrapper
62    if dimensions is not None:
63        dimensions = [ILinearDimension(item) for item in dimensions]
64
65    # clear the output toolbox
66    impact.gui.output_toolbox.clear()
67
68    # check that some dimensions were returned
69    if dimensions:
70
71        # iterate all the created dimensions
72        for i in range(0, len(dimensions) - 1  + 1):
73
74            # display the extents of the dimension in the output toolbox
75            impact.gui.output_toolbox.add(dimensions[i].extents.to_string())
76