Update for API change: scene.cursor_location -> scene.cursor.location
[blender-addons-contrib.git] / add_dimension.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and / or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 bl_info = {
20     'name': 'Dimension',
21     'author': 'Spivak Vladimir (http://cwolf3d.korostyshev.net)',
22     'version': (3, 9, 5),
23     'blender': (2, 78, 0),
24     'location': 'View3D > Add > Curve',
25     'description': 'Adds Dimension',
26     'warning': '', # used for warning icon and text in addons panel
27     'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Dimension',
28     "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
29     'category': 'Add Curve'}
30
31
32 ##------------------------------------------------------------
33 #### import modules
34 import bpy
35 from bpy.props import  *
36 from mathutils import  *
37 from math import  *
38 from bpy.app.handlers import persistent
39
40 # Add a TextCurve
41 def addText(string = '', loc = ((0, 0, 0)), textsize = 1, align = 'CENTER', offset_y = 0, font = ''):
42
43     tcu = bpy.data.curves.new(string + 'Data', 'FONT')
44     text = bpy.data.objects.new(string + 'Text', tcu)
45     tcu.body = string
46     tcu.align_x = align
47     tcu.size = textsize
48     tcu.offset_y = offset_y
49     if font == '':
50         fnt = bpy.data.fonts[0]
51     else:
52         fnt = bpy.data.fonts.load(font)
53     tcu.font = fnt
54     text.location = loc
55     bpy.context.collection.objects.link(text)
56
57     return text
58
59 ##------------------------------------------------------------
60 # Dimension: Linear-1
61 def Linear1(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.1, arrowlength = 0.25):
62
63     newpoints = []
64
65     w = 1
66     if width < 0:
67         w = -1
68     l = 1
69     if length < 0:
70         l = -1
71
72     if center:
73        center1 = w * depth / 2
74        center2 = w * depth / 2
75     else:
76        center1 = 0
77        center2 = w * depth
78
79     if arrow == 'Arrow1' or arrow == 'Arrow2':
80         newpoints.append([-center1, 0, 0]) #1
81         newpoints.append([-center1, length, 0]) #2
82         newpoints.append([-center1, length + l * dsize, 0]) #3
83         newpoints.append([center2, length + l * dsize, 0]) #4
84         newpoints.append([center2, length + l * dsize / 2 + l * depth / 100, 0]) #5
85         newpoints.append([center2 + w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #6
86         if arrow == 'Arrow1':
87             newpoints.append([center2 + w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #7
88             newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #8
89         else:
90             newpoints.append([center2 + w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #7
91             newpoints.append([width-center2-w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #8
92         newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #9
93         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 100, 0]) #10
94         newpoints.append([width-center2, length + l * dsize, 0]) #11
95         newpoints.append([width + center1, length + l * dsize, 0]) #12
96         newpoints.append([width + center1, length, 0]) #13
97         newpoints.append([width + center1, 0, 0]) #14
98         newpoints.append([width-center2, 0, 0]) #15
99         newpoints.append([width-center2, length, 0]) #16
100         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 100, 0]) #17
101         newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #18
102         if arrow == 'Arrow1':
103             newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #19
104             newpoints.append([center2 + w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #20
105         else:
106             newpoints.append([width-center2-w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #19
107             newpoints.append([center2 + w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #20
108         newpoints.append([center2 + w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #21
109         newpoints.append([center2, length + l * dsize / 2-l * depth / 100, 0]) #22
110         newpoints.append([center2, length, 0]) #23
111         newpoints.append([center2, 0, 0]) #24
112
113     if arrow == 'Serifs1' or arrow == 'Serifs2':
114         b = sqrt(depth * depth / 2)
115         x = sin(radians(45)) * arrowlength * w
116         y = cos(radians(45)) * arrowlength * l
117         newpoints.append([-center1, 0, 0]) #1
118         newpoints.append([-center1, length, 0]) #2
119         newpoints.append([-center1, length + l * dsize / 2-l * depth / 2-l * b, 0]) #3
120         newpoints.append([-center1-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #4
121         newpoints.append([-center1-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #5
122         if arrow == 'Serifs2':
123             newpoints.append([-center1-w * b, length + l * dsize / 2-l * depth / 2, 0]) #6
124             newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #7
125             newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #8
126         newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #9
127         newpoints.append([-center1, length + l * dsize, 0]) #10
128         newpoints.append([center2, length + l * dsize, 0]) #11
129         newpoints.append([center2, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #12
130         newpoints.append([center2 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #13
131         newpoints.append([center2 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #14
132         newpoints.append([center2 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #15
133         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #16
134         newpoints.append([width-center2, length + l * dsize, 0]) #17
135         newpoints.append([width + center1, length + l * dsize, 0]) #18
136         newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #19
137         newpoints.append([width + center1 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #20
138         newpoints.append([width + center1 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #21
139         if arrow == 'Serifs2':
140             newpoints.append([width + center1 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #22
141             newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #23
142             newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #24
143         newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #25
144         newpoints.append([width + center1, length, 0]) #26
145         newpoints.append([width + center1, 0, 0]) #27
146         newpoints.append([width-center2, 0, 0]) #28
147         newpoints.append([width-center2, length, 0]) #29
148         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2-l * b, 0]) #30
149         newpoints.append([width-center2-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #31
150         newpoints.append([width-center2-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #32
151         newpoints.append([width-center2-w * b, length + l * dsize / 2-l * depth / 2, 0]) #33
152         newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #34
153         newpoints.append([center2, length, 0]) #35
154         newpoints.append([center2, 0, 0]) #36
155
156     if arrow == 'Without':
157         newpoints.append([-center1, 0, 0]) #1
158         newpoints.append([-center1, length, 0]) #2
159         newpoints.append([-center1, length + l * dsize, 0]) #3
160         newpoints.append([center2, length + l * dsize, 0]) #4
161         newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #7
162         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #8
163         newpoints.append([width-center2, length + l * dsize, 0]) #11
164         newpoints.append([width + center1, length + l * dsize, 0]) #12
165         newpoints.append([width + center1, length, 0]) #13
166         newpoints.append([width + center1, 0, 0]) #14
167         newpoints.append([width-center2, 0, 0]) #15
168         newpoints.append([width-center2, length, 0]) #16
169         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #19
170         newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #20
171         newpoints.append([center2, length, 0]) #23
172         newpoints.append([center2, 0, 0]) #24
173
174     return newpoints
175
176 ##------------------------------------------------------------
177 # Dimension: Linear-2
178 def Linear2(width = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
179
180     newpoints = []
181
182     w = 1
183     if width < 0:
184         w = -1
185
186     if center:
187        center1 = w * depth / 2
188        center2 = w * depth / 2
189     else:
190        center1 = 0
191        center2 = w * depth
192
193     if arrow == 'Arrow1' or arrow == 'Arrow2':
194         newpoints.append([0, 0, 0]) #1
195         newpoints.append([w * arrowlength, arrowdepth + depth / 2, 0]) #2
196         if arrow == 'Arrow1':
197             newpoints.append([w * arrowlength, depth / 2, 0]) #3
198             newpoints.append([width-w * arrowlength, depth / 2, 0]) #4
199         else:
200             newpoints.append([w * arrowlength * 3 / 4, depth / 2, 0]) #3
201             newpoints.append([width-w * arrowlength * 3 / 4, depth / 2, 0]) #4
202         newpoints.append([width-w * arrowlength, arrowdepth + depth / 2, 0]) #5
203         newpoints.append([width, 0, 0]) #6
204         newpoints.append([width-w * arrowlength, -arrowdepth-depth / 2, 0]) #7
205         if arrow == 'Arrow1':
206             newpoints.append([width-w * arrowlength, -depth / 2, 0]) #8
207             newpoints.append([w * arrowlength, -depth / 2, 0]) #9
208         else:
209             newpoints.append([width-w * arrowlength * 3 / 4, -depth / 2, 0]) #8
210             newpoints.append([w * arrowlength * 3 / 4, -depth / 2, 0]) #9
211         newpoints.append([w * arrowlength, -arrowdepth-depth / 2, 0]) #10
212
213     if arrow == 'Serifs1':
214         b = sqrt(depth * depth / 2)
215         x = sin(radians(45)) * arrowlength * w
216         y = cos(radians(45)) * arrowlength
217         newpoints.append([-center1, -dsize / 2, 0]) #2
218         newpoints.append([-center1, -depth / 2-b, 0]) #3
219         newpoints.append([-center1-x, -depth / 2-b-y, 0]) #4
220         newpoints.append([-center1-w * b-x, -depth / 2-y, 0]) #5
221         newpoints.append([-center1-w * b, -depth / 2, 0]) #6
222         newpoints.append([-center1-w * dsize / 2, -depth / 2, 0]) #7
223         newpoints.append([-center1-w * dsize / 2, depth / 2, 0]) #8
224         newpoints.append([-center1, depth / 2, 0]) #9
225         newpoints.append([-center1, dsize / 2, 0]) #10
226         newpoints.append([center2, dsize / 2, 0]) #11
227         newpoints.append([center2, depth / 2 + b, 0]) #12
228         newpoints.append([center2 + x, depth / 2 + b + y, 0]) #13
229         newpoints.append([center2 + w * b + x, depth / 2 + y, 0]) #14
230         newpoints.append([center2 + w * b, depth / 2, 0]) #15
231         newpoints.append([width-center2, depth / 2, 0]) #16
232         newpoints.append([width-center2, dsize / 2, 0]) #17
233         newpoints.append([width + center1, dsize / 2, 0]) #18
234         newpoints.append([width + center1, depth / 2 + b, 0]) #19
235         newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
236         newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
237         newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
238         newpoints.append([width + center1 + w * dsize / 2, depth / 2, 0]) #23
239         newpoints.append([width + center1 + w * dsize / 2, -depth / 2, 0]) #24
240         newpoints.append([width + center1, -depth / 2, 0]) #25
241         newpoints.append([width + center1, -dsize / 2, 0]) #26
242         newpoints.append([width-center2, -dsize / 2, 0]) #29
243         newpoints.append([width-center2, -depth / 2-b, 0]) #30
244         newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
245         newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
246         newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
247         newpoints.append([center2, -depth / 2, 0]) #34
248         newpoints.append([center2, -dsize / 2, 0]) #35
249
250     if arrow == 'Serifs2':
251         b = sqrt(depth * depth / 2)
252         x = sin(radians(45)) * arrowlength * w
253         y = cos(radians(45)) * arrowlength
254         newpoints.append([-center1 + w * b, -depth / 2, 0]) #3
255         newpoints.append([-center1-x, -depth / 2-b-y, 0]) #4
256         newpoints.append([-center1-w * b-x, -depth / 2-y, 0]) #5
257         newpoints.append([center2 + x, depth / 2 + b + y, 0]) #13
258         newpoints.append([center2 + w * b + x, depth / 2 + y, 0]) #14
259         newpoints.append([center2 + w * b, depth / 2, 0]) #15
260         newpoints.append([width + center1-w * b, depth / 2, 0]) #19
261         newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
262         newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
263         newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
264         newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
265         newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
266
267     if arrow == 'Without':
268         newpoints.append([0, depth / 2, 0]) #3
269         newpoints.append([width, depth / 2, 0]) #4
270         newpoints.append([width, -depth / 2, 0]) #8
271         newpoints.append([0, -depth / 2, 0]) #9
272
273     return newpoints
274
275 ##------------------------------------------------------------
276 # Dimension: Linear-3
277 def Linear3(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
278
279     newpoints = []
280
281     w = 1
282     if width < 0:
283         w = -1
284     l = 1
285     if length < 0:
286         l = -1
287
288     if center:
289        center1 = w * depth / 2
290        center2 = w * depth / 2
291     else:
292        center1 = 0
293        center2 = w * depth
294
295     if arrow == 'Arrow1' or arrow == 'Arrow2':
296         newpoints.append([-center1, 0, 0]) #1
297         newpoints.append([-center1, length, 0]) #2
298         newpoints.append([-center1, length + l * dsize / 2-l * depth / 100, 0]) #3
299         newpoints.append([-center1-w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #4
300         if arrow == 'Arrow1':
301             newpoints.append([-center1-w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #5
302         else:
303             newpoints.append([-center1-w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #5
304         newpoints.append([-center1-w * arrowlength-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #6
305         newpoints.append([-center1-w * arrowlength-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #7
306         if arrow == 'Arrow1':
307             newpoints.append([-center1-w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #8
308         else:
309             newpoints.append([-center1-w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #8
310         newpoints.append([-center1-w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #9
311         newpoints.append([-center1, length + l * dsize / 2 + l * depth / 100, 0]) #10
312         newpoints.append([-center1, length + l * dsize, 0]) #11
313         newpoints.append([center2, length + l * dsize, 0]) #12
314         newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #13
315         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #14
316         newpoints.append([width-center2, length + l * dsize, 0]) #15
317         newpoints.append([width + center1, length + l * dsize, 0]) #16
318         newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 100, 0]) #17
319         newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #18
320         if arrow == 'Arrow1':
321             newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #19
322         else:
323             newpoints.append([width + center1 + w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #19
324         newpoints.append([width + center1 + w * arrowlength + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #20
325         newpoints.append([width + center1 + w * arrowlength + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #21
326         if arrow == 'Arrow1':
327             newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #22
328         else:
329             newpoints.append([width + center1 + w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #22
330         newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #23
331         newpoints.append([width + center1, length + l * dsize / 2-l * depth / 100, 0]) #24
332         newpoints.append([width + center1, length, 0]) #25
333         newpoints.append([width + center1, 0, 0]) #26
334         newpoints.append([width-center2, 0, 0]) #27
335         newpoints.append([width-center2, length, 0]) #28
336         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #29
337         newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #30
338         newpoints.append([center2, length, 0]) #31
339         newpoints.append([center2, 0, 0]) #32
340
341     if arrow == 'Serifs1' or arrow == 'Serifs2':
342         b = sqrt(depth * depth / 2)
343         x = sin(radians(45)) * arrowlength * w
344         y = cos(radians(45)) * arrowlength * l
345         newpoints.append([-center1, 0, 0]) #1
346         newpoints.append([-center1, length, 0]) #2
347         newpoints.append([-center1, length + l * dsize / 2-l * depth / 2-l * b, 0]) #3
348         newpoints.append([-center1-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #4
349         newpoints.append([-center1-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #5
350         newpoints.append([-center1-w * b, length + l * dsize / 2-l * depth / 2, 0]) #6
351         if arrow == 'Serifs1':
352             newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #7
353             newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #8
354         else:
355             newpoints.append([-center1-w * dsize, length + l * dsize / 2-l * depth / 2, 0]) #7
356             newpoints.append([-center1-w * dsize, length + l * dsize / 2 + l * depth / 2, 0]) #8
357         newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #9
358         newpoints.append([-center1, length + l * dsize, 0]) #10
359         newpoints.append([center2, length + l * dsize, 0]) #11
360         newpoints.append([center2, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #12
361         newpoints.append([center2 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #13
362         newpoints.append([center2 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #14
363         newpoints.append([center2 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #15
364         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #16
365         newpoints.append([width-center2, length + l * dsize, 0]) #17
366         newpoints.append([width + center1, length + l * dsize, 0]) #18
367         newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #19
368         newpoints.append([width + center1 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #20
369         newpoints.append([width + center1 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #21
370         newpoints.append([width + center1 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #22
371         if arrow == 'Serifs1':
372             newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #23
373             newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #24
374         else:
375             newpoints.append([width + center1 + w * dsize, length + l * dsize / 2 + l * depth / 2, 0]) #23
376             newpoints.append([width + center1 + w * dsize, length + l * dsize / 2-l * depth / 2, 0]) #24
377         newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #25
378         newpoints.append([width + center1, length, 0]) #26
379         newpoints.append([width + center1, 0, 0]) #27
380         newpoints.append([width-center2, 0, 0]) #28
381         newpoints.append([width-center2, length, 0]) #29
382         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2-l * b, 0]) #30
383         newpoints.append([width-center2-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #31
384         newpoints.append([width-center2-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #32
385         newpoints.append([width-center2-w * b, length + l * dsize / 2-l * depth / 2, 0]) #33
386         newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #34
387         newpoints.append([center2, length, 0]) #35
388         newpoints.append([center2, 0, 0]) #36
389
390     if arrow == 'Without':
391         newpoints.append([-center1, 0, 0]) #1
392         newpoints.append([-center1, length, 0]) #2
393         newpoints.append([-center1, length + l * dsize / 2-l * depth / 2, 0]) #5
394         newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #6
395         newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #7
396         newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #8
397         newpoints.append([-center1, length + l * dsize, 0]) #11
398         newpoints.append([center2, length + l * dsize, 0]) #12
399         newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #13
400         newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #14
401         newpoints.append([width-center2, length + l * dsize, 0]) #15
402         newpoints.append([width + center1, length + l * dsize, 0]) #16
403         newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2, 0]) #19
404         newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #20
405         newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #21
406         newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #22
407         newpoints.append([width + center1, length, 0]) #25
408         newpoints.append([width + center1, 0, 0]) #26
409         newpoints.append([width-center2, 0, 0]) #27
410         newpoints.append([width-center2, length, 0]) #28
411         newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #29
412         newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #30
413         newpoints.append([center2, length, 0]) #31
414         newpoints.append([center2, 0, 0]) #32
415
416     return newpoints
417
418 ##------------------------------------------------------------
419 # Dimension: Radius
420 def Radius(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
421
422     newpoints = []
423
424     w = 1
425     if width < 0:
426         w = -1
427     length = abs(length)
428
429     if center:
430        center1 = w * depth / 2
431        center2 = w * depth / 2
432     else:
433        center1 = 0
434        center2 = w * depth
435
436     if arrow == 'Arrow1' or arrow == 'Arrow2':
437         newpoints.append([0, depth / 2, 0]) #1
438         newpoints.append([width, depth / 2, 0]) #2
439         newpoints.append([width + w * arrowlength, depth / 2 + arrowdepth, 0]) #3
440         if arrow == 'Arrow1':
441             newpoints.append([width + w * arrowlength, depth / 2, 0]) #4
442         else:
443             newpoints.append([width + w * arrowlength * 3 / 4, depth / 2, 0]) #4
444         newpoints.append([width + w * arrowlength + w * length, depth / 2, 0]) #5
445         newpoints.append([width + w * arrowlength + w * length, -depth / 2, 0]) #6
446         if arrow == 'Arrow1':
447             newpoints.append([width + w * arrowlength, -depth / 2, 0]) #7
448         else:
449             newpoints.append([width + w * arrowlength * 3 / 4, -depth / 2, 0]) #7
450         newpoints.append([width + w * arrowlength, -depth / 2-arrowdepth, 0]) #8
451         newpoints.append([width, -depth / 2, 0]) #9
452         newpoints.append([0, -depth / 2, 0]) #10
453
454     if arrow == 'Serifs1' or arrow == 'Serifs2':
455         b = sqrt(depth * depth / 2)
456         x = sin(radians(45)) * arrowlength * w
457         y = cos(radians(45)) * arrowlength
458         newpoints.append([0, depth / 2, 0]) #1
459         if arrow == 'Serifs1':
460             newpoints.append([width-center2, depth / 2, 0]) #16
461             newpoints.append([width-center2, dsize / 2, 0]) #17
462             newpoints.append([width + center1, dsize / 2, 0]) #18
463             newpoints.append([width + center1, depth / 2 + b, 0]) #19
464         else:
465             newpoints.append([width + center1-w * b, depth / 2, 0]) #19
466         newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
467         newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
468         newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
469         newpoints.append([width + center1 + w * length, depth / 2, 0]) #23
470         newpoints.append([width + center1 + w * length, -depth / 2, 0]) #24
471         if arrow == 'Serifs1':
472             newpoints.append([width + center1, -depth / 2, 0]) #25
473             newpoints.append([width + center1, -dsize / 2, 0]) #26
474             newpoints.append([width-center2, -dsize / 2, 0]) #29
475             newpoints.append([width-center2, -depth / 2-b, 0]) #30
476         else:
477             newpoints.append([width-center2 + w * b, -depth / 2, 0]) #30
478         newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
479         newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
480         newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
481         newpoints.append([0, -depth / 2, 0]) #10
482
483     if arrow == 'Without':
484         newpoints.append([0, depth / 2, 0]) #1
485         newpoints.append([width, depth / 2, 0]) #2
486         newpoints.append([width, -depth / 2, 0]) #9
487         newpoints.append([0, -depth / 2, 0]) #10
488
489     return newpoints
490
491 ##------------------------------------------------------------
492 # Dimension: Diameter
493 def Diameter(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
494
495     newpoints = []
496
497     width = width / 2
498     w = 1
499     if width < 0:
500         w = -1
501     length = abs(length)
502
503     if center:
504        center1 = w * depth / 2
505        center2 = w * depth / 2
506     else:
507        center1 = 0
508        center2 = w * depth
509
510     if arrow == 'Arrow1' or arrow == 'Arrow2':
511         newpoints.append([0, depth / 2, 0]) #1
512         newpoints.append([width, depth / 2, 0]) #2
513         newpoints.append([width + w * arrowlength, depth / 2 + arrowdepth, 0]) #3
514         if arrow == 'Arrow1':
515             newpoints.append([width + w * arrowlength, depth / 2, 0]) #4
516         else:
517             newpoints.append([width + w * arrowlength * 3 / 4, depth / 2, 0]) #4
518         newpoints.append([width + w * arrowlength + w * length, depth / 2, 0]) #5
519         newpoints.append([width + w * arrowlength + w * length, -depth / 2, 0]) #6
520         if arrow == 'Arrow1':
521             newpoints.append([width + w * arrowlength, -depth / 2, 0]) #7
522         else:
523             newpoints.append([width + w * arrowlength * 3 / 4, -depth / 2, 0]) #7
524         newpoints.append([width + w * arrowlength, -depth / 2-arrowdepth, 0]) #8
525         newpoints.append([width, -depth / 2, 0]) #9
526         newpoints.append([0, -depth / 2, 0]) #10
527         newpoints.append([-width, -depth / 2, 0]) #11
528         newpoints.append([-width-w * arrowlength, -depth / 2-arrowdepth, 0]) #12
529         if arrow == 'Arrow1':
530             newpoints.append([-width-w * arrowlength, -depth / 2, 0]) #13
531         else:
532             newpoints.append([-width-w * arrowlength * 3 / 4, -depth / 2, 0]) #13
533         newpoints.append([-width-w * arrowlength-w * length, -depth / 2, 0]) #14
534         newpoints.append([-width-w * arrowlength-w * length, depth / 2, 0]) #15
535         if arrow == 'Arrow1':
536             newpoints.append([-width-w * arrowlength, depth / 2, 0]) #16
537         else:
538             newpoints.append([-width-w * arrowlength * 3 / 4, depth / 2, 0]) #16
539         newpoints.append([-width-w * arrowlength, depth / 2 + arrowdepth, 0]) #17
540         newpoints.append([-width, depth / 2, 0]) #18
541
542     if arrow == 'Serifs1' or arrow == 'Serifs2':
543         b = sqrt(depth * depth / 2)
544         x = sin(radians(45)) * arrowlength * w
545         y = cos(radians(45)) * arrowlength
546         newpoints.append([0, depth / 2, 0]) #1
547         if arrow == 'Serifs1':
548             newpoints.append([width-center2, depth / 2, 0]) #16
549             newpoints.append([width-center2, dsize / 2, 0]) #17
550             newpoints.append([width + center1, dsize / 2, 0]) #18
551             newpoints.append([width + center1, depth / 2 + b, 0]) #19
552         else:
553             newpoints.append([width + center1-w * b, depth / 2, 0]) #19
554         newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
555         newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
556         newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
557         newpoints.append([width + center1 + w * length, depth / 2, 0]) #23
558         newpoints.append([width + center1 + w * length, -depth / 2, 0]) #24
559         if arrow == 'Serifs1':
560             newpoints.append([width + center1, -depth / 2, 0]) #25
561             newpoints.append([width + center1, -dsize / 2, 0]) #26
562             newpoints.append([width-center2, -dsize / 2, 0]) #29
563             newpoints.append([width-center2, -depth / 2-b, 0]) #30
564         else:
565             newpoints.append([width-center2 + w * b, -depth / 2, 0]) #30
566         newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
567         newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
568         newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
569         newpoints.append([0, -depth / 2, 0]) #10
570         if arrow == 'Serifs1':
571             newpoints.append([-width + center2, -depth / 2, 0]) #25
572             newpoints.append([-width + center2, -dsize / 2, 0]) #26
573             newpoints.append([-width-center1, -dsize / 2, 0]) #29
574             newpoints.append([-width-center1, -depth / 2-b, 0]) #30
575         else:
576             newpoints.append([-width-center1 + w * b, -depth / 2, 0]) #30
577         newpoints.append([-width-center1-x, -depth / 2-b-y, 0]) #31
578         newpoints.append([-width-center1-w * b-x, -depth / 2-y, 0]) #32
579         newpoints.append([-width-center1-w * b, -depth / 2, 0]) #33
580         newpoints.append([-width + center2-w * length, -depth / 2, 0]) #24
581         newpoints.append([-width + center2-w * length, depth / 2, 0]) #23
582         if arrow == 'Serifs1':
583             newpoints.append([-width-center1, depth / 2, 0]) #16
584             newpoints.append([-width-center1, dsize / 2, 0]) #17
585             newpoints.append([-width + center2, dsize / 2, 0]) #18
586             newpoints.append([-width + center2, depth / 2 + b, 0]) #19
587         else:
588             newpoints.append([-width + center2-w * b, depth / 2, 0]) #19
589         newpoints.append([-width + center2 + x, depth / 2 + b + y, 0]) #20
590         newpoints.append([-width + center2 + w * b + x, depth / 2 + y, 0]) #21
591         newpoints.append([-width + center2 + w * b, depth / 2, 0]) #22
592
593     if arrow == 'Without':
594         newpoints.append([0, depth / 2, 0]) #1
595         newpoints.append([width, depth / 2, 0]) #2
596         newpoints.append([width, -depth / 2, 0]) #9
597         newpoints.append([0, -depth / 2, 0]) #10
598         newpoints.append([-width, -depth / 2, 0]) #11
599         newpoints.append([-width, depth / 2, 0]) #18
600
601     return newpoints
602
603 ##------------------------------------------------------------
604 # Dimension: Angular1
605 def Angular1(width = 2, length = 2, depth = 0.1, angle = 45, resolution = 10, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
606
607     newpoints = []
608
609     if arrow == 'Serifs1' or arrow == 'Serifs2':
610         arrow = 'Without'
611
612     w = 1
613     if width < 0:
614         w = -1
615
616     if resolution == 0:
617        resolution = 1
618
619     if arrow == 'Without':
620        arrowdepth = 0.0
621        arrowlength = 0.0
622
623     length = abs(length)
624     angle = radians(angle)
625
626     if center:
627        center1 = w * depth / 2
628        center2 = w * depth / 2
629     else:
630        center1 = 0
631        center2 = w * depth
632
633     g = hypot(width + w * length, center2)
634     u_depth = asin((center2) / g)
635
636     g = hypot(width, center2)
637     u_depth_min = asin((center2 + center2/4) / g)
638
639     g = hypot(width, arrowlength + w * center2)
640     u_arrow = asin((arrowlength + w * center2) / g)
641
642     if width < 0:
643         u_depth = -u_depth
644         u_depth_min = -u_depth_min
645
646     a = 1
647     if angle < 0 :
648        a = -1
649        u_depth = -u_depth
650        u_depth_min = -u_depth_min
651        u_arrow = -u_arrow
652
653     x = (a * center1) / tan(angle / 2)
654     newpoints.append([-x, -a * center1, 0]) #1
655     newpoints.append([width + w * length, -a * center1, 0]) #2
656     newpoints.append([width + w * length, a * center2, 0]) #3
657
658     if arrow == 'Without':
659         newpoints.append([width + w * depth / 2, a * center2, 0]) #4
660     else:
661         newpoints.append([width + w * depth / 100, a * center2, 0]) #4
662
663     g = width + w * arrowdepth + w * depth / 2
664     x = cos(u_arrow + u_depth) * g
665     y = sin(u_arrow + u_depth) * g
666     newpoints.append([x, y, 0]) #5
667
668     if arrow == 'Arrow1':
669         g = width + w * depth / 2
670         x = cos(u_arrow + u_depth) * g
671         y = sin(u_arrow + u_depth) * g
672         newpoints.append([x, y, 0]) #6
673     if arrow == 'Arrow2':
674         g = width + w * depth / 2
675         x = cos(u_arrow * 3 / 4 + u_depth) * g
676         y = sin(u_arrow * 3 / 4 + u_depth) * g
677         newpoints.append([x, y, 0]) #6
678
679     i = 1
680     while i < resolution :
681         u = i * (angle - u_arrow * 2 - u_depth * 2) / resolution
682         g = width + w * depth / 2
683         x = cos(u + u_arrow + u_depth) * g
684         y = sin(u + u_arrow + u_depth) * g
685         newpoints.append([x, y, 0]) #n
686         i  += 1
687
688     if arrow == 'Arrow1':
689         g = width + w * depth / 2
690         x = cos(angle - u_arrow - u_depth) * g
691         y = sin(angle - u_arrow - u_depth) * g
692         newpoints.append([x, y, 0]) #7
693     if arrow == 'Arrow2':
694         g = width + w * depth / 2
695         x = cos(angle - u_arrow * 3 / 4 - u_depth) * g
696         y = sin(angle - u_arrow * 3 / 4 - u_depth) * g
697         newpoints.append([x, y, 0]) #7
698
699     u = angle - u_arrow - u_depth
700     g = width + w * arrowdepth + w * depth / 2
701     x = cos(u) * g
702     y = sin(u) * g
703     newpoints.append([x, y, 0]) #8
704
705     if arrow == 'Without':
706         g = width + w * depth / 2
707         x = cos(angle-u_depth_min) * g
708         y = sin(angle-u_depth_min) * g
709         newpoints.append([x, y, 0]) #9
710     else:
711         g = width + w * depth / 100
712         x = cos(angle-u_depth_min) * g
713         y = sin(angle-u_depth_min) * g
714         newpoints.append([x, y, 0]) #9
715
716     if arrow == 'Without':
717         g = width-w * depth / 2
718         x = cos(angle-u_depth_min) * g
719         y = sin(angle-u_depth_min) * g
720         newpoints.append([x, y, 0]) #10
721     else:
722         g = width-w * depth / 100
723         x = cos(angle-u_depth_min) * g
724         y = sin(angle-u_depth_min) * g
725         newpoints.append([x, y, 0]) #10
726
727     g = width-w * arrowdepth-w * depth / 2
728     x = cos(u) * g
729     y = sin(u) * g
730     newpoints.append([x, y, 0]) #11
731
732     if arrow == 'Arrow1':
733         u = angle - u_arrow - u_depth
734         g = width-w * depth / 2
735         x = cos(u) * g
736         y = sin(u) * g
737         newpoints.append([x, y, 0]) #12
738     if arrow == 'Arrow2':
739         u = angle - u_arrow * 3 / 4 - u_depth
740         g = width-w * depth / 2
741         x = cos(u) * g
742         y = sin(u) * g
743         newpoints.append([x, y, 0]) #12
744
745     i = resolution - 1
746     while i >=  1 :
747         u = i * (angle - u_arrow * 2 - u_depth * 2) / resolution
748         g = width-w * depth / 2
749         x = cos(u + u_arrow + u_depth) * g
750         y = sin(u + u_arrow + u_depth) * g
751         newpoints.append([x, y, 0]) #n
752         i -=  1
753
754     if arrow == 'Arrow1':
755         g = width-w * depth / 2
756         x = cos(u_arrow + u_depth) * g
757         y = sin(u_arrow + u_depth) * g
758         newpoints.append([x, y, 0]) #13
759     if arrow == 'Arrow2':
760         g = width-w * depth / 2
761         x = cos(u_arrow * 3 / 4 + u_depth) * g
762         y = sin(u_arrow * 3 / 4 + u_depth) * g
763         newpoints.append([x, y, 0]) #13
764
765     g = width-w * arrowdepth-w * depth / 2
766     x = cos(u_arrow + u_depth) * g
767     y = sin(u_arrow + u_depth) * g
768     newpoints.append([x, y, 0]) #14
769
770     if arrow == 'Without':
771         newpoints.append([width-w * depth / 2, a * center2, 0]) #15
772     else:
773         newpoints.append([width-w * depth / 100, a * center2, 0]) #15
774
775     x = (a * center2) / tan(angle / 2)
776     newpoints.append([x, a * center2, 0]) #16
777
778     g = width + w * length
779     x = cos(angle-u_depth) * g
780     y = sin(angle-u_depth) * g
781     newpoints.append([x, y, 0]) #17
782
783     if center:
784         g = width + w * length
785         x = cos(angle + u_depth) * g
786         y = sin(angle + u_depth) * g
787         newpoints.append([x, y, 0]) #18
788     else:
789         g = width + w * length
790         x = cos(angle) * g
791         y = sin(angle) * g
792         newpoints.append([x, y, 0]) #18
793
794     return newpoints
795
796 ##------------------------------------------------------------
797 # Dimension: Angular2
798 def Angular2(width = 2, depth = 0.1, angle = 45, resolution = 10, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
799
800     newpoints = []
801
802     if arrow == 'Serifs1' or arrow == 'Serifs2':
803         arrow = 'Without'
804
805     w = 1
806     if width < 0:
807         w = -1
808
809     if resolution == 0:
810        resolution = 1
811
812     if arrow == 'Without':
813        arrowdepth = 0.0
814        arrowlength = 0.0
815
816     angle = radians(angle)
817
818     newpoints.append([width, 0, 0]) #1
819
820     g = hypot(width + w * depth / 2, arrowlength)
821     u_arrow = asin((arrowlength) / g)
822     if angle < 0 :
823        u_arrow = -u_arrow
824
825     g = width + w * arrowdepth + w * depth / 2
826     x = cos(u_arrow) * g
827     y = sin(u_arrow) * g
828     newpoints.append([x, y, 0]) #2
829
830     if arrow == 'Arrow1':
831         g = width + w * depth / 2
832         x = cos(u_arrow) * g
833         y = sin(u_arrow) * g
834         newpoints.append([x, y, 0]) #3
835
836     if arrow == 'Arrow2':
837         g = width + w * depth / 2
838         x = cos(u_arrow * 3 / 4) * g
839         y = sin(u_arrow * 3 / 4) * g
840         newpoints.append([x, y, 0]) #3
841
842     i = 1
843     while i < resolution :
844         u = i * (angle - u_arrow * 2) / resolution
845         g = width + w * depth / 2
846         x = cos(u + u_arrow) * g
847         y = sin(u + u_arrow) * g
848         newpoints.append([x, y, 0]) #n
849         i  += 1
850
851     if arrow == 'Arrow1':
852         u = angle - u_arrow
853         g = width + w * depth / 2
854         x = cos(u) * g
855         y = sin(u) * g
856         newpoints.append([x, y, 0]) #4
857     if arrow == 'Arrow2':
858         u = angle - u_arrow * 3 / 4
859         g = width + w * depth / 2
860         x = cos(u) * g
861         y = sin(u) * g
862         newpoints.append([x, y, 0]) #4
863
864     u = angle - u_arrow
865     g = width + w * arrowdepth + w * depth / 2
866     x = cos(u) * g
867     y = sin(u) * g
868     newpoints.append([x, y, 0]) #5
869
870     g = width
871     x = cos(angle) * g
872     y = sin(angle) * g
873     newpoints.append([x, y, 0]) #6
874
875     g = width-w * arrowdepth-w * depth / 2
876     x = cos(u) * g
877     y = sin(u) * g
878     newpoints.append([x, y, 0]) #7
879
880     if arrow == 'Arrow1':
881         u = angle - u_arrow
882         g = width-w * depth / 2
883         x = cos(u) * g
884         y = sin(u) * g
885         newpoints.append([x, y, 0]) #8
886     if arrow == 'Arrow2':
887         u = angle - u_arrow * 3 / 4
888         g = width-w * depth / 2
889         x = cos(u) * g
890         y = sin(u) * g
891         newpoints.append([x, y, 0]) #8
892
893     i = resolution - 1
894     while i > 0 :
895         u = i * (angle - u_arrow * 2) / resolution
896         g = width-w * depth / 2
897         x = cos(u + u_arrow) * g
898         y = sin(u + u_arrow) * g
899         newpoints.append([x, y, 0]) #n
900         i -=  1
901
902     if arrow == 'Arrow1':
903         g = width-w * depth / 2
904         x = cos(u_arrow) * g
905         y = sin(u_arrow) * g
906         newpoints.append([x, y, 0]) #9
907     if arrow == 'Arrow2':
908         g = width-w * depth / 2
909         x = cos(u_arrow * 3 / 4) * g
910         y = sin(u_arrow * 3 / 4) * g
911         newpoints.append([x, y, 0]) #9
912
913     g = width-w * arrowdepth-w * depth / 2
914     x = cos(u_arrow) * g
915     y = sin(u_arrow) * g
916     newpoints.append([x, y, 0]) #10
917
918     return newpoints
919
920 ##------------------------------------------------------------
921 # Dimension: Angular3
922 def Angular3(width = 2, length = 2, dsize = 1, depth = 0.1, angle = 45, resolution = 10, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
923
924     newpoints = []
925
926     if arrow == 'Serifs1' or arrow == 'Serifs2':
927         arrow = 'Without'
928
929     w = 1
930     if width < 0:
931         w = -1
932
933     if resolution == 0:
934        resolution = 1
935
936     if arrow == 'Without':
937        arrowdepth = 0.0
938        arrowlength = 0.0
939
940     resolution_2 = floor(resolution / 2)
941
942     length = abs(length)
943     angle = radians(angle)
944
945     if center:
946        center1 = w * depth / 2
947        center2 = w * depth / 2
948     else:
949        center1 = 0
950        center2 = w * depth
951
952     g = hypot(width + w * length, center2)
953     u_depth = asin((center2) / g)
954
955     g = hypot(width + depth / 2, center2)
956     u_depth_13 = asin((center2 + center2/4) / g)
957
958     g = hypot(width-depth / 2, center2)
959     u_depth_14 = asin((center2 + center2/4) / g)
960
961     g = hypot(width, center2)
962     u_depth_min = asin((center2) / g)
963
964     g = hypot(width, arrowlength + w * center2)
965     u_arrow = asin((arrowlength + w * center2) / g)
966
967     g = hypot(width, arrowlength + w * center2 + dsize)
968     u_dsize = asin((arrowlength + w * center2 + dsize) / g)
969
970     if width < 0:
971         u_depth = -u_depth
972         u_depth_min = -u_depth_min
973         u_depth_13 = -u_depth_13
974         u_depth_14 = -u_depth_14
975
976     a = 1
977     if angle < 0 :
978        a = -1
979        u_depth = -u_depth
980        u_depth_min = -u_depth_min
981        u_arrow = -u_arrow
982        u_depth_13 = -u_depth_13
983        u_depth_14 = -u_depth_14
984
985     x = (a * center1) / tan(angle / 2)
986     newpoints.append([-x, -a * center1, 0]) #1
987
988     if arrow == 'Without':
989         newpoints.append([width-w * depth / 2, -a * center1, 0]) #2
990     else:
991         newpoints.append([width-w * depth / 100, -a * center1, 0]) #2
992
993     g = width-w * arrowdepth-w * depth / 2
994     x = cos(-u_arrow-u_depth) * g
995     y = sin(-u_arrow-u_depth) * g
996     newpoints.append([x, y, 0]) #3
997
998     if arrow == 'Arrow1':
999         g = width-w * depth / 2
1000         x = cos(-u_arrow-u_depth) * g
1001         y = sin(-u_arrow-u_depth) * g
1002         newpoints.append([x, y, 0]) #4
1003     if arrow == 'Arrow2':
1004         g = width-w * depth / 2
1005         x = cos(-u_arrow * 3 / 4-u_depth) * g
1006         y = sin(-u_arrow * 3 / 4-u_depth) * g
1007         newpoints.append([x, y, 0]) #4
1008
1009     i = 1
1010     while i < resolution_2 :
1011         u = i * (-u_dsize) / resolution_2
1012         g = width-w * depth / 2
1013         x = cos(u-u_arrow) * g
1014         y = sin(u-u_arrow) * g
1015         newpoints.append([x, y, 0]) #n
1016         i  += 1
1017
1018     g = width-w * depth / 2
1019     x = cos(-u_arrow-u_depth-u_dsize) * g
1020     y = sin(-u_arrow-u_depth-u_dsize) * g
1021     newpoints.append([x, y, 0]) #5
1022
1023     g = width + w * depth / 2
1024     x = cos(-u_arrow-u_depth-u_dsize) * g
1025     y = sin(-u_arrow-u_depth-u_dsize) * g
1026     newpoints.append([x, y, 0]) #6
1027
1028     i = resolution_2
1029     while i >=  1 :
1030         u = i * (-u_dsize) / resolution_2
1031         g = width + w * depth / 2
1032         x = cos(u-u_arrow) * g
1033         y = sin(u-u_arrow) * g
1034         newpoints.append([x, y, 0]) #n
1035         i -=  1
1036
1037     if arrow == 'Arrow1':
1038        g = width + w * depth / 2
1039        x = cos(-u_arrow-u_depth) * g
1040        y = sin(-u_arrow-u_depth) * g
1041        newpoints.append([x, y, 0]) #7
1042     if arrow == 'Arrow2':
1043        g = width + w * depth / 2
1044        x = cos(-u_arrow * 3 / 4-u_depth) * g
1045        y = sin(-u_arrow * 3 / 4-u_depth) * g
1046        newpoints.append([x, y, 0]) #7
1047
1048     g = width + w * arrowdepth + w * depth / 2
1049     x = cos(-u_arrow-u_depth) * g
1050     y = sin(-u_arrow-u_depth) * g
1051     newpoints.append([x, y, 0]) #8
1052
1053     if arrow == 'Without':
1054         newpoints.append([width + w * depth / 2, -a * center1, 0]) #9
1055     else:
1056         newpoints.append([width + w * depth / 100, -a * center1, 0]) #9
1057
1058     newpoints.append([width + w * length, -a * center1, 0]) #10
1059
1060     newpoints.append([width + w * length, a * center2, 0]) #11
1061
1062     g = width + w * depth / 2
1063     x = cos(u_depth_min) * g
1064     y = sin(u_depth_min) * g
1065     newpoints.append([x, y, 0]) #12
1066
1067     i = 1
1068     while i < resolution :
1069         u = i * (angle - u_depth * 2) / resolution
1070         g = width + w * depth / 2
1071         x = cos(u + u_depth) * g
1072         y = sin(u + u_depth) * g
1073         newpoints.append([x, y, 0]) #n
1074         i  += 1
1075
1076     if width > 0 :
1077         g = width + w * depth / 2
1078         x = cos(angle - u_depth_13) * g
1079         y = sin(angle - u_depth_13) * g
1080         newpoints.append([x, y, 0]) #13
1081
1082         g = width-w * depth / 2
1083         x = cos(angle - u_depth_14) * g
1084         y = sin(angle - u_depth_14) * g
1085         newpoints.append([x, y, 0]) #14
1086     else:
1087         g = width + w * depth / 2
1088         x = cos(angle - u_depth_14) * g
1089         y = sin(angle - u_depth_14) * g
1090         newpoints.append([x, y, 0]) #13
1091
1092         g = width-w * depth / 2
1093         x = cos(angle - u_depth_13) * g
1094         y = sin(angle - u_depth_13) * g
1095         newpoints.append([x, y, 0]) #14
1096
1097     i = resolution - 1
1098     while i >=  1 :
1099         u = i * (angle - u_depth * 2) / resolution
1100         g = width-w * depth / 2
1101         x = cos(u + u_depth) * g
1102         y = sin(u + u_depth) * g
1103         newpoints.append([x, y, 0]) #n
1104         i -=  1
1105
1106     g = width-w * depth / 2
1107     x = cos(u_depth_min) * g
1108     y = sin(u_depth_min) * g
1109     newpoints.append([x, y, 0]) #15
1110
1111     x = (a * center2) / tan(angle / 2)
1112     newpoints.append([x, a * center2, 0]) #16
1113
1114     g = width + w * length
1115     x = cos(angle-u_depth) * g
1116     y = sin(angle-u_depth) * g
1117     newpoints.append([x, y, 0]) #17
1118
1119     if center:
1120         g = width + w * length
1121         x = cos(angle + u_depth) * g
1122         y = sin(angle + u_depth) * g
1123         newpoints.append([x, y, 0]) #18
1124
1125         if arrow == 'Without':
1126             g = width + w * depth / 2
1127             x = cos(angle + u_depth) * g
1128             y = sin(angle + u_depth) * g
1129             newpoints.append([x, y, 0]) #19
1130         else:
1131             g = width + w * depth / 100
1132             x = cos(angle + u_depth) * g
1133             y = sin(angle + u_depth) * g
1134             newpoints.append([x, y, 0]) #19
1135     else:
1136         g = width + w * length
1137         x = cos(angle) * g
1138         y = sin(angle) * g
1139         newpoints.append([x, y, 0]) #18
1140
1141         if arrow == 'Without':
1142             g = width + w * depth / 2
1143             x = cos(angle) * g
1144             y = sin(angle) * g
1145             newpoints.append([x, y, 0]) #19
1146         else:
1147             g = width + w * depth / 100
1148             x = cos(angle) * g
1149             y = sin(angle) * g
1150             newpoints.append([x, y, 0]) #19
1151
1152     g = width + w * arrowdepth + w * depth / 2
1153     x = cos(angle + u_arrow + u_depth) * g
1154     y = sin(angle + u_arrow + u_depth) * g
1155     newpoints.append([x, y, 0]) #20
1156
1157     if arrow == 'Arrow1':
1158         g = width + w * depth / 2
1159         x = cos(angle + u_arrow + u_depth) * g
1160         y = sin(angle + u_arrow + u_depth) * g
1161         newpoints.append([x, y, 0]) #21
1162     if arrow == 'Arrow2':
1163         g = width + w * depth / 2
1164         x = cos(angle + u_arrow * 3 / 4 + u_depth) * g
1165         y = sin(angle + u_arrow * 3 / 4 + u_depth) * g
1166         newpoints.append([x, y, 0]) #21
1167
1168     i = 1
1169     while i < resolution_2 :
1170         u = i * (u_dsize) / resolution_2
1171         g = width + w * depth / 2
1172         x = cos(u + angle + u_arrow) * g
1173         y = sin(u + angle + u_arrow) * g
1174         newpoints.append([x, y, 0]) #n
1175         i  += 1
1176
1177     g = width + w * depth / 2
1178     x = cos(angle + u_arrow + u_depth + u_dsize) * g
1179     y = sin(angle + u_arrow + u_depth + u_dsize) * g
1180     newpoints.append([x, y, 0]) #22
1181
1182     g = width-w * depth / 2
1183     x = cos(angle + u_arrow + u_depth + u_dsize) * g
1184     y = sin(angle + u_arrow + u_depth + u_dsize) * g
1185     newpoints.append([x, y, 0]) #23
1186
1187     i = resolution_2
1188     while i >=  1 :
1189         u = i * (u_dsize) / resolution_2
1190         g = width-w * depth / 2
1191         x = cos(u + angle + u_arrow) * g
1192         y = sin(u + angle + u_arrow) * g
1193         newpoints.append([x, y, 0]) #n
1194         i -=  1
1195
1196     if arrow == 'Arrow1':
1197         g = width-w * depth / 2
1198         x = cos(angle + u_arrow + u_depth) * g
1199         y = sin(angle + u_arrow + u_depth) * g
1200         newpoints.append([x, y, 0]) #24
1201     if arrow == 'Arrow2':
1202         g = width-w * depth / 2
1203         x = cos(angle + u_arrow * 3 / 4 + u_depth) * g
1204         y = sin(angle + u_arrow * 3 / 4 + u_depth) * g
1205         newpoints.append([x, y, 0]) #24
1206
1207     g = width-w * arrowdepth-w * depth / 2
1208     x = cos(angle + u_arrow + u_depth) * g
1209     y = sin(angle + u_arrow + u_depth) * g
1210     newpoints.append([x, y, 0]) #25
1211
1212     if center:
1213         if arrow == 'Without':
1214             g = width-w * depth / 2
1215             x = cos(angle + u_depth) * g
1216             y = sin(angle + u_depth) * g
1217             newpoints.append([x, y, 0]) #26
1218         else:
1219             g = width-w * depth / 100
1220             x = cos(angle + u_depth) * g
1221             y = sin(angle + u_depth) * g
1222             newpoints.append([x, y, 0]) #26
1223     else:
1224         if arrow == 'Without':
1225             g = width-w * depth / 2
1226             x = cos(angle) * g
1227             y = sin(angle) * g
1228             newpoints.append([x, y, 0]) #26
1229         else:
1230             g = width-w * depth / 100
1231             x = cos(angle) * g
1232             y = sin(angle) * g
1233             newpoints.append([x, y, 0]) #26
1234
1235     return newpoints
1236
1237 ##------------------------------------------------------------
1238 # Dimension: Note
1239 def Note(width = 2, length = 2, depth = 0.1, angle = 45, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
1240
1241     newpoints = []
1242
1243     if arrow == 'Serifs1' or arrow == 'Serifs2':
1244         arrow = 'Without'
1245
1246     w = 1
1247     if width < 0:
1248         w = -1
1249     angle = radians(angle)
1250     length = abs(length)
1251
1252     if cos(angle) > 0:
1253         newpoints.append([0, 0, 0]) #1
1254
1255         if arrow == 'Arrow1':
1256             g = hypot(arrowlength, depth / 2 + arrowdepth)
1257             u = asin((depth / 2 + arrowdepth) / g)
1258             x = cos(angle + u) * g
1259             y = sin(angle + u) * g
1260             newpoints.append([w * x, y, 0]) #2
1261
1262             g = hypot(arrowlength, depth / 2)
1263             u = asin((depth / 2) / g)
1264             x = cos(angle + u) * g
1265             y = sin(angle + u) * g
1266             newpoints.append([w * x, y, 0]) #3
1267
1268         if arrow == 'Arrow2':
1269             g = hypot(arrowlength, depth / 2 + arrowdepth)
1270             u = asin((depth / 2 + arrowdepth) / g)
1271             x = cos(angle + u) * g
1272             y = sin(angle + u) * g
1273             newpoints.append([w * x, y, 0]) #2
1274
1275             g = hypot(arrowlength * 3 / 4, depth / 2)
1276             u = asin((depth / 2) / g)
1277             x = cos(angle + u) * g
1278             y = sin(angle + u) * g
1279             newpoints.append([w * x, y, 0]) #3
1280
1281         if arrow == 'Without':
1282             g = w * depth / 2
1283             x = cos(angle + radians(90)) * g
1284             y = sin(angle + radians(90)) * g
1285             newpoints.append([x, y, 0]) #2
1286
1287         g = hypot(width, depth / 2)
1288         u = asin((depth / 2) / g)
1289         x = cos(angle + u) * g
1290         y = sin(angle) * width
1291         newpoints.append([w * x, y + w * depth / 2, 0]) #4
1292
1293         newpoints.append([w * x + w * length, y + w * depth / 2, 0]) #5
1294         newpoints.append([w * x + w * length, y-w * depth / 2, 0]) #6
1295
1296         g = hypot(width, depth / 2)
1297         u = asin((depth / 2) / g)
1298         y = sin(angle) * width
1299         x = cos(angle-u) * g
1300         newpoints.append([w * x, y-w * depth / 2, 0]) #7
1301
1302         if arrow == 'Arrow1':
1303             g = hypot(arrowlength, depth / 2)
1304             u = asin((depth / 2) / g)
1305             x = cos(angle-u) * g
1306             y = sin(angle-u) * g
1307             newpoints.append([w * x, y, 0]) #8
1308
1309             g = hypot(arrowlength, depth / 2 + arrowdepth)
1310             u = asin((depth / 2 + arrowdepth) / g)
1311             x = cos(angle-u) * g
1312             y = sin(angle-u) * g
1313             newpoints.append([w * x, y, 0]) #9
1314
1315         if arrow == 'Arrow2':
1316             g = hypot(arrowlength * 3 / 4, depth / 2)
1317             u = asin((depth / 2) / g)
1318             x = cos(angle-u) * g
1319             y = sin(angle-u) * g
1320             newpoints.append([w * x, y, 0]) #8
1321
1322             g = hypot(arrowlength, depth / 2 + arrowdepth)
1323             u = asin((depth / 2 + arrowdepth) / g)
1324             x = cos(angle-u) * g
1325             y = sin(angle-u) * g
1326             newpoints.append([w * x, y, 0]) #9
1327
1328         if arrow == 'Without':
1329             g = -w * depth / 2
1330             x = cos(angle + radians(90)) * g
1331             y = sin(angle + radians(90)) * g
1332             newpoints.append([x, y, 0]) #6
1333
1334     else:
1335         newpoints.append([0, 0, 0]) #1
1336
1337         if arrow == 'Arrow1':
1338             g = hypot(arrowlength, depth / 2 + arrowdepth)
1339             u = asin((depth / 2 + arrowdepth) / g)
1340             x = cos(angle-u) * g
1341             y = sin(angle-u) * g
1342             newpoints.append([w * x, y, 0]) #2
1343
1344             g = hypot(arrowlength, depth / 2)
1345             u = asin((depth / 2) / g)
1346             x = cos(angle-u) * g
1347             y = sin(angle-u) * g
1348             newpoints.append([w * x, y, 0]) #3
1349
1350         if arrow == 'Arrow2':
1351             g = hypot(arrowlength, depth / 2 + arrowdepth)
1352             u = asin((depth / 2 + arrowdepth) / g)
1353             x = cos(angle-u) * g
1354             y = sin(angle-u) * g
1355             newpoints.append([w * x, y, 0]) #2
1356
1357             g = hypot(arrowlength * 3 / 4, depth / 2)
1358             u = asin((depth / 2) / g)
1359             x = cos(angle-u) * g
1360             y = sin(angle-u) * g
1361             newpoints.append([w * x, y, 0]) #3
1362
1363         if arrow == 'Without':
1364             g = -w * depth / 2
1365             x = cos(angle + radians(90)) * g
1366             y = sin(angle + radians(90)) * g
1367             newpoints.append([x, y, 0]) #2
1368
1369         g = hypot(width, depth / 2)
1370         u = asin((depth / 2) / g)
1371         x = cos(angle-u) * g
1372         y = sin(angle) * width
1373         newpoints.append([w * x, y + w * depth / 2, 0]) #4
1374
1375         newpoints.append([w * x-w * length, y + w * depth / 2, 0]) #5
1376         newpoints.append([w * x-w * length, y-w * depth / 2, 0]) #6
1377
1378         g = hypot(width, depth / 2)
1379         u = asin((depth / 2) / g)
1380         y = sin(angle) * width
1381         x = cos(angle + u) * g
1382         newpoints.append([w * x, y-w * depth / 2, 0]) #7
1383
1384         if arrow == 'Arrow1':
1385             g = hypot(arrowlength, depth / 2)
1386             u = asin((depth / 2) / g)
1387             x = cos(angle + u) * g
1388             y = sin(angle + u) * g
1389             newpoints.append([w * x, y, 0]) #8
1390
1391             g = hypot(arrowlength, depth / 2 + arrowdepth)
1392             u = asin((depth / 2 + arrowdepth) / g)
1393             x = cos(angle + u) * g
1394             y = sin(angle + u) * g
1395             newpoints.append([w * x, y, 0]) #9
1396
1397         if arrow == 'Arrow2':
1398             g = hypot(arrowlength * 3 / 4, depth / 2)
1399             u = asin((depth / 2) / g)
1400             x = cos(angle + u) * g
1401             y = sin(angle + u) * g
1402             newpoints.append([w * x, y, 0]) #8
1403
1404             g = hypot(arrowlength, depth / 2 + arrowdepth)
1405             u = asin((depth / 2 + arrowdepth) / g)
1406             x = cos(angle + u) * g
1407             y = sin(angle + u) * g
1408             newpoints.append([w * x, y, 0]) #9
1409
1410         if arrow == 'Without':
1411             g = w * depth / 2
1412             x = cos(angle + radians(90)) * g
1413             y = sin(angle + radians(90)) * g
1414             newpoints.append([x, y, 0]) #6
1415
1416     return newpoints
1417
1418 ##------------------------------------------------------------
1419 # make and set Material
1420 def makeMaterial(name, diffuse, specular, alpha):
1421
1422     mat = bpy.data.materials.new(name)
1423     mat.diffuse_color = diffuse
1424     mat.diffuse_shader = 'LAMBERT'
1425     mat.diffuse_intensity = 1.0
1426     mat.specular_color = specular
1427     mat.specular_shader = 'COOKTORR'
1428     mat.specular_intensity = 1.0
1429     mat.alpha = alpha
1430     mat.ambient = 1
1431     mat.specular_hardness = 1
1432     mat.use_shadeless = True
1433
1434     return mat
1435
1436 def setMaterial(ob, mat):
1437
1438     me = ob.data
1439     me.materials.append(mat)
1440
1441 def ablength(x1 = 0.0, y1 = 0.0, z1 = 0.0, x2 = 0.0, y2 = 0.0, z2 = 0.0):
1442   return sqrt( (x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2 )
1443
1444 ##------------------------------------------------------------
1445 # calculates the matrix for the new object
1446 # depending on user pref
1447 def align_matrix(context, location):
1448
1449     loc = Matrix.Translation(location)
1450     obj_align = context.preferences.edit.object_align
1451     if (context.space_data.type == 'VIEW_3D'
1452         and obj_align == 'VIEW'):
1453         rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
1454     else:
1455         rot = Matrix()
1456     align_matrix = loc * rot
1457
1458     return align_matrix
1459
1460 ##------------------------------------------------------------
1461 #### Curve creation functions
1462 # sets bezierhandles to auto
1463 def setBezierHandles(obj, mode = 'VECTOR'):
1464
1465     view_layer = bpy.context.view_layer
1466     if obj.type !=  'CURVE':
1467         return
1468     view_layer.objects.active = obj
1469     bpy.ops.object.mode_set(mode = 'EDIT', toggle = True)
1470     bpy.ops.curve.select_all(action = 'SELECT')
1471     bpy.ops.curve.handle_type_set(type = mode)
1472     bpy.ops.object.mode_set(mode = 'OBJECT', toggle = True)
1473     bpy.context.scene.update()
1474
1475 ##------------------------------------------------------------
1476 #### Add units
1477 def addUnits(stext, units):
1478     scale = bpy.context.scene.unit_settings.scale_length
1479     unit_system = bpy.context.scene.unit_settings.system
1480     separate_units = bpy.context.scene.unit_settings.use_separate
1481     if unit_system == 'METRIC':
1482         if units == 'None': scale_steps = 1
1483         if units == '\u00b5m': scale_steps = 1000000
1484         if units == 'mm': scale_steps = 1000
1485         if units == 'cm': scale_steps = 100
1486         if units == 'm': scale_steps = 1
1487         if units == 'km': scale_steps = 1/1000
1488         if units == 'thou': scale_steps = 36000 * 1.0936133
1489         if units == '"': scale_steps = 36 * 1.0936133
1490         if units == '\'': scale_steps = 3 * 1.0936133
1491         if units == 'yd': scale_steps = 1 * 1.0936133
1492         if units == 'mi': scale_steps = 1/1760 * 1.0936133
1493         dval = stext * scale_steps * scale
1494     elif unit_system == 'IMPERIAL':
1495         if units == 'None': scale_steps = 3 * 1.0936133
1496         if units == '\u00b5m': scale_steps = 1000000
1497         if units == 'mm': scale_steps = 1000
1498         if units == 'cm': scale_steps = 100
1499         if units == 'm': scale_steps = 1
1500         if units == 'km': scale_steps = 1/1000
1501         if units == 'thou': scale_steps = 36000 * 1.0936133
1502         if units == '"': scale_steps = 36 * 1.0936133
1503         if units == '\'': scale_steps = 3 * 1.0936133
1504         if units == 'yd': scale_steps = 1 * 1.0936133
1505         if units == 'mi': scale_steps = 1/1760 * 1.0936133
1506         dval = stext * scale_steps * scale
1507     else:
1508         dval = stext
1509     return dval
1510 ##------------------------------------------------------------
1511 # create new CurveObject from vertarray and splineType
1512 def createCurve(vertArray, self, align_matrix):
1513     # options to vars
1514     name = self.Dimension_Type         # Type as name
1515
1516     # create curve
1517     newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
1518     newSpline = newCurve.splines.new('BEZIER') # spline
1519
1520     newSpline.bezier_points.add(int(len(vertArray) * 0.333333333))
1521     newSpline.bezier_points.foreach_set('co', vertArray)
1522
1523     # set curveOptions
1524     newCurve.dimensions = '2D'
1525     newSpline.use_cyclic_u = True
1526     newSpline.use_endpoint_u = True
1527
1528     # create object with newCurve
1529     DimensionCurve = bpy.data.objects.new(name, newCurve) # object
1530     bpy.context.collection.objects.link(DimensionCurve) # place in active scene
1531     DimensionCurve.Dimension = True
1532     DimensionCurve.matrix_world = align_matrix # apply matrix
1533     self.Dimension_Name = DimensionCurve.name
1534
1535     # creat DimensionText and rotation
1536     w = 1
1537     if self.Dimension_width < 0 :
1538         w = -1
1539     l = 1
1540     if self.Dimension_length < 0 :
1541         l = -1
1542
1543     x = self.Dimension_width / 2
1544     y = self.Dimension_length + l * self.Dimension_dsize / 2 + self.Dimension_depth / 2 + self.Dimension_textdepth
1545
1546     gettextround = int(self.Dimension_textround)
1547     stext = addUnits(self.Dimension_width, self.Dimension_units)
1548     stext = abs(round(stext, gettextround))
1549     if gettextround == 0:
1550         stext = abs(int(stext))
1551
1552     align = 'CENTER'
1553     offset_y = 0
1554
1555     if self.Dimension_Type == 'Linear-2':
1556         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1557
1558     if self.Dimension_Type == 'Radius':
1559         x = self.Dimension_width + w * self.Dimension_dsize / 2 + w * abs(self.Dimension_length) / 2
1560         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1561
1562     if self.Dimension_Type == 'Diameter':
1563         x = 0
1564         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1565
1566     g = hypot(x, y)
1567     c = self.Dimension_startlocation
1568     u = asin(y / g)
1569     if self.Dimension_width < 0 :
1570         u = radians(180) - u
1571     xx = cos(u) * g
1572     yy = sin(u) * g
1573
1574     stext = str(stext)
1575     if self.Dimension_units != 'None' and self.Dimension_add_units_name:
1576         stext += self.Dimension_units
1577
1578     if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
1579         xx = cos(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
1580         yy = sin(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
1581         system_rotation = bpy.context.scene.unit_settings.system_rotation
1582         if system_rotation == 'DEGREES':
1583             stext = abs(round(self.Dimension_angle, gettextround))
1584             if gettextround == 0:
1585                 stext = abs(int(stext))
1586             stext = str(stext) + '°'
1587         else:
1588             stext = abs(round(self.Dimension_angle * pi / 180, gettextround))
1589             if gettextround == 0:
1590                 stext = abs(int(stext))
1591             stext = str(stext)
1592         align = 'LEFT'
1593         if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1594             align = 'RIGHT'
1595         if self.Dimension_width < 0 :
1596             offset_y = 0
1597             align = 'RIGHT'
1598             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1599                 align = 'LEFT'
1600
1601     if self.Dimension_Type == 'Note':
1602         if cos(radians(self.Dimension_angle)) > 0:
1603             xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
1604             yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
1605             stext = self.Dimension_note
1606             align = 'LEFT'
1607             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1608                 align = 'RIGHT'
1609             if self.Dimension_width < 0 :
1610                 align = 'RIGHT'
1611                 xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
1612                 yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
1613                 if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1614                    align = 'LEFT'
1615         else:
1616             xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
1617             yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
1618             stext = self.Dimension_note
1619             align = 'RIGHT'
1620             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1621                 align = 'LEFT'
1622             if self.Dimension_width < 0 :
1623                 align = 'LEFT'
1624                 xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
1625                 yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
1626                 if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1627                     align = 'RIGHT'
1628
1629     if self.Dimension_liberty == '2D':
1630         tv = Vector((xx, yy, 0))
1631
1632         DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
1633
1634         if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1635             DimensionCurve.rotation_euler[0] = radians(0)
1636             DimensionCurve.rotation_euler[1] = radians(0)
1637             if self.Dimension_XYType == 'X':
1638                 DimensionCurve.rotation_euler[2] = radians(self.Dimension_rotation)
1639                 DimensionCurve.location[1] += self.Dimension_offset
1640             if self.Dimension_XYType == 'Y':
1641                 DimensionCurve.rotation_euler[2] = radians(90+self.Dimension_rotation)
1642                 DimensionCurve.location[0] += self.Dimension_offset
1643
1644         if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1645             DimensionCurve.rotation_euler[0] = radians(90)
1646             if self.Dimension_XZType == 'X':
1647                 DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
1648                 DimensionCurve.location[1] += self.Dimension_offset
1649             if self.Dimension_XZType == 'Z':
1650                 DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
1651                 DimensionCurve.location[0] += self.Dimension_offset
1652             DimensionCurve.rotation_euler[2] = radians(0)
1653
1654         if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1655             DimensionCurve.rotation_euler[0] = radians(90)
1656             if self.Dimension_YZType == 'Y':
1657                 DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
1658                 DimensionCurve.location[0] += self.Dimension_offset
1659             if self.Dimension_YZType == 'Z':
1660                 DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
1661                 DimensionCurve.location[1] += self.Dimension_offset
1662             DimensionCurve.rotation_euler[2] = radians(90)
1663
1664         if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'RIGHT':
1665             DimensionText.rotation_euler[1] = radians(0)
1666         if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1667             DimensionText.rotation_euler[1] = radians(180)
1668
1669         if self.Dimension_width_or_location == 'location':
1670             if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
1671                 vx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
1672                 vy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
1673                 vz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
1674                 if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1675                     g = hypot(vx, vy)
1676                     if g !=  0 :
1677                        u2 = acos(vx / g)
1678                        u1 = asin(vy / g)
1679                        if u1 < 0 :
1680                            u2 = u1
1681                     else:
1682                        u2 = 0
1683                     DimensionCurve.rotation_euler[2] = u2
1684
1685                 if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1686                     g = hypot(vx, vz)
1687                     if g !=  0 :
1688                        u2 = acos(vx / g)
1689                        u1 = asin(vz / g)
1690                        if u1 < 0 :
1691                            u2 = u1
1692                     else:
1693                        u2 = 0
1694                     DimensionCurve.rotation_euler[1] = -u2
1695
1696                 if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1697                     g = hypot(vy, vz)
1698                     if g !=  0 :
1699                        u2 = acos(vy / g)
1700                        u1 = asin(vz / g)
1701                        if u1 < 0 :
1702                            u2 = u1
1703                     else:
1704                        u2 = 0
1705                     DimensionCurve.rotation_euler[1] = -u2
1706
1707     if self.Dimension_liberty == '3D':
1708         tv = Vector((xx, yy, 0))
1709         DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
1710         v = self.Dimension_endlocation - self.Dimension_startlocation
1711         if v.length !=  0 :
1712            u1 = -asin(v[2] / v.length)
1713         else:
1714            u1 = 0
1715         g = hypot(v[0], v[1])
1716         if g !=  0 :
1717            u2 = asin(v[1] / g)
1718            if self.Dimension_endlocation.x < self.Dimension_startlocation.x :
1719               u2 = radians(180)-asin(v[1] / g)
1720         else:
1721            u2 = 0
1722
1723         DimensionCurve.rotation_euler[0] = radians(self.Dimension_rotation)
1724         DimensionCurve.rotation_euler[1] = u1
1725         DimensionCurve.rotation_euler[2] = u2
1726
1727     # Align to view
1728     if self.Dimension_align_to_camera :
1729         obj_camera = bpy.context.scene.camera
1730         DimensionCurve.rotation_euler[0] = obj_camera.rotation_euler[0]
1731         DimensionCurve.rotation_euler[1] = obj_camera.rotation_euler[1]
1732         DimensionCurve.rotation_euler[2] = obj_camera.rotation_euler[2]
1733
1734     # set materials
1735     if self.Dimension_matname in bpy.data.materials :
1736         setMaterial(DimensionCurve, bpy.data.materials[self.Dimension_matname])
1737         setMaterial(DimensionText, bpy.data.materials[self.Dimension_matname])
1738     else:
1739         red = makeMaterial(self.Dimension_matname, (1, 0, 0), (1, 0, 0), 1)
1740         setMaterial(DimensionCurve, red)
1741         setMaterial(DimensionText, red)
1742
1743     setBezierHandles(DimensionCurve, 'VECTOR')
1744     setBezierHandles(DimensionText, 'VECTOR')
1745
1746     group_name = 'Dimensions'
1747
1748     bpy.ops.object.mode_set(mode = 'OBJECT')
1749
1750     if group_name in bpy.data.collections:
1751         group = bpy.data.collections[group_name]
1752     else:
1753         group = bpy.data.collections.new(group_name)
1754
1755     if not DimensionCurve.name in group.objects:
1756         group.objects.link(DimensionCurve)
1757
1758     if not DimensionText.name in group.objects:
1759         group.objects.link(DimensionText)
1760
1761     DimensionText.parent = DimensionCurve
1762
1763     if self.Dimension_appoint_parent and not self.Dimension_parent == '':
1764         const =  DimensionCurve.constraints.new(type='CHILD_OF')
1765         const.target =  bpy.data.objects[self.Dimension_parent]
1766         const.inverse_matrix = bpy.data.objects[self.Dimension_parent].matrix_world.inverted()
1767         bpy.context.scene.update()
1768
1769     bpy.ops.object.select_all(action='DESELECT')
1770     DimensionCurve.select_set(True)
1771     DimensionText.select_set(True)
1772     bpy.context.view_layer.objects.active = DimensionCurve
1773     bpy.context.scene.update()
1774
1775     DimensionCurve.Dimension_Name = self.Dimension_Name
1776     DimensionCurve.Dimension_Type = self.Dimension_Type
1777     DimensionCurve.Dimension_XYZType = self.Dimension_XYZType
1778     DimensionCurve.Dimension_XYType = self.Dimension_XYType
1779     DimensionCurve.Dimension_XZType = self.Dimension_XZType
1780     DimensionCurve.Dimension_YZType = self.Dimension_YZType
1781     DimensionCurve.Dimension_startlocation = c
1782     DimensionCurve.Dimension_endlocation = self.Dimension_endlocation
1783     DimensionCurve.Dimension_endanglelocation = self.Dimension_endanglelocation
1784     DimensionCurve.Dimension_width_or_location = self.Dimension_width_or_location
1785     DimensionCurve.Dimension_liberty = self.Dimension_liberty
1786     DimensionCurve.Dimension_Change = False
1787
1788     #### Dimension properties
1789     DimensionCurve.Dimension_resolution = self.Dimension_resolution
1790     DimensionCurve.Dimension_width = self.Dimension_width
1791     DimensionCurve.Dimension_length = self.Dimension_length
1792     DimensionCurve.Dimension_dsize = self.Dimension_dsize
1793     DimensionCurve.Dimension_depth = self.Dimension_depth
1794     DimensionCurve.Dimension_depth_from_center = self.Dimension_depth_from_center
1795     DimensionCurve.Dimension_angle = self.Dimension_angle
1796     DimensionCurve.Dimension_rotation = self.Dimension_rotation
1797     DimensionCurve.Dimension_offset = self.Dimension_offset
1798
1799     #### Dimension text properties
1800     DimensionCurve.Dimension_textsize = self.Dimension_textsize
1801     DimensionCurve.Dimension_textdepth = self.Dimension_textdepth
1802     DimensionCurve.Dimension_textround = self.Dimension_textround
1803     DimensionCurve.Dimension_font = self.Dimension_font
1804
1805     #### Dimension Arrow properties
1806     DimensionCurve.Dimension_arrow = self.Dimension_arrow
1807     DimensionCurve.Dimension_arrowdepth = self.Dimension_arrowdepth
1808     DimensionCurve.Dimension_arrowlength = self.Dimension_arrowlength
1809
1810     #### Materials properties
1811     DimensionCurve.Dimension_matname = self.Dimension_matname
1812
1813     #### Note properties
1814     DimensionCurve.Dimension_note = self.Dimension_note
1815     DimensionCurve.Dimension_align_to_camera = self.Dimension_align_to_camera
1816
1817     #### Parent
1818     DimensionCurve.Dimension_parent = self.Dimension_parent
1819     DimensionCurve.Dimension_appoint_parent = self.Dimension_appoint_parent
1820
1821     #### Units
1822     DimensionCurve.Dimension_units = self.Dimension_units
1823     DimensionCurve.Dimension_add_units_name = self.Dimension_add_units_name
1824
1825     return
1826
1827 ##------------------------------------------------------------
1828 # Main Function
1829 def main(self, align_matrix):
1830     # deselect all objects
1831     bpy.ops.object.select_all(action = 'DESELECT')
1832
1833     # options
1834     Type = self.Dimension_Type
1835
1836     if self.Dimension_width_or_location == 'location':
1837         if self.Dimension_liberty == '2D':
1838             if self.Dimension_XYZType == 'TOP':
1839                 if self.Dimension_XYType == 'X':
1840                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1841                 if self.Dimension_XYType == 'Y':
1842                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1843             if self.Dimension_XYZType == 'FRONT':
1844                 if self.Dimension_XZType == 'X':
1845                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1846                 if self.Dimension_XZType == 'Z':
1847                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1848             if self.Dimension_XYZType == 'RIGHT':
1849                 if self.Dimension_YZType == 'Y':
1850                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1851                 if self.Dimension_YZType == 'Z':
1852                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1853             if self.Dimension_XYZType == 'BOTTOM':
1854                 if self.Dimension_XYType == 'X':
1855                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1856                 if self.Dimension_XYType == 'Y':
1857                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1858             if self.Dimension_XYZType == 'BACK':
1859                 if self.Dimension_XZType == 'X':
1860                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1861                 if self.Dimension_XZType == 'Z':
1862                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1863             if self.Dimension_XYZType == 'LEFT':
1864                 if self.Dimension_YZType == 'Y':
1865                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1866                 if self.Dimension_YZType == 'Z':
1867                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1868         if self.Dimension_liberty == '3D':
1869             v = self.Dimension_endlocation - self.Dimension_startlocation
1870             self.Dimension_width = v.length
1871
1872         if Type == 'Angular1' or Type == 'Angular2' or Type == 'Angular3':
1873             c = ablength(self.Dimension_startlocation.x, self.Dimension_startlocation.y, self.Dimension_startlocation.z, self.Dimension_endlocation.x, self.Dimension_endlocation.y, self.Dimension_endlocation.z)
1874             b = ablength(self.Dimension_startlocation.x, self.Dimension_startlocation.y, self.Dimension_startlocation.z, self.Dimension_endanglelocation.x, self.Dimension_endanglelocation.y, self.Dimension_endanglelocation.z)
1875             a = ablength(self.Dimension_endanglelocation.x, self.Dimension_endanglelocation.y, self.Dimension_endanglelocation.z, self.Dimension_endlocation.x, self.Dimension_endlocation.y, self.Dimension_endlocation.z)
1876             self.Dimension_width = max(a, b, c)
1877             vanglex = self.Dimension_endanglelocation.x - self.Dimension_startlocation.x
1878             vangley = self.Dimension_endanglelocation.y - self.Dimension_startlocation.y
1879             vanglez = self.Dimension_endanglelocation.z - self.Dimension_startlocation.z
1880             vendx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
1881             vendy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
1882             vendz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
1883             if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1884                 self.Dimension_XYType = 'X'
1885                 g = hypot(vanglex, vangley)
1886                 if g !=  0 :
1887                    u2 = acos(vanglex / g)
1888                    u1 = asin(vangley / g)
1889                    if u1 < 0 :
1890                        u2 = -u2
1891                 else:
1892                    u2 = 0
1893                 g = hypot(vendx, vendy)
1894                 if g !=  0 :
1895                    uu2 = acos(vendx / g)
1896                    uu1 = asin(vendy / g)
1897                    if uu1 < 0 :
1898                        uu2 = -uu2
1899                 else:
1900                    uu2 = 0
1901                 self.Dimension_angle = degrees(u2 - uu2)
1902             if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1903                 self.Dimension_XZType = 'Z'
1904                 g = hypot(vanglex, vanglez)
1905                 if g !=  0 :
1906                    u2 = acos(vanglex / g)
1907                    u1 = asin(vanglez / g)
1908                    if u1 < 0 :
1909                        u2 = -u2
1910                 else:
1911                    u2 = 0
1912                 g = hypot(vendx, vendz)
1913                 if g !=  0 :
1914                    uu2 = acos(vendx / g)
1915                    uu1 = asin(vendz / g)
1916                    if uu1 < 0 :
1917                        uu2 = -uu2
1918                 else:
1919                    uu2 = 0
1920                 self.Dimension_angle = degrees(u2 - uu2)
1921             if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1922                 self.Dimension_YZType = 'Z'
1923                 g = hypot(vangley, vanglez)
1924                 if g !=  0 :
1925                    u2 = acos(vangley / g)
1926                    u1 = asin(vanglez / g)
1927                    if u1 < 0 :
1928                        u2 = -u2
1929                 else:
1930                    u2 = 0
1931                 g = hypot(vendy, vendz)
1932                 if g !=  0 :
1933                    uu2 = acos(vendy / g)
1934                    uu1 = asin(vendz / g)
1935                    if uu1 < 0 :
1936                        uu2 = -uu2
1937                 else:
1938                    uu2 = 0
1939                 self.Dimension_angle = degrees(u2 - uu2)
1940             if self.Dimension_liberty == '3D':
1941                 c = ablength(self.Dimension_startlocation.x, self.Dimension_startlocation.y, self.Dimension_startlocation.z, self.Dimension_endlocation.x, self.Dimension_endlocation.y, self.Dimension_endlocation.z)
1942                 b = ablength(self.Dimension_startlocation.x, self.Dimension_startlocation.y, self.Dimension_startlocation.z, self.Dimension_endanglelocation.x, self.Dimension_endanglelocation.y, self.Dimension_endanglelocation.z)
1943                 a = ablength(self.Dimension_endanglelocation.x, self.Dimension_endanglelocation.y, self.Dimension_endanglelocation.z, self.Dimension_endlocation.x, self.Dimension_endlocation.y, self.Dimension_endlocation.z)
1944                 if b != 0 and c != 0 :
1945                     self.Dimension_angle = degrees(acos((b**2 + c**2 - a**2)/(2*b*c)))
1946                 else:
1947                     self.Dimension_angle = 0
1948
1949     #
1950     if self.Dimension_width == 0:
1951         return {'FINISHED'}
1952
1953     # get verts
1954     if Type == 'Linear-1':
1955         verts = Linear1(self.Dimension_width,
1956                           self.Dimension_length,
1957                           self.Dimension_dsize,
1958                           self.Dimension_depth,
1959                           self.Dimension_depth_from_center,
1960                           self.Dimension_arrow,
1961                           self.Dimension_arrowdepth,
1962                           self.Dimension_arrowlength)
1963
1964     if Type == 'Linear-2':
1965         verts = Linear2(self.Dimension_width,
1966                           self.Dimension_dsize,
1967                           self.Dimension_depth,
1968                           self.Dimension_depth_from_center,
1969                           self.Dimension_arrow,
1970                           self.Dimension_arrowdepth,
1971                           self.Dimension_arrowlength)
1972
1973     if Type == 'Linear-3':
1974         verts = Linear3(self.Dimension_width,
1975                           self.Dimension_length,
1976                           self.Dimension_dsize,
1977                           self.Dimension_depth,
1978                           self.Dimension_depth_from_center,
1979                           self.Dimension_arrow,
1980                           self.Dimension_arrowdepth,
1981                           self.Dimension_arrowlength)
1982
1983     if Type == 'Radius':
1984         verts = Radius(self.Dimension_width,
1985                           self.Dimension_length,
1986                           self.Dimension_dsize,
1987                           self.Dimension_depth,
1988                           self.Dimension_depth_from_center,
1989                           self.Dimension_arrow,
1990                           self.Dimension_arrowdepth,
1991                           self.Dimension_arrowlength)
1992
1993     if Type == 'Diameter':
1994         verts = Diameter(self.Dimension_width,
1995                           self.Dimension_length,
1996                           self.Dimension_dsize,
1997                           self.Dimension_depth,
1998                           self.Dimension_depth_from_center,
1999                           self.Dimension_arrow,
2000                           self.Dimension_arrowdepth,
2001                           self.Dimension_arrowlength)
2002
2003     if Type == 'Angular1':
2004         if self.Dimension_angle == 0:
2005             return {'FINISHED'}
2006         verts = Angular1(self.Dimension_width,
2007                           self.Dimension_length,
2008                           self.Dimension_depth,
2009                           self.Dimension_angle,
2010                           self.Dimension_resolution,
2011                           self.Dimension_depth_from_center,
2012                           self.Dimension_arrow,
2013                           self.Dimension_arrowdepth,
2014                           self.Dimension_arrowlength)
2015
2016     if Type == 'Angular2':
2017         if self.Dimension_angle == 0:
2018             return {'FINISHED'}
2019         verts = Angular2(self.Dimension_width,
2020                           self.Dimension_depth,
2021                           self.Dimension_angle,
2022                           self.Dimension_resolution,
2023                           self.Dimension_arrow,
2024                           self.Dimension_arrowdepth,
2025                           self.Dimension_arrowlength)
2026
2027     if Type == 'Angular3':
2028         if self.Dimension_angle == 0:
2029             return {'FINISHED'}
2030         verts = Angular3(self.Dimension_width,
2031                           self.Dimension_length,
2032                           self.Dimension_dsize,
2033                           self.Dimension_depth,
2034                           self.Dimension_angle,
2035                           self.Dimension_resolution,
2036                           self.Dimension_depth_from_center,
2037                           self.Dimension_arrow,
2038                           self.Dimension_arrowdepth,
2039                           self.Dimension_arrowlength)
2040
2041     if Type == 'Note':
2042         verts = Note(self.Dimension_width,
2043                           self.Dimension_length,
2044                           self.Dimension_depth,
2045                           self.Dimension_angle,
2046                           self.Dimension_arrow,
2047                           self.Dimension_arrowdepth,
2048                           self.Dimension_arrowlength)
2049
2050     vertArray = []
2051     # turn verts into array
2052     for v in verts:
2053         vertArray  += v
2054
2055     # create object
2056     createCurve(vertArray, self, align_matrix)
2057
2058     return
2059
2060 #### Delete dimension group
2061 def DimensionDelete(self, context):
2062
2063     bpy.context.scene.update()
2064     bpy.ops.object.mode_set(mode = 'OBJECT')
2065
2066     bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
2067     bpy.ops.object.delete()
2068     bpy.context.scene.update()
2069
2070     return
2071
2072 class Dimension(bpy.types.Operator):
2073     ''''''
2074     bl_idname = "curve.dimension"
2075     bl_label = "Dimension"
2076     bl_options = {'REGISTER', 'UNDO'}
2077     bl_description = "add dimension"
2078
2079     # align_matrix for the invoke
2080     align_matrix = Matrix()
2081
2082     Dimension = BoolProperty(name = "Dimension",
2083                 default = True,
2084                 description = "dimension")
2085
2086     #### change properties
2087     Dimension_Name = StringProperty(name = "Name",
2088                     description = "Name")
2089
2090     Dimension_Change = BoolProperty(name = "Change",
2091                 default = False,
2092                 description = "change dimension")
2093
2094     Dimension_Delete = StringProperty(name = "Delete",
2095                     description = "Delete dimension")
2096
2097     #### general properties
2098     Types = [('Linear-1', 'Linear-1', 'Linear-1'),
2099              ('Linear-2', 'Linear-2', 'Linear-2'),
2100              ('Linear-3', 'Linear-3', 'Linear-3'),
2101              ('Radius', 'Radius', 'Radius'),
2102              ('Diameter', 'Diameter', 'Diameter'),
2103              ('Angular1', 'Angular1', 'Angular1'),
2104              ('Angular2', 'Angular2', 'Angular2'),
2105              ('Angular3', 'Angular3', 'Angular3'),
2106              ('Note', 'Note', 'Note')]
2107     Dimension_Type = EnumProperty(name = "Type",
2108                 description = "Form of Curve to create",
2109                 items = Types)
2110     XYZTypes = [
2111                 ('TOP', 'Top', 'TOP'),
2112                 ('FRONT', 'Front', 'FRONT'),
2113                 ('RIGHT', 'Right', 'RIGHT'),
2114                 ('BOTTOM', 'Bottom', 'BOTTOM'),
2115                 ('BACK', 'Back', 'BACK'),
2116                 ('LEFT', 'Left', 'LEFT')]
2117     Dimension_XYZType = EnumProperty(name = "Coordinate system",
2118                 description = "Place in a coordinate system",
2119                 items = XYZTypes)
2120     XYTypes = [
2121                 ('X', 'X', 'X'),
2122                 ('Y', 'Y', 'Y')]
2123     Dimension_XYType = EnumProperty(name = "XY",
2124                 description = "XY",
2125                 items = XYTypes)
2126     XZTypes = [
2127                 ('X', 'X', 'X'),
2128                 ('Z', 'Z', 'Z')]
2129     Dimension_XZType = EnumProperty(name = "XZ",
2130                 description = "XZ",
2131                 items = XZTypes)
2132     YZTypes = [
2133                 ('Y', 'Y', 'Y'),
2134                 ('Z', 'Z', 'Z')]
2135     Dimension_YZType = EnumProperty(name = "YZ",
2136                 description = "YZ",
2137                 items = YZTypes)
2138     Dimension_startlocation = FloatVectorProperty(name = "",
2139                 description = "Start location",
2140                 default = (0.0, 0.0, 0.0),
2141                 subtype = 'XYZ')
2142     Dimension_endlocation = FloatVectorProperty(name = "",
2143                 description = "End location",
2144                 default = (2.0, 2.0, 2.0),
2145                 subtype = 'XYZ')
2146     Dimension_endanglelocation = FloatVectorProperty(name = "",
2147                 description = "End angle location",
2148                 default = (4.0, 4.0, 4.0),
2149                 subtype = 'XYZ')
2150     width_or_location_items = [
2151                 ('width', 'width', 'width'),
2152                 ('location', 'location', 'location')]
2153     Dimension_width_or_location = EnumProperty(name = "width or location",
2154                 items = width_or_location_items,
2155                 description = "width or location")
2156     libertyItems = [
2157                 ('2D', '2D', '2D'),
2158                 ('3D', '3D', '3D')]
2159     Dimension_liberty = EnumProperty(name = "2D / 3D",
2160                 items = libertyItems,
2161                 description = "2D or 3D Dimension")
2162
2163     ### Arrow
2164     Arrows = [
2165                 ('Arrow1', 'Arrow1', 'Arrow1'),
2166                 ('Arrow2', 'Arrow2', 'Arrow2'),
2167                 ('Serifs1', 'Serifs1', 'Serifs1'),
2168                 ('Serifs2', 'Serifs2', 'Serifs2'),
2169                 ('Without', 'Without', 'Without')]
2170     Dimension_arrow = EnumProperty(name = "Arrow",
2171                 items = Arrows,
2172                 description = "Arrow")
2173     Dimension_arrowdepth = FloatProperty(name = "Depth",
2174                 default = 0.1,
2175                 min = 0, soft_min = 0,
2176                 description = "Arrow depth")
2177     Dimension_arrowlength = FloatProperty(name = "Length",
2178                 default = 0.25,
2179                 min = 0, soft_min = 0,
2180                 description = "Arrow length")
2181
2182     #### Dimension properties
2183     Dimension_resolution = IntProperty(name = "Resolution",
2184                 default = 10,
2185                 min = 1, soft_min = 1,
2186                 description = "Resolution")
2187     Dimension_width = FloatProperty(name = "Width",
2188                 default = 2,
2189                 unit = 'LENGTH',
2190                 description = "Width")
2191     Dimension_length = FloatProperty(name = "Length",
2192                 default = 2,
2193                 description = "Length")
2194     Dimension_dsize = FloatProperty(name = "Size",
2195                 default = 1,
2196                 min = 0, soft_min = 0,
2197                 description = "Size")
2198     Dimension_depth = FloatProperty(name = "Depth",
2199                 default = 0.1,
2200                 min = 0, soft_min = 0,
2201                 description = "Depth")
2202     Dimension_depth_from_center = BoolProperty(name = "Depth from center",
2203                 default = False,
2204                 description = "Depth from center")
2205     Dimension_angle = FloatProperty(name = "Angle",
2206                 default = 45,
2207                 description = "Angle")
2208     Dimension_rotation = FloatProperty(name = "Rotation",
2209                 default = 0,
2210                 description = "Rotation")
2211     Dimension_offset = FloatProperty(name = "Offset",
2212                 default = 0,
2213                 description = "Offset")
2214
2215     #### Dimension units properties
2216     Units = [
2217                 ('None', 'None', 'None'),
2218                 ('\u00b5m', '\u00b5m', '\u00b5m'),
2219                 ('mm', 'mm', 'mm'),
2220                 ('cm', 'cm', 'cm'),
2221                 ('m', 'm', 'm'),
2222                 ('km', 'km', 'km'),
2223                 ('thou', 'thou', 'thou'),
2224                 ('"', '"', '"'),
2225                 ('\'', '\'', '\''),
2226                 ('yd', 'yd', 'yd'),
2227                 ('mi', 'mi', 'mi')]
2228     Dimension_units = EnumProperty(name = "Units",
2229                 items = Units,
2230                 description = "Units")
2231     Dimension_add_units_name = BoolProperty(name = "Add units name",
2232                 default = False,
2233                 description = "Add units name")
2234
2235     #### Dimension text properties
2236     Dimension_textsize = FloatProperty(name = "Size",
2237                 default = 1,
2238                 description = "Size")
2239     Dimension_textdepth = FloatProperty(name = "Depth",
2240                 default = 0.2,
2241                 description = "Depth")
2242     Dimension_textround = IntProperty(name = "Rounding",
2243                 default = 2,
2244                 min = 0, soft_min = 0,
2245                 description = "Rounding")
2246     Dimension_font = StringProperty(name = "Font",
2247                 default = '',
2248                 subtype = 'FILE_PATH',
2249                 description = "Font")
2250
2251     #### Materials properties
2252     Dimension_matname = StringProperty(name = "Name",
2253                 default = 'Dimension_Red',
2254                 description = "Material name")
2255
2256     #### Note properties
2257     Dimension_note = StringProperty(name = "Note",
2258                 default = 'Note',
2259                 description = "Note text")
2260     Dimension_align_to_camera = BoolProperty(name = "Align to camera",
2261                 default = False,
2262                 description = "Align to camera")
2263
2264     TMP_startlocation = FloatVectorProperty(name = "",
2265                 description = "Start location",
2266                 default = (0.0, 0.0, 0.0),
2267                 subtype = 'XYZ')
2268     TMP_endlocation = FloatVectorProperty(name = "",
2269                 description = "Start location",
2270                 default = (2.0, 2.0, 2.0),
2271                 subtype = 'XYZ')
2272     TMP_endanglelocation = FloatVectorProperty(name = "",
2273                 description = "Start location",
2274                 default = (4.0, 4.0, 4.0),
2275                 subtype = 'XYZ')
2276     #### Parent
2277     Dimension_parent = StringProperty(name = "Parent",
2278                 default = '',
2279                 description = "Parent")
2280     Dimension_appoint_parent = BoolProperty(name = "Appoint parent",
2281                 default = False,
2282                 description = "Appoint parent")
2283
2284     ##### DRAW #####
2285     def draw(self, context):
2286         layout = self.layout
2287
2288         # general options
2289         col = layout.column()
2290         col.prop(self, 'Dimension_Type')
2291
2292         # options per Type Linear-1(width = 2, length = 2, dsize = 1, depth = 0.1)
2293         if self.Dimension_Type == 'Linear-1':
2294             row = layout.row()
2295             row.prop(self, 'Dimension_width_or_location', expand = True)
2296             col = layout.column()
2297             col.label(text = "End location:")
2298             row = layout.row()
2299             if self.Dimension_width_or_location == 'width':
2300                 row.prop(self, 'Dimension_width')
2301             else:
2302                 row.prop(self, 'Dimension_endlocation')
2303             box = layout.box()
2304             box.label("Options")
2305             box.prop(self, 'Dimension_length')
2306             box.prop(self, 'Dimension_dsize')
2307             box.prop(self, 'Dimension_depth')
2308             box.prop(self, 'Dimension_depth_from_center')
2309             box.prop(self, 'Dimension_rotation')
2310             box.prop(self, 'Dimension_offset')
2311
2312         # options per Type Linear-2(width = 2, dsize = 1, depth = 0.1)
2313         if self.Dimension_Type == 'Linear-2':
2314             row = layout.row()
2315             row.prop(self, 'Dimension_width_or_location', expand = True)
2316             col = layout.column()
2317             col.label(text = "End location:")
2318             row = layout.row()
2319             if self.Dimension_width_or_location == 'width':
2320                 row.prop(self, 'Dimension_width')
2321             else:
2322                 row.prop(self, 'Dimension_endlocation')
2323             box = layout.box()
2324             box.label("Options")
2325             box.prop(self, 'Dimension_dsize')
2326             box.prop(self, 'Dimension_depth')
2327             box.prop(self, 'Dimension_rotation')
2328             box.prop(self, 'Dimension_offset')
2329
2330         # options per Type Linear-3(width = 2, length = 2, dsize = 1, depth = 0.1)
2331         if self.Dimension_Type == 'Linear-3':
2332             row = layout.row()
2333             row.prop(self, 'Dimension_width_or_location', expand = True)
2334             col = layout.column()
2335             col.label(text = "End location:")
2336             row = layout.row()
2337             if self.Dimension_width_or_location == 'width':
2338                 row.prop(self, 'Dimension_width')
2339             else:
2340                 row.prop(self, 'Dimension_endlocation')
2341             box = layout.box()
2342             box.label("Options")
2343             box.prop(self, 'Dimension_length')
2344             box.prop(self, 'Dimension_dsize')
2345             box.prop(self, 'Dimension_depth')
2346             box.prop(self, 'Dimension_depth_from_center')
2347             box.prop(self, 'Dimension_rotation')
2348             box.prop(self, 'Dimension_offset')
2349
2350         # options per Type Radius(width = 2, length = 2, dsize = 1, depth = 0.1)
2351         if self.Dimension_Type == 'Radius':
2352             row = layout.row()
2353             row.prop(self, 'Dimension_width_or_location', expand = True)
2354             col = layout.column()
2355             col.label(text = "End location:")
2356             row = layout.row()
2357             if self.Dimension_width_or_location == 'width':
2358                 row.prop(self, 'Dimension_width')
2359             else:
2360                 row.prop(self, 'Dimension_endlocation')
2361             box = layout.box()
2362             box.label("Options")
2363             box.prop(self, 'Dimension_length')
2364             box.prop(self, 'Dimension_dsize')
2365             box.prop(self, 'Dimension_depth')
2366             box.prop(self, 'Dimension_rotation')
2367
2368         # options per Type Diameter(width = 2, length = 2, dsize = 1, depth = 0.1)
2369         if self.Dimension_Type == 'Diameter':
2370             row = layout.row()
2371             row.prop(self, 'Dimension_width_or_location', expand = True)
2372             col = layout.column()
2373             col.label(text = "End location:")
2374             row = layout.row()
2375             if self.Dimension_width_or_location == 'width':
2376                 row.prop(self, 'Dimension_width')
2377             else:
2378                 row.prop(self, 'Dimension_endlocation')
2379             box = layout.box()
2380             box.label("Options")
2381             box.prop(self, 'Dimension_length')
2382             box.prop(self, 'Dimension_dsize')
2383             box.prop(self, 'Dimension_depth')
2384             box.prop(self, 'Dimension_rotation')
2385
2386         # options per Type Angular1(width = 2, dsize = 1, depth = 0.1, angle = 45)
2387         if self.Dimension_Type == 'Angular1':
2388             row = layout.row()
2389             row.prop(self, 'Dimension_width_or_location', expand = True)
2390             col = layout.column()
2391             col.label(text = "End location:")
2392             row = layout.row()
2393             if self.Dimension_width_or_location == 'width':
2394                 row.prop(self, 'Dimension_angle')
2395             else:
2396                 row.prop(self, 'Dimension_endlocation')
2397                 col = layout.column()
2398                 col.label(text = "End angle location:")
2399                 row = layout.row()
2400                 row.prop(self, 'Dimension_endanglelocation')
2401                 row = layout.row()
2402                 props = row.operator("curve.dimension", text = 'Change angle')
2403                 props.Dimension_Change = True
2404                 props.Dimension_Delete = self.Dimension_Name
2405                 props.Dimension_width_or_location = self.Dimension_width_or_location
2406                 props.Dimension_startlocation = self.Dimension_endanglelocation
2407                 props.Dimension_endlocation = self.Dimension_startlocation
2408                 props.Dimension_endanglelocation = self.Dimension_endlocation
2409                 props.Dimension_liberty = self.Dimension_liberty
2410                 props.Dimension_Type = self.Dimension_Type
2411                 props.Dimension_XYZType = self.Dimension_XYZType
2412                 props.Dimension_XYType = self.Dimension_XYType
2413                 props.Dimension_XZType = self.Dimension_XZType
2414                 props.Dimension_YZType = self.Dimension_YZType
2415                 props.Dimension_resolution = self.Dimension_resolution
2416                 props.Dimension_width = self.Dimension_width
2417                 props.Dimension_length = self.Dimension_length
2418                 props.Dimension_dsize = self.Dimension_dsize
2419                 props.Dimension_depth = self.Dimension_depth
2420                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2421                 props.Dimension_angle = self.Dimension_angle
2422                 props.Dimension_rotation = self.Dimension_rotation
2423                 props.Dimension_offset = self.Dimension_offset
2424                 props.Dimension_textsize = self.Dimension_textsize
2425                 props.Dimension_textdepth = self.Dimension_textdepth
2426                 props.Dimension_textround = self.Dimension_textround
2427                 props.Dimension_matname = self.Dimension_matname
2428                 props.Dimension_note = self.Dimension_note
2429                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2430                 props.Dimension_arrow = self.Dimension_arrow
2431                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2432                 props.Dimension_arrowlength = self.Dimension_arrowlength
2433                 props.Dimension_parent = self.Dimension_parent
2434                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2435                 props.Dimension_units = self.Dimension_units
2436                 props.Dimension_add_units_name = self.Dimension_add_units_name
2437             box = layout.box()
2438             box.label("Options")
2439             box.prop(self, 'Dimension_width')
2440             box.prop(self, 'Dimension_length')
2441             box.prop(self, 'Dimension_depth')
2442             box.prop(self, 'Dimension_depth_from_center')
2443             box.prop(self, 'Dimension_rotation')
2444             box.prop(self, 'Dimension_resolution')
2445
2446         # options per Type Angular2(width = 2, dsize = 1, depth = 0.1, angle = 45)
2447         if self.Dimension_Type == 'Angular2':
2448             row = layout.row()
2449             row.prop(self, 'Dimension_width_or_location', expand = True)
2450             col = layout.column()
2451             col.label(text = "End location:")
2452             row = layout.row()
2453             if self.Dimension_width_or_location == 'width':
2454                 row.prop(self, 'Dimension_angle')
2455             else:
2456                 row.prop(self, 'Dimension_endlocation')
2457                 col = layout.column()
2458                 col.label(text = "End angle location:")
2459                 row = layout.row()
2460                 row.prop(self, 'Dimension_endanglelocation')
2461                 row = layout.row()
2462                 props = row.operator("curve.dimension", text = 'Change angle')
2463                 props.Dimension_Change = True
2464                 props.Dimension_Delete = self.Dimension_Name
2465                 props.Dimension_width_or_location = self.Dimension_width_or_location
2466                 props.Dimension_startlocation = self.Dimension_endanglelocation
2467                 props.Dimension_endlocation = self.Dimension_startlocation
2468                 props.Dimension_endanglelocation = self.Dimension_endlocation
2469                 props.Dimension_liberty = self.Dimension_liberty
2470                 props.Dimension_Type = self.Dimension_Type
2471                 props.Dimension_XYZType = self.Dimension_XYZType
2472                 props.Dimension_XYType = self.Dimension_XYType
2473                 props.Dimension_XZType = self.Dimension_XZType
2474                 props.Dimension_YZType = self.Dimension_YZType
2475                 props.Dimension_resolution = self.Dimension_resolution
2476                 props.Dimension_width = self.Dimension_width
2477                 props.Dimension_length = self.Dimension_length
2478                 props.Dimension_dsize = self.Dimension_dsize
2479                 props.Dimension_depth = self.Dimension_depth
2480                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2481                 props.Dimension_angle = self.Dimension_angle
2482                 props.Dimension_rotation = self.Dimension_rotation
2483                 props.Dimension_offset = self.Dimension_offset
2484                 props.Dimension_textsize = self.Dimension_textsize
2485                 props.Dimension_textdepth = self.Dimension_textdepth
2486                 props.Dimension_textround = self.Dimension_textround
2487                 props.Dimension_matname = self.Dimension_matname
2488                 props.Dimension_note = self.Dimension_note
2489                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2490                 props.Dimension_arrow = self.Dimension_arrow
2491                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2492                 props.Dimension_arrowlength = self.Dimension_arrowlength
2493                 props.Dimension_parent = self.Dimension_parent
2494                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2495                 props.Dimension_units = self.Dimension_units
2496                 props.Dimension_add_units_name = self.Dimension_add_units_name
2497             box = layout.box()
2498             box.label("Options")
2499             box.prop(self, 'Dimension_width')
2500             box.prop(self, 'Dimension_depth')
2501             box.prop(self, 'Dimension_rotation')
2502             box.prop(self, 'Dimension_resolution')
2503
2504         # options per Type Angular3(width = 2, dsize = 1, depth = 0.1, angle = 45)
2505         if self.Dimension_Type == 'Angular3':
2506             row = layout.row()
2507             row.prop(self, 'Dimension_width_or_location', expand = True)
2508             col = layout.column()
2509             col.label(text = "End location:")
2510             row = layout.row()
2511             if self.Dimension_width_or_location == 'width':
2512                 row.prop(self, 'Dimension_angle')
2513             else:
2514                 row.prop(self, 'Dimension_endlocation')
2515                 col = layout.column()
2516                 col.label(text = "End angle location:")
2517                 row = layout.row()
2518                 row.prop(self, 'Dimension_endanglelocation')
2519                 row = layout.row()
2520                 props = row.operator("curve.dimension", text = 'Change angle')
2521                 props.Dimension_Change = True
2522                 props.Dimension_Delete = self.Dimension_Name
2523                 props.Dimension_width_or_location = self.Dimension_width_or_location
2524                 props.Dimension_startlocation = self.Dimension_endanglelocation
2525                 props.Dimension_endlocation = self.Dimension_startlocation
2526                 props.Dimension_endanglelocation = self.Dimension_endlocation
2527                 props.Dimension_liberty = self.Dimension_liberty
2528                 props.Dimension_Type = self.Dimension_Type
2529                 props.Dimension_XYZType = self.Dimension_XYZType
2530                 props.Dimension_XYType = self.Dimension_XYType
2531                 props.Dimension_XZType = self.Dimension_XZType
2532                 props.Dimension_YZType = self.Dimension_YZType
2533                 props.Dimension_resolution = self.Dimension_resolution
2534                 props.Dimension_width = self.Dimension_width
2535                 props.Dimension_length = self.Dimension_length
2536                 props.Dimension_dsize = self.Dimension_dsize
2537                 props.Dimension_depth = self.Dimension_depth
2538                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2539                 props.Dimension_angle = self.Dimension_angle
2540                 props.Dimension_rotation = self.Dimension_rotation
2541                 props.Dimension_offset = self.Dimension_offset
2542                 props.Dimension_textsize = self.Dimension_textsize
2543                 props.Dimension_textdepth = self.Dimension_textdepth
2544                 props.Dimension_textround = self.Dimension_textround
2545                 props.Dimension_matname = self.Dimension_matname
2546                 props.Dimension_note = self.Dimension_note
2547                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2548                 props.Dimension_arrow = self.Dimension_arrow
2549                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2550                 props.Dimension_arrowlength = self.Dimension_arrowlength
2551                 props.Dimension_parent = self.Dimension_parent
2552                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2553                 props.Dimension_units = self.Dimension_units
2554                 props.Dimension_add_units_name = self.Dimension_add_units_name
2555             box = layout.box()
2556             box.label("Options")
2557             box.prop(self, 'Dimension_width')
2558             box.prop(self, 'Dimension_length')
2559             box.prop(self, 'Dimension_dsize')
2560             box.prop(self, 'Dimension_depth')
2561             box.prop(self, 'Dimension_depth_from_center')
2562             box.prop(self, 'Dimension_rotation')
2563             box.prop(self, 'Dimension_resolution')
2564
2565         # options per Type Note(width = 2, length = 2, dsize = 1, depth = 0.1)
2566         if self.Dimension_Type == 'Note':
2567             row = layout.row()
2568             row.prop(self, 'Dimension_width_or_location', expand = True)
2569             col = layout.column()
2570             col.label(text = "End location:")
2571             row = layout.row()
2572             if self.Dimension_width_or_location == 'width':
2573                 row.prop(self, 'Dimension_width')
2574             else:
2575                 row.prop(self, 'Dimension_endlocation')
2576             box = layout.box()
2577             box.label("Options")
2578             box.prop(self, 'Dimension_length')
2579             box.prop(self, 'Dimension_depth')
2580             box.prop(self, 'Dimension_angle')
2581             box.prop(self, 'Dimension_rotation')
2582             box.prop(self, 'Dimension_note')
2583             box.prop(self, 'Dimension_offset')
2584
2585         col = layout.column()
2586         row = layout.row()
2587         row.prop(self, 'Dimension_align_to_camera')
2588         col = layout.column()
2589         row = layout.row()
2590         row.prop(self, 'Dimension_liberty', expand = True)
2591
2592         if self.Dimension_liberty == '2D':
2593             col = layout.column()
2594             col.label("Coordinate system")
2595             row = layout.row()
2596             row.prop(self, 'Dimension_XYZType', expand = True)
2597             if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
2598                 row = layout.row()
2599                 row.prop(self, 'Dimension_XYType', expand = True)
2600             if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
2601                 row = layout.row()
2602                 row.prop(self, 'Dimension_XZType', expand = True)
2603             if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
2604                 row = layout.row()
2605                 row.prop(self, 'Dimension_YZType', expand = True)
2606
2607         col = layout.column()
2608         col.label("Start location:")
2609         row = layout.row()
2610         row.prop(self, 'Dimension_startlocation')
2611
2612         box = layout.box()
2613         box.prop(self, 'Dimension_units')
2614         box.prop(self, 'Dimension_add_units_name')
2615
2616         if not self.Dimension_parent == '':
2617             box = layout.box()
2618             box.prop(self, 'Dimension_appoint_parent')
2619
2620         box = layout.box()
2621         box.label("Text Options")
2622         box.prop(self, 'Dimension_textsize')
2623         box.prop(self, 'Dimension_textdepth')
2624         box.prop(self, 'Dimension_textround')
2625         box.prop(self, 'Dimension_font')
2626
2627         box = layout.box()
2628         box.label("Arrow Options")
2629         box.prop(self, 'Dimension_arrow')
2630         box.prop(self, 'Dimension_arrowdepth')
2631         box.prop(self, 'Dimension_arrowlength')
2632
2633         box = layout.box()
2634         box.label("Material Option")
2635         box.prop(self, 'Dimension_matname')
2636
2637     ##### POLL #####
2638     @classmethod
2639     def poll(cls, context):
2640         return context.scene !=  None
2641
2642     ##### EXECUTE #####
2643     def execute(self, context):
2644
2645         if self.Dimension_Change:
2646             DimensionDelete(self, context)
2647
2648         #go to object mode
2649         if bpy.ops.object.mode_set.poll():
2650             bpy.ops.object.mode_set(mode = 'OBJECT')
2651             bpy.context.scene.update()
2652
2653         # turn off undo
2654         undo = bpy.context.preferences.edit.use_global_undo
2655         bpy.context.preferences.edit.use_global_undo = False
2656
2657         # main function
2658         self.align_matrix = align_matrix(context, self.Dimension_startlocation)
2659         main(self, self.align_matrix)
2660
2661         # restore pre operator undo state
2662         bpy.context.preferences.edit.use_global_undo = undo
2663
2664         return {'FINISHED'}
2665
2666     ##### INVOKE #####
2667     def invoke(self, context, event):
2668         bpy.context.scene.update()
2669         if self.Dimension_Change:
2670             bpy.context.scene.cursor.location = self.Dimension_startlocation
2671         else:
2672             if self.Dimension_width_or_location == 'width':
2673                 self.Dimension_startlocation = bpy.context.scene.cursor.location
2674
2675             if self.Dimension_width_or_location == 'location':
2676                 if (self.Dimension_endlocation[2] - self.Dimension_startlocation[2]) !=  0 :
2677                     self.Dimension_XYZType = 'FRONT'
2678                     self.Dimension_XZType = 'Z'
2679                 if (self.Dimension_endlocation[1] - self.Dimension_startlocation[1]) !=  0 :
2680                     self.Dimension_XYZType = 'TOP'
2681                     self.Dimension_XYType = 'Y'
2682                 if (self.Dimension_endlocation[0] - self.Dimension_startlocation[0]) !=  0 :
2683                     self.Dimension_XYZType = 'TOP'
2684                     self.Dimension_XYType = 'X'
2685
2686         self.align_matrix = align_matrix(context, self.Dimension_startlocation)
2687
2688         self.execute(context)
2689
2690         return {'FINISHED'}
2691
2692 # Properties class
2693 class DimensionAdd(bpy.types.Panel):
2694     ''''''
2695     bl_idname = "VIEW3D_PT_properties_dimension_add"
2696     bl_label = "Dimension Add"
2697     bl_description = "Dimension Add"
2698     bl_space_type = "PROPERTIES"
2699     bl_region_type = "WINDOW"
2700     bl_context = "object"
2701
2702     @classmethod
2703     def poll(cls, context):
2704         selected = 0
2705         for obj in context.selected_objects :
2706             if obj.type == 'MESH':
2707                 for i in obj.data.vertices :
2708                     if i.select :
2709                         selected  += 1
2710
2711             if obj.type == 'CURVE':
2712                 for i in obj.data.splines :
2713                     for j in i.bezier_points :
2714                         if j.select_control_point :
2715                             selected  += 1
2716
2717         if selected == 1 or selected == 2 or selected == 3:
2718             return context.selected_objects
2719
2720     ##### DRAW #####
2721     def draw(self, context):
2722         vertex = []
2723         for obj in context.selected_objects :
2724             if obj.type == 'MESH':
2725                 for i in obj.data.vertices :
2726                     if i.select :
2727                         vertex.append(obj.matrix_world * i.co)
2728
2729             if obj.type == 'CURVE':
2730                 for i in obj.data.splines :
2731                     for j in i.bezier_points :
2732                         if j.select_control_point :
2733                             vertex.append(obj.matrix_world * j.co)
2734
2735         if len(vertex) == 1:
2736             startvertex = vertex[0]
2737             endvertex = bpy.context.scene.cursor.location
2738             layout = self.layout
2739             col = layout.column()
2740             col.label(text="Note:")
2741             row = layout.row()
2742             props1 = row.operator("curve.dimension", text = 'Add linear note')
2743             props1.Dimension_Change = False
2744             props1.Dimension_Type = 'Note'
2745             props1.Dimension_width_or_location = 'location'
2746             props1.Dimension_startlocation = startvertex
2747             props1.Dimension_liberty = '2D'
2748             props1.Dimension_rotation = 0
2749             props1.Dimension_parent = obj.name
2750
2751             props2 = row.operator("curve.dimension", text = 'Add 3D note')
2752             props2.Dimension_Change = False
2753             props2.Dimension_Type = 'Note'
2754             props2.Dimension_width_or_location = 'location'
2755             props2.Dimension_startlocation = startvertex
2756             props2.Dimension_liberty = '3D'
2757             props2.Dimension_rotation = 0
2758             props2.Dimension_parent = obj.name
2759
2760             col = layout.column()
2761             col.label(text="Distance to 3D cursor:")
2762             row = layout.row()
2763             props3 = row.operator("curve.dimension", text = 'Add linear dimension')
2764             props3.Dimension_Change = False
2765             props3.Dimension_Type = 'Linear-1'
2766             props3.Dimension_width_or_location = 'location'
2767             props3.Dimension_startlocation = endvertex
2768             props3.Dimension_endlocation = startvertex
2769             props3.Dimension_liberty = '2D'
2770             props3.Dimension_rotation = 0
2771             props3.Dimension_parent = obj.name
2772
2773             props4 = row.operator("curve.dimension", text = 'Add 3D dimension')
2774             props4.Dimension_Change = False
2775             props4.Dimension_Type = 'Linear-1'
2776             props4.Dimension_width_or_location = 'location'
2777             props4.Dimension_startlocation = endvertex
2778             props4.Dimension_endlocation = startvertex
2779             props4.Dimension_liberty = '3D'
2780             props4.Dimension_rotation = 0
2781             props4.Dimension_parent = obj.name
2782
2783             col = layout.column()
2784             col.label(text="Radius to 3D cursor:")
2785             row = layout.row()
2786             props7 = row.operator("curve.dimension", text = 'Add linear radius')
2787             props7.Dimension_Change = False
2788             props7.Dimension_Type = 'Radius'
2789             props7.Dimension_width_or_location = 'location'
2790             props7.Dimension_startlocation = endvertex
2791             props7.Dimension_endlocation = startvertex
2792             props7.Dimension_liberty = '2D'
2793             props7.Dimension_rotation = 0
2794             props7.Dimension_parent = obj.name
2795
2796             props8 = row.operator("curve.dimension", text = 'Add 3D radius')
2797             props8.Dimension_Change = False
2798             props8.Dimension_Type = 'Radius'
2799             props8.Dimension_width_or_location = 'location'
2800             props8.Dimension_startlocation = endvertex
2801             props8.Dimension_endlocation = startvertex
2802             props8.Dimension_liberty = '3D'
2803             props8.Dimension_rotation = 0
2804             props8.Dimension_parent = obj.name
2805
2806             col = layout.column()
2807             col.label(text="Diameter to 3D cursor:")
2808             row = layout.row()
2809             props9 = row.operator("curve.dimension", text = 'Add linear diameter')
2810             props9.Dimension_Change = False
2811             props9.Dimension_Type = 'Diameter'
2812             props9.Dimension_width_or_location = 'location'
2813             props9.Dimension_startlocation = endvertex
2814             props9.Dimension_endlocation = startvertex
2815             props9.Dimension_liberty = '2D'
2816             props9.Dimension_rotation = 0
2817             props9.Dimension_parent = obj.name
2818
2819             props10 = row.operator("curve.dimension", text = 'Add 3D diameter')
2820             props10.Dimension_Change = False
2821             props10.Dimension_Type = 'Diameter'
2822             props10.Dimension_width_or_location = 'location'
2823             props10.Dimension_startlocation = endvertex
2824             props10.Dimension_endlocation = startvertex
2825             props10.Dimension_liberty = '3D'
2826             props10.Dimension_rotation = 0
2827             props10.Dimension_parent = obj.name
2828
2829         if len(vertex) == 2:
2830             startvertex = vertex[0]
2831             endvertex = vertex[1]
2832             if endvertex[0] < startvertex[0]:
2833                 startvertex = vertex[1]
2834                 endvertex = vertex[0]
2835
2836             layout = self.layout
2837             col = layout.column()
2838             col.label(text="Distance:")
2839             row = layout.row()
2840             props1 = row.operator("curve.dimension", text = 'Add linear dimension')
2841             props1.Dimension_Change = False
2842             props1.Dimension_Type = 'Linear-1'
2843             props1.Dimension_width_or_location = 'location'
2844             props1.Dimension_startlocation = startvertex
2845             props1.Dimension_endlocation = endvertex
2846             props1.Dimension_liberty = '2D'
2847             props1.Dimension_rotation = 0
2848             props1.Dimension_parent = obj.name
2849
2850             props2 = row.operator("curve.dimension", text = 'Add 3D dimension')
2851             props2.Dimension_Change = False
2852             props2.Dimension_Type = 'Linear-1'
2853             props2.Dimension_width_or_location = 'location'
2854             props2.Dimension_startlocation = startvertex
2855             props2.Dimension_endlocation = endvertex
2856             props2.Dimension_liberty = '3D'
2857             props2.Dimension_rotation = 0
2858             props2.Dimension_parent = obj.name
2859
2860             col = layout.column()
2861             col.label(text="Radius:")
2862             row = layout.row()
2863             props3 = row.operator("curve.dimension", text = 'Add linear radius')
2864             props3.Dimension_Change = False
2865             props3.Dimension_Type = 'Radius'
2866             props3.Dimension_width_or_location = 'location'
2867             props3.Dimension_startlocation = startvertex
2868             props3.Dimension_endlocation = endvertex
2869             props3.Dimension_liberty = '2D'
2870             props3.Dimension_rotation = 0
2871             props3.Dimension_parent = obj.name
2872
2873             props4 = row.operator("curve.dimension", text = 'Add 3D radius')
2874             props4.Dimension_Change = False
2875             props4.Dimension_Type = 'Radius'
2876             props4.Dimension_width_or_location = 'location'
2877             props4.Dimension_startlocation = startvertex
2878             props4.Dimension_endlocation = endvertex
2879             props4.Dimension_liberty = '3D'
2880             props4.Dimension_rotation = 0
2881             props4.Dimension_parent = obj.name
2882
2883             col = layout.column()
2884             col.label(text="Diameter:")
2885             row = layout.row()
2886             props5 = row.operator("curve.dimension", text = 'Add linear diameter')
2887             props5.Dimension_Change = False
2888             props5.Dimension_Type = 'Diameter'
2889             props5.Dimension_width_or_location = 'location'
2890             props5.Dimension_startlocation = startvertex
2891             props5.Dimension_endlocation = endvertex
2892             props5.Dimension_liberty = '2D'
2893             props5.Dimension_rotation = 0
2894             props5.Dimension_parent = obj.name
2895
2896             props6 = row.operator("curve.dimension", text = 'Add 3D diameter')
2897             props6.Dimension_Change = False
2898             props6.Dimension_Type = 'Diameter'
2899             props6.Dimension_width_or_location = 'location'
2900             props6.Dimension_startlocation = startvertex
2901             props6.Dimension_endlocation = endvertex
2902             props6.Dimension_liberty = '3D'
2903             props6.Dimension_rotation = 0
2904             props6.Dimension_parent = obj.name
2905
2906         if len(vertex) == 3:
2907             startvertex = vertex[0]
2908             endvertex = vertex[1]
2909             endanglevertex = vertex[2]
2910             if endvertex[0] < startvertex[0]:
2911                 startvertex = vertex[1]
2912                 endvertex = vertex[0]
2913
2914             layout = self.layout
2915             col = layout.column()
2916             col.label(text="Angle:")
2917             row = layout.row()
2918             props1 = row.operator("curve.dimension", text = 'Add Linear angle dimension')
2919             props1.Dimension_Change = False
2920             props1.Dimension_Type = 'Angular1'
2921             props1.Dimension_width_or_location = 'location'
2922             props1.Dimension_startlocation = startvertex
2923             props1.Dimension_endlocation = endvertex
2924             props1.Dimension_endanglelocation = endanglevertex
2925             props1.Dimension_liberty = '2D'
2926             props1.Dimension_rotation = 0
2927             props1.Dimension_parent = obj.name
2928
2929             props2 = row.operator("curve.dimension", text = 'Add 3D angle dimension')
2930             props2.Dimension_Change = False
2931             props2.Dimension_Type = 'Angular1'
2932             props2.Dimension_width_or_location = 'location'
2933             props2.Dimension_startlocation = startvertex
2934             props2.Dimension_endlocation = endvertex
2935             props2.Dimension_endanglelocation = endanglevertex
2936             props2.Dimension_liberty = '3D'
2937             props2.Dimension_rotation = 0
2938             props2.Dimension_parent = obj.name
2939
2940 # Properties class
2941 class DimensionPanel(bpy.types.Panel):
2942     ''''''
2943     bl_idname = "OBJECT_PT_properties_dimension"
2944     bl_label = "Dimension change"
2945     bl_description = "Dimension change"
2946     bl_space_type = "PROPERTIES"
2947     bl_region_type = "WINDOW"
2948     bl_context = "object"
2949
2950     @classmethod
2951     def poll(cls, context):
2952         if context.object.Dimension == True:
2953             return (context.object)
2954
2955     ##### DRAW #####
2956     def draw(self, context):
2957         if context.object.Dimension == True:
2958             layout = self.layout
2959
2960             obj = context.object
2961             row = layout.row()
2962
2963             props = row.operator("curve.dimension", text = 'Change')
2964             props.Dimension_Change = True
2965             props.Dimension_Delete = obj.name
2966             props.Dimension_width_or_location = obj.Dimension_width_or_location
2967             props.Dimension_startlocation = obj.location
2968             props.Dimension_endlocation = obj.Dimension_endlocation
2969             props.Dimension_endanglelocation = obj.Dimension_endanglelocation
2970             props.Dimension_liberty = obj.Dimension_liberty
2971             props.Dimension_Type = obj.Dimension_Type
2972             props.Dimension_XYZType = obj.Dimension_XYZType
2973             props.Dimension_XYType = obj.Dimension_XYType
2974             props.Dimension_XZType = obj.Dimension_XZType
2975             props.Dimension_YZType = obj.Dimension_YZType
2976             props.Dimension_resolution = obj.Dimension_resolution
2977             props.Dimension_width = obj.Dimension_width
2978             props.Dimension_length = obj.Dimension_length
2979             props.Dimension_dsize = obj.Dimension_dsize
2980             props.Dimension_depth = obj.Dimension_depth
2981             props.Dimension_depth_from_center = obj.Dimension_depth_from_center
2982             props.Dimension_angle = obj.Dimension_angle
2983             props.Dimension_rotation = obj.Dimension_rotation
2984             props.Dimension_offset = 0
2985             props.Dimension_textsize = obj.Dimension_textsize
2986             props.Dimension_textdepth = obj.Dimension_textdepth
2987             props.Dimension_textround = obj.Dimension_textround
2988             props.Dimension_font = obj.Dimension_font
2989             props.Dimension_matname = obj.Dimension_matname
2990             props.Dimension_note = obj.Dimension_note
2991             props.Dimension_align_to_camera = obj.Dimension_align_to_camera
2992             props.Dimension_arrow = obj.Dimension_arrow
2993             props.Dimension_arrowdepth = obj.Dimension_arrowdepth
2994             props.Dimension_arrowlength = obj.Dimension_arrowlength
2995             props.Dimension_parent = obj.Dimension_parent
2996             props.Dimension_appoint_parent = obj.Dimension_appoint_parent
2997             props.Dimension_units = obj.Dimension_units
2998             props.Dimension_add_units_name = obj.Dimension_add_units_name
2999
3000 #location update
3001 def StartLocationUpdate(self, context):
3002
3003     bpy.context.scene.cursor.location = self.Dimension_startlocation
3004
3005     return
3006
3007 # Add properties to objects
3008 def DimensionVariables():
3009
3010     bpy.types.Object.Dimension = bpy.props.BoolProperty()
3011     bpy.types.Object.Dimension_Change = bpy.props.BoolProperty()
3012     bpy.types.Object.Dimension_Name = bpy.props.StringProperty(name = "Name",
3013                 description = "Name")
3014     #### general properties
3015     Types = [('Linear-1', 'Linear-1', 'Linear-1'),
3016              ('Linear-2', 'Linear-2', 'Linear-2'),
3017              ('Linear-3', 'Linear-3', 'Linear-3'),
3018              ('Radius', 'Radius', 'Radius'),
3019              ('Diameter', 'Diameter', 'Diameter'),
3020              ('Angular1', 'Angular1', 'Angular1'),
3021              ('Angular2', 'Angular2', 'Angular2'),
3022              ('Angular3', 'Angular3', 'Angular3'),
3023              ('Note', 'Note', 'Note')]
3024     bpy.types.Object.Dimension_Type = bpy.props.EnumProperty(name = "Type",
3025                 description = "Form of Curve to create",
3026                 items = Types)
3027     XYZTypes = [
3028                 ('TOP', 'Top', 'TOP'),
3029                 ('FRONT', 'Front', 'FRONT'),
3030                 ('RIGHT', 'Right', 'RIGHT'),
3031                 ('BOTTOM', 'Bottom', 'BOTTOM'),
3032                 ('BACK', 'Back', 'BACK'),
3033                 ('LEFT', 'Left', 'LEFT')]
3034     bpy.types.Object.Dimension_XYZType = bpy.props.EnumProperty(name = "Coordinate system",
3035                 description = "Place in a coordinate system",
3036                 items = XYZTypes)
3037     XYTypes = [
3038                 ('X', 'X', 'X'),
3039                 ('Y', 'Y', 'Y')]
3040     bpy.types.Object.Dimension_XYType = bpy.props.EnumProperty(name = "XY",
3041                 description = "XY",
3042                 items = XYTypes)
3043     XZTypes = [
3044                 ('X', 'X', 'X'),
3045                 ('Z', 'Z', 'Z')]
3046     bpy.types.Object.Dimension_XZType = bpy.props.EnumProperty(name = "XZ",
3047                 description = "XZ",
3048                 items = XZTypes)
3049     YZTypes = [
3050                 ('Y', 'Y', 'Y'),
3051                 ('Z', 'Z', 'Z')]
3052     bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "YZ",
3053                 description = "YZ",
3054                 items = YZTypes)
3055     bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "Coordinate system",
3056                 description = "Place in a coordinate system",
3057                 items = YZTypes)
3058     bpy.types.Object.Dimension_startlocation = bpy.props.FloatVectorProperty(name = "Start location",
3059                 description = "",
3060                 subtype = 'XYZ',
3061                 update = StartLocationUpdate)
3062     bpy.types.Object.Dimension_endlocation = bpy.props.FloatVectorProperty(name = "End location",
3063                 description = "",
3064                 subtype = 'XYZ')
3065     bpy.types.Object.Dimension_endanglelocation = bpy.props.FloatVectorProperty(name = "End angle location",
3066                 description = "End angle location",
3067                 subtype = 'XYZ')
3068     width_or_location_items = [
3069                 ('width', 'width', 'width'),
3070                 ('location', 'location', 'location')]
3071     bpy.types.Object.Dimension_width_or_location = bpy.props.EnumProperty(name = "width or location",
3072                 items = width_or_location_items,
3073                 description = "width or location")
3074     libertyItems = [
3075                 ('2D', '2D', '2D'),
3076                 ('3D', '3D', '3D')]
3077     bpy.types.Object.Dimension_liberty = bpy.props.EnumProperty(name = "2D / 3D",
3078                 items = libertyItems,
3079                 description = "2D or 3D Dimension")
3080
3081     ### Arrow
3082     Arrows = [
3083                 ('Arrow1', 'Arrow1', 'Arrow1'),
3084                 ('Arrow2', 'Arrow2', 'Arrow2'),
3085                 ('Serifs1', 'Serifs1', 'Serifs1'),
3086                 ('Serifs2', 'Serifs2', 'Serifs2'),
3087                 ('Without', 'Without', 'Without')]
3088     bpy.types.Object.Dimension_arrow = bpy.props.EnumProperty(name = "Arrow",
3089                 items = Arrows,
3090                 description = "Arrow")
3091     bpy.types.Object.Dimension_arrowdepth = bpy.props.FloatProperty(name = "Depth",
3092                     min = 0, soft_min = 0,
3093                     description = "Arrow depth")
3094     bpy.types.Object.Dimension_arrowlength = bpy.props.FloatProperty(name = "Length",
3095                     min = 0, soft_min = 0,
3096                     description = "Arrow length")
3097
3098     #### Dimension properties
3099     bpy.types.Object.Dimension_resolution = bpy.props.IntProperty(name = "Resolution",
3100                     min = 1, soft_min = 1,
3101                     description = "Resolution")
3102     bpy.types.Object.Dimension_width = bpy.props.FloatProperty(name = "Width",
3103                     unit = 'LENGTH',
3104                     description = "Width")
3105     bpy.types.Object.Dimension_length = bpy.props.FloatProperty(name = "Length",
3106                     description = "Length")
3107     bpy.types.Object.Dimension_dsize = bpy.props.FloatProperty(name = "Size",
3108                     min = 0, soft_min = 0,
3109                     description = "Size")
3110     bpy.types.Object.Dimension_depth = bpy.props.FloatProperty(name = "Depth",
3111                     min = 0, soft_min = 0,
3112                     description = "Depth")
3113     bpy.types.Object.Dimension_depth_from_center = bpy.props.BoolProperty(name = "Depth from center",
3114                     description = "Depth from center")
3115     bpy.types.Object.Dimension_angle = bpy.props.FloatProperty(name = "Angle",
3116                     description = "Angle")
3117     bpy.types.Object.Dimension_rotation = bpy.props.FloatProperty(name = "Rotation",
3118                     description = "Rotation")
3119
3120     #### Dimension units properties
3121     Units = [
3122                 ('None', 'None', 'None'),
3123                 ('\u00b5m', '\u00b5m', '\u00b5m'),
3124                 ('mm', 'mm', 'mm'),
3125                 ('cm', 'cm', 'cm'),
3126                 ('m', 'm', 'm'),
3127                 ('km', 'km', 'km'),
3128                 ('thou', 'thou', 'thou'),
3129                 ('"', '"', '"'),
3130                 ('\'', '\'', '\''),
3131                 ('yd', 'yd', 'yd'),
3132                 ('mi', 'mi', 'mi')]
3133     bpy.types.Object.Dimension_units = bpy.props.EnumProperty(name = "Units",
3134                 items = Units,
3135                 description = "Units")
3136     bpy.types.Object.Dimension_add_units_name = bpy.props.BoolProperty(name = "Add units name",
3137                 description = "Add units name")
3138     bpy.types.Object.Dimension_offset = bpy.props.FloatProperty(name = "Offset",
3139                 description = "Offset")
3140
3141     #### Dimension text properties
3142     bpy.types.Object.Dimension_textsize = bpy.props.FloatProperty(name = "Size",
3143                     description = "Size")
3144     bpy.types.Object.Dimension_textdepth = bpy.props.FloatProperty(name = "Depth",
3145                     description = "Depth")
3146     bpy.types.Object.Dimension_textround = bpy.props.IntProperty(name = "Rounding",
3147                     min = 0, soft_min = 0,
3148                     description = "Rounding")
3149     bpy.types.Object.Dimension_font = bpy.props.StringProperty(name = "Font",
3150                     subtype = 'FILE_PATH',
3151                     description = "Font")
3152
3153     #### Materials properties
3154     bpy.types.Object.Dimension_matname = bpy.props.StringProperty(name = "Name",
3155                     default = 'Dimension_Red',
3156                     description = "Material name")
3157
3158     #### Note text
3159     bpy.types.Object.Dimension_note = bpy.props.StringProperty(name = "Note",
3160                     default = 'Note',
3161                     description = "Note text")
3162     bpy.types.Object.Dimension_align_to_camera = bpy.props.BoolProperty(name = "Align to camera",
3163                 description = "Align to camera")
3164
3165     #### Parent
3166     bpy.types.Object.Dimension_parent = bpy.props.StringProperty(name = "Parent",
3167                     default = '',
3168                     description = "Parent")
3169     bpy.types.Object.Dimension_appoint_parent = bpy.props.BoolProperty(name = "Appoint parent",
3170                 description = "Appoint parent")
3171
3172 ################################################################################
3173 ##### REGISTER #####
3174
3175 def Dimension_button(self, context):
3176     oper = self.layout.operator(Dimension.bl_idname, text = "Dimension", icon = "PLUGIN")
3177     oper.Dimension_Change = False
3178     oper.Dimension_width_or_location = 'width'
3179     oper.Dimension_liberty = '2D'
3180
3181 def register():
3182     bpy.utils.register_module(__name__)
3183
3184     bpy.types.VIEW3D_MT_curve_add.append(Dimension_button)
3185
3186     DimensionVariables()
3187
3188 def unregister():
3189     bpy.utils.unregister_module(__name__)
3190
3191     bpy.types.VIEW3D_MT_curve_add.remove(Dimension_button)
3192
3193 if __name__ == "__main__":
3194     register()