DimensionBetweenPoints example (Python)¶
DimensionBetweenPoints example (Python)¶
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 lineLength = 20
16
17 # move to the origin
18 ab.move_ad(0, 0)
19
20 # draw a vertical line
21 ab.line_ad(0, lineLength)
22
23 # move in the x direction
24 ab.move_ad(10, 0)
25
26 # draw a vertical line
27 ab.line_ad(10, lineLength)
28
29 # move in the x direction
30 ab.move_ad(20, 0)
31
32 # draw a vertical line
33 ab.line_ad(20, lineLength)
34
35 # move in the x direction
36 ab.move_ad(30, 0)
37
38 # draw a vertical line
39 ab.line_ad(30, lineLength)
40
41 # move in the x direction
42 ab.move_ad(40, 0)
43
44 # draw a vertical line
45 ab.line_ad(40, lineLength)
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 = None
52 try:
53 v1 = impact.creator.vector(5,10)
54 except Exception as exc:
55 pass
56 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
57 v2 = None
58 try:
59 v2 = impact.creator.vector(35,10)
60 except Exception as exc:
61 pass
62 impact.gui.output_toolbox.add(f"Failed to create object via impact.creator.vector(): {exc}")
63 offset = 5
64 projectionLength = 10
65 projectionSide = ipProjectionSide.psLeft
66 dimensionMode = ipDimensionMode.dmSingle
67
68 # create the dimensions between the points
69 dimensions = ab.dimension_between_points( v1, v2, offset, projectionLength, projectionSide, dimensionMode )
70
71 # clear the output toolbox
72 impact.gui.output_tool_box.clear()
73
74 # check that some dimensions were returned
75 if isinstance(dimensions):
76
77 # iterate all the created dimensions
78 for i in range(0, len(dimensions) - 1 + 1):
79
80 # display the extents of the dimension in the output toolbox
81 impact.gui.output_toolbox.add(dimensions(i).extents.to_string() )