addons-contrib: more view_layer syntax updates
[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.scene.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     scene = bpy.context.scene
1518     newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
1519     newSpline = newCurve.splines.new('BEZIER') # spline
1520
1521     newSpline.bezier_points.add(int(len(vertArray) * 0.333333333))
1522     newSpline.bezier_points.foreach_set('co', vertArray)
1523
1524     # set curveOptions
1525     newCurve.dimensions = '2D'
1526     newSpline.use_cyclic_u = True
1527     newSpline.use_endpoint_u = True
1528
1529     # create object with newCurve
1530     DimensionCurve = bpy.data.objects.new(name, newCurve) # object
1531     scene.objects.link(DimensionCurve) # place in active scene
1532     DimensionCurve.Dimension = True
1533     DimensionCurve.matrix_world = align_matrix # apply matrix
1534     self.Dimension_Name = DimensionCurve.name
1535
1536     # creat DimensionText and rotation
1537     w = 1
1538     if self.Dimension_width < 0 :
1539         w = -1
1540     l = 1
1541     if self.Dimension_length < 0 :
1542         l = -1
1543
1544     x = self.Dimension_width / 2
1545     y = self.Dimension_length + l * self.Dimension_dsize / 2 + self.Dimension_depth / 2 + self.Dimension_textdepth
1546
1547     gettextround = int(self.Dimension_textround)
1548     stext = addUnits(self.Dimension_width, self.Dimension_units)
1549     stext = abs(round(stext, gettextround))
1550     if gettextround == 0:
1551         stext = abs(int(stext))
1552
1553     align = 'CENTER'
1554     offset_y = 0
1555
1556     if self.Dimension_Type == 'Linear-2':
1557         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1558
1559     if self.Dimension_Type == 'Radius':
1560         x = self.Dimension_width + w * self.Dimension_dsize / 2 + w * abs(self.Dimension_length) / 2
1561         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1562
1563     if self.Dimension_Type == 'Diameter':
1564         x = 0
1565         y = self.Dimension_depth / 2 + self.Dimension_textdepth
1566
1567     g = hypot(x, y)
1568     c = self.Dimension_startlocation
1569     u = asin(y / g)
1570     if self.Dimension_width < 0 :
1571         u = radians(180) - u
1572     xx = cos(u) * g
1573     yy = sin(u) * g
1574
1575     stext = str(stext)
1576     if self.Dimension_units != 'None' and self.Dimension_add_units_name:
1577         stext += self.Dimension_units
1578
1579     if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
1580         xx = cos(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
1581         yy = sin(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
1582         system_rotation = bpy.context.scene.unit_settings.system_rotation
1583         if system_rotation == 'DEGREES':
1584             stext = abs(round(self.Dimension_angle, gettextround))
1585             if gettextround == 0:
1586                 stext = abs(int(stext))
1587             stext = str(stext) + '°'
1588         else:
1589             stext = abs(round(self.Dimension_angle * pi / 180, gettextround))
1590             if gettextround == 0:
1591                 stext = abs(int(stext))
1592             stext = str(stext)
1593         align = 'LEFT'
1594         if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1595             align = 'RIGHT'
1596         if self.Dimension_width < 0 :
1597             offset_y = 0
1598             align = 'RIGHT'
1599             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1600                 align = 'LEFT'
1601
1602     if self.Dimension_Type == 'Note':
1603         if cos(radians(self.Dimension_angle)) > 0:
1604             xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
1605             yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
1606             stext = self.Dimension_note
1607             align = 'LEFT'
1608             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1609                 align = 'RIGHT'
1610             if self.Dimension_width < 0 :
1611                 align = 'RIGHT'
1612                 xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
1613                 yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
1614                 if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1615                    align = 'LEFT'
1616         else:
1617             xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
1618             yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
1619             stext = self.Dimension_note
1620             align = 'RIGHT'
1621             if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1622                 align = 'LEFT'
1623             if self.Dimension_width < 0 :
1624                 align = 'LEFT'
1625                 xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
1626                 yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
1627                 if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1628                     align = 'RIGHT'
1629
1630     if self.Dimension_liberty == '2D':
1631         tv = Vector((xx, yy, 0))
1632
1633         DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
1634
1635         if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1636             DimensionCurve.rotation_euler[0] = radians(0)
1637             DimensionCurve.rotation_euler[1] = radians(0)
1638             if self.Dimension_XYType == 'X':
1639                 DimensionCurve.rotation_euler[2] = radians(self.Dimension_rotation)
1640                 DimensionCurve.location[1] += self.Dimension_offset
1641             if self.Dimension_XYType == 'Y':
1642                 DimensionCurve.rotation_euler[2] = radians(90+self.Dimension_rotation)
1643                 DimensionCurve.location[0] += self.Dimension_offset
1644
1645         if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1646             DimensionCurve.rotation_euler[0] = radians(90)
1647             if self.Dimension_XZType == 'X':
1648                 DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
1649                 DimensionCurve.location[1] += self.Dimension_offset
1650             if self.Dimension_XZType == 'Z':
1651                 DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
1652                 DimensionCurve.location[0] += self.Dimension_offset
1653             DimensionCurve.rotation_euler[2] = radians(0)
1654
1655         if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1656             DimensionCurve.rotation_euler[0] = radians(90)
1657             if self.Dimension_YZType == 'Y':
1658                 DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
1659                 DimensionCurve.location[0] += self.Dimension_offset
1660             if self.Dimension_YZType == 'Z':
1661                 DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
1662                 DimensionCurve.location[1] += self.Dimension_offset
1663             DimensionCurve.rotation_euler[2] = radians(90)
1664
1665         if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'RIGHT':
1666             DimensionText.rotation_euler[1] = radians(0)
1667         if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
1668             DimensionText.rotation_euler[1] = radians(180)
1669
1670         if self.Dimension_width_or_location == 'location':
1671             if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
1672                 vx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
1673                 vy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
1674                 vz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
1675                 if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1676                     g = hypot(vx, vy)
1677                     if g !=  0 :
1678                        u2 = acos(vx / g)
1679                        u1 = asin(vy / g)
1680                        if u1 < 0 :
1681                            u2 = u1
1682                     else:
1683                        u2 = 0
1684                     DimensionCurve.rotation_euler[2] = u2
1685
1686                 if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1687                     g = hypot(vx, vz)
1688                     if g !=  0 :
1689                        u2 = acos(vx / g)
1690                        u1 = asin(vz / g)
1691                        if u1 < 0 :
1692                            u2 = u1
1693                     else:
1694                        u2 = 0
1695                     DimensionCurve.rotation_euler[1] = -u2
1696
1697                 if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1698                     g = hypot(vy, vz)
1699                     if g !=  0 :
1700                        u2 = acos(vy / g)
1701                        u1 = asin(vz / g)
1702                        if u1 < 0 :
1703                            u2 = u1
1704                     else:
1705                        u2 = 0
1706                     DimensionCurve.rotation_euler[1] = -u2
1707
1708     if self.Dimension_liberty == '3D':
1709         tv = Vector((xx, yy, 0))
1710         DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
1711         v = self.Dimension_endlocation - self.Dimension_startlocation
1712         if v.length !=  0 :
1713            u1 = -asin(v[2] / v.length)
1714         else:
1715            u1 = 0
1716         g = hypot(v[0], v[1])
1717         if g !=  0 :
1718            u2 = asin(v[1] / g)
1719            if self.Dimension_endlocation.x < self.Dimension_startlocation.x :
1720               u2 = radians(180)-asin(v[1] / g)
1721         else:
1722            u2 = 0
1723
1724         DimensionCurve.rotation_euler[0] = radians(self.Dimension_rotation)
1725         DimensionCurve.rotation_euler[1] = u1
1726         DimensionCurve.rotation_euler[2] = u2
1727
1728     # Align to view
1729     if self.Dimension_align_to_camera :
1730         obj_camera = bpy.context.scene.camera
1731         DimensionCurve.rotation_euler[0] = obj_camera.rotation_euler[0]
1732         DimensionCurve.rotation_euler[1] = obj_camera.rotation_euler[1]
1733         DimensionCurve.rotation_euler[2] = obj_camera.rotation_euler[2]
1734
1735     # set materials
1736     if self.Dimension_matname in bpy.data.materials :
1737         setMaterial(DimensionCurve, bpy.data.materials[self.Dimension_matname])
1738         setMaterial(DimensionText, bpy.data.materials[self.Dimension_matname])
1739     else:
1740         red = makeMaterial(self.Dimension_matname, (1, 0, 0), (1, 0, 0), 1)
1741         setMaterial(DimensionCurve, red)
1742         setMaterial(DimensionText, red)
1743
1744     setBezierHandles(DimensionCurve, 'VECTOR')
1745     setBezierHandles(DimensionText, 'VECTOR')
1746
1747     group_name = 'Dimensions'
1748
1749     bpy.ops.object.mode_set(mode = 'OBJECT')
1750
1751     if group_name in bpy.data.collections:
1752         group = bpy.data.collections[group_name]
1753     else:
1754         group = bpy.data.collections.new(group_name)
1755
1756     if not DimensionCurve.name in group.objects:
1757         group.objects.link(DimensionCurve)
1758
1759     if not DimensionText.name in group.objects:
1760         group.objects.link(DimensionText)
1761
1762     DimensionText.parent = DimensionCurve
1763
1764     if self.Dimension_appoint_parent and not self.Dimension_parent == '':
1765         const =  DimensionCurve.constraints.new(type='CHILD_OF')
1766         const.target =  bpy.data.objects[self.Dimension_parent]
1767         const.inverse_matrix = bpy.data.objects[self.Dimension_parent].matrix_world.inverted()
1768         bpy.context.scene.update()
1769
1770     bpy.ops.object.select_all(action='DESELECT')
1771     DimensionCurve.select_set(True)
1772     DimensionText.select_set(True)
1773     bpy.context.view_layer.objects.active = DimensionCurve
1774     bpy.context.scene.update()
1775
1776     DimensionCurve.Dimension_Name = self.Dimension_Name
1777     DimensionCurve.Dimension_Type = self.Dimension_Type
1778     DimensionCurve.Dimension_XYZType = self.Dimension_XYZType
1779     DimensionCurve.Dimension_XYType = self.Dimension_XYType
1780     DimensionCurve.Dimension_XZType = self.Dimension_XZType
1781     DimensionCurve.Dimension_YZType = self.Dimension_YZType
1782     DimensionCurve.Dimension_startlocation = c
1783     DimensionCurve.Dimension_endlocation = self.Dimension_endlocation
1784     DimensionCurve.Dimension_endanglelocation = self.Dimension_endanglelocation
1785     DimensionCurve.Dimension_width_or_location = self.Dimension_width_or_location
1786     DimensionCurve.Dimension_liberty = self.Dimension_liberty
1787     DimensionCurve.Dimension_Change = False
1788
1789     #### Dimension properties
1790     DimensionCurve.Dimension_resolution = self.Dimension_resolution
1791     DimensionCurve.Dimension_width = self.Dimension_width
1792     DimensionCurve.Dimension_length = self.Dimension_length
1793     DimensionCurve.Dimension_dsize = self.Dimension_dsize
1794     DimensionCurve.Dimension_depth = self.Dimension_depth
1795     DimensionCurve.Dimension_depth_from_center = self.Dimension_depth_from_center
1796     DimensionCurve.Dimension_angle = self.Dimension_angle
1797     DimensionCurve.Dimension_rotation = self.Dimension_rotation
1798     DimensionCurve.Dimension_offset = self.Dimension_offset
1799
1800     #### Dimension text properties
1801     DimensionCurve.Dimension_textsize = self.Dimension_textsize
1802     DimensionCurve.Dimension_textdepth = self.Dimension_textdepth
1803     DimensionCurve.Dimension_textround = self.Dimension_textround
1804     DimensionCurve.Dimension_font = self.Dimension_font
1805
1806     #### Dimension Arrow properties
1807     DimensionCurve.Dimension_arrow = self.Dimension_arrow
1808     DimensionCurve.Dimension_arrowdepth = self.Dimension_arrowdepth
1809     DimensionCurve.Dimension_arrowlength = self.Dimension_arrowlength
1810
1811     #### Materials properties
1812     DimensionCurve.Dimension_matname = self.Dimension_matname
1813
1814     #### Note properties
1815     DimensionCurve.Dimension_note = self.Dimension_note
1816     DimensionCurve.Dimension_align_to_camera = self.Dimension_align_to_camera
1817
1818     #### Parent
1819     DimensionCurve.Dimension_parent = self.Dimension_parent
1820     DimensionCurve.Dimension_appoint_parent = self.Dimension_appoint_parent
1821
1822     #### Units
1823     DimensionCurve.Dimension_units = self.Dimension_units
1824     DimensionCurve.Dimension_add_units_name = self.Dimension_add_units_name
1825
1826     return
1827
1828 ##------------------------------------------------------------
1829 # Main Function
1830 def main(self, align_matrix):
1831     # deselect all objects
1832     bpy.ops.object.select_all(action = 'DESELECT')
1833
1834     # options
1835     Type = self.Dimension_Type
1836
1837     if self.Dimension_width_or_location == 'location':
1838         if self.Dimension_liberty == '2D':
1839             if self.Dimension_XYZType == 'TOP':
1840                 if self.Dimension_XYType == 'X':
1841                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1842                 if self.Dimension_XYType == 'Y':
1843                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1844             if self.Dimension_XYZType == 'FRONT':
1845                 if self.Dimension_XZType == 'X':
1846                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1847                 if self.Dimension_XZType == 'Z':
1848                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1849             if self.Dimension_XYZType == 'RIGHT':
1850                 if self.Dimension_YZType == 'Y':
1851                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1852                 if self.Dimension_YZType == 'Z':
1853                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1854             if self.Dimension_XYZType == 'BOTTOM':
1855                 if self.Dimension_XYType == 'X':
1856                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1857                 if self.Dimension_XYType == 'Y':
1858                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1859             if self.Dimension_XYZType == 'BACK':
1860                 if self.Dimension_XZType == 'X':
1861                     self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
1862                 if self.Dimension_XZType == 'Z':
1863                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1864             if self.Dimension_XYZType == 'LEFT':
1865                 if self.Dimension_YZType == 'Y':
1866                     self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
1867                 if self.Dimension_YZType == 'Z':
1868                     self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
1869         if self.Dimension_liberty == '3D':
1870             v = self.Dimension_endlocation - self.Dimension_startlocation
1871             self.Dimension_width = v.length
1872
1873         if Type == 'Angular1' or Type == 'Angular2' or Type == 'Angular3':
1874             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)
1875             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)
1876             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)
1877             self.Dimension_width = max(a, b, c)
1878             vanglex = self.Dimension_endanglelocation.x - self.Dimension_startlocation.x
1879             vangley = self.Dimension_endanglelocation.y - self.Dimension_startlocation.y
1880             vanglez = self.Dimension_endanglelocation.z - self.Dimension_startlocation.z
1881             vendx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
1882             vendy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
1883             vendz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
1884             if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
1885                 self.Dimension_XYType = 'X'
1886                 g = hypot(vanglex, vangley)
1887                 if g !=  0 :
1888                    u2 = acos(vanglex / g)
1889                    u1 = asin(vangley / g)
1890                    if u1 < 0 :
1891                        u2 = -u2
1892                 else:
1893                    u2 = 0
1894                 g = hypot(vendx, vendy)
1895                 if g !=  0 :
1896                    uu2 = acos(vendx / g)
1897                    uu1 = asin(vendy / g)
1898                    if uu1 < 0 :
1899                        uu2 = -uu2
1900                 else:
1901                    uu2 = 0
1902                 self.Dimension_angle = degrees(u2 - uu2)
1903             if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
1904                 self.Dimension_XZType = 'Z'
1905                 g = hypot(vanglex, vanglez)
1906                 if g !=  0 :
1907                    u2 = acos(vanglex / g)
1908                    u1 = asin(vanglez / g)
1909                    if u1 < 0 :
1910                        u2 = -u2
1911                 else:
1912                    u2 = 0
1913                 g = hypot(vendx, vendz)
1914                 if g !=  0 :
1915                    uu2 = acos(vendx / g)
1916                    uu1 = asin(vendz / g)
1917                    if uu1 < 0 :
1918                        uu2 = -uu2
1919                 else:
1920                    uu2 = 0
1921                 self.Dimension_angle = degrees(u2 - uu2)
1922             if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
1923                 self.Dimension_YZType = 'Z'
1924                 g = hypot(vangley, vanglez)
1925                 if g !=  0 :
1926                    u2 = acos(vangley / g)
1927                    u1 = asin(vanglez / g)
1928                    if u1 < 0 :
1929                        u2 = -u2
1930                 else:
1931                    u2 = 0
1932                 g = hypot(vendy, vendz)
1933                 if g !=  0 :
1934                    uu2 = acos(vendy / g)
1935                    uu1 = asin(vendz / g)
1936                    if uu1 < 0 :
1937                        uu2 = -uu2
1938                 else:
1939                    uu2 = 0
1940                 self.Dimension_angle = degrees(u2 - uu2)
1941             if self.Dimension_liberty == '3D':
1942                 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)
1943                 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)
1944                 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)
1945                 if b != 0 and c != 0 :
1946                     self.Dimension_angle = degrees(acos((b**2 + c**2 - a**2)/(2*b*c)))
1947                 else:
1948                     self.Dimension_angle = 0
1949
1950     #
1951     if self.Dimension_width == 0:
1952         return {'FINISHED'}
1953
1954     # get verts
1955     if Type == 'Linear-1':
1956         verts = Linear1(self.Dimension_width,
1957                           self.Dimension_length,
1958                           self.Dimension_dsize,
1959                           self.Dimension_depth,
1960                           self.Dimension_depth_from_center,
1961                           self.Dimension_arrow,
1962                           self.Dimension_arrowdepth,
1963                           self.Dimension_arrowlength)
1964
1965     if Type == 'Linear-2':
1966         verts = Linear2(self.Dimension_width,
1967                           self.Dimension_dsize,
1968                           self.Dimension_depth,
1969                           self.Dimension_depth_from_center,
1970                           self.Dimension_arrow,
1971                           self.Dimension_arrowdepth,
1972                           self.Dimension_arrowlength)
1973
1974     if Type == 'Linear-3':
1975         verts = Linear3(self.Dimension_width,
1976                           self.Dimension_length,
1977                           self.Dimension_dsize,
1978                           self.Dimension_depth,
1979                           self.Dimension_depth_from_center,
1980                           self.Dimension_arrow,
1981                           self.Dimension_arrowdepth,
1982                           self.Dimension_arrowlength)
1983
1984     if Type == 'Radius':
1985         verts = Radius(self.Dimension_width,
1986                           self.Dimension_length,
1987                           self.Dimension_dsize,
1988                           self.Dimension_depth,
1989                           self.Dimension_depth_from_center,
1990                           self.Dimension_arrow,
1991                           self.Dimension_arrowdepth,
1992                           self.Dimension_arrowlength)
1993
1994     if Type == 'Diameter':
1995         verts = Diameter(self.Dimension_width,
1996                           self.Dimension_length,
1997                           self.Dimension_dsize,
1998                           self.Dimension_depth,
1999                           self.Dimension_depth_from_center,
2000                           self.Dimension_arrow,
2001                           self.Dimension_arrowdepth,
2002                           self.Dimension_arrowlength)
2003
2004     if Type == 'Angular1':
2005         if self.Dimension_angle == 0:
2006             return {'FINISHED'}
2007         verts = Angular1(self.Dimension_width,
2008                           self.Dimension_length,
2009                           self.Dimension_depth,
2010                           self.Dimension_angle,
2011                           self.Dimension_resolution,
2012                           self.Dimension_depth_from_center,
2013                           self.Dimension_arrow,
2014                           self.Dimension_arrowdepth,
2015                           self.Dimension_arrowlength)
2016
2017     if Type == 'Angular2':
2018         if self.Dimension_angle == 0:
2019             return {'FINISHED'}
2020         verts = Angular2(self.Dimension_width,
2021                           self.Dimension_depth,
2022                           self.Dimension_angle,
2023                           self.Dimension_resolution,
2024                           self.Dimension_arrow,
2025                           self.Dimension_arrowdepth,
2026                           self.Dimension_arrowlength)
2027
2028     if Type == 'Angular3':
2029         if self.Dimension_angle == 0:
2030             return {'FINISHED'}
2031         verts = Angular3(self.Dimension_width,
2032                           self.Dimension_length,
2033                           self.Dimension_dsize,
2034                           self.Dimension_depth,
2035                           self.Dimension_angle,
2036                           self.Dimension_resolution,
2037                           self.Dimension_depth_from_center,
2038                           self.Dimension_arrow,
2039                           self.Dimension_arrowdepth,
2040                           self.Dimension_arrowlength)
2041
2042     if Type == 'Note':
2043         verts = Note(self.Dimension_width,
2044                           self.Dimension_length,
2045                           self.Dimension_depth,
2046                           self.Dimension_angle,
2047                           self.Dimension_arrow,
2048                           self.Dimension_arrowdepth,
2049                           self.Dimension_arrowlength)
2050
2051     vertArray = []
2052     # turn verts into array
2053     for v in verts:
2054         vertArray  += v
2055
2056     # create object
2057     createCurve(vertArray, self, align_matrix)
2058
2059     return
2060
2061 #### Delete dimension group
2062 def DimensionDelete(self, context):
2063
2064     bpy.context.scene.update()
2065     bpy.ops.object.mode_set(mode = 'OBJECT')
2066
2067     bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
2068     bpy.ops.object.delete()
2069     bpy.context.scene.update()
2070
2071     return
2072
2073 class Dimension(bpy.types.Operator):
2074     ''''''
2075     bl_idname = "curve.dimension"
2076     bl_label = "Dimension"
2077     bl_options = {'REGISTER', 'UNDO'}
2078     bl_description = "add dimension"
2079
2080     # align_matrix for the invoke
2081     align_matrix = Matrix()
2082
2083     Dimension = BoolProperty(name = "Dimension",
2084                 default = True,
2085                 description = "dimension")
2086
2087     #### change properties
2088     Dimension_Name = StringProperty(name = "Name",
2089                     description = "Name")
2090
2091     Dimension_Change = BoolProperty(name = "Change",
2092                 default = False,
2093                 description = "change dimension")
2094
2095     Dimension_Delete = StringProperty(name = "Delete",
2096                     description = "Delete dimension")
2097
2098     #### general properties
2099     Types = [('Linear-1', 'Linear-1', 'Linear-1'),
2100              ('Linear-2', 'Linear-2', 'Linear-2'),
2101              ('Linear-3', 'Linear-3', 'Linear-3'),
2102              ('Radius', 'Radius', 'Radius'),
2103              ('Diameter', 'Diameter', 'Diameter'),
2104              ('Angular1', 'Angular1', 'Angular1'),
2105              ('Angular2', 'Angular2', 'Angular2'),
2106              ('Angular3', 'Angular3', 'Angular3'),
2107              ('Note', 'Note', 'Note')]
2108     Dimension_Type = EnumProperty(name = "Type",
2109                 description = "Form of Curve to create",
2110                 items = Types)
2111     XYZTypes = [
2112                 ('TOP', 'Top', 'TOP'),
2113                 ('FRONT', 'Front', 'FRONT'),
2114                 ('RIGHT', 'Right', 'RIGHT'),
2115                 ('BOTTOM', 'Bottom', 'BOTTOM'),
2116                 ('BACK', 'Back', 'BACK'),
2117                 ('LEFT', 'Left', 'LEFT')]
2118     Dimension_XYZType = EnumProperty(name = "Coordinate system",
2119                 description = "Place in a coordinate system",
2120                 items = XYZTypes)
2121     XYTypes = [
2122                 ('X', 'X', 'X'),
2123                 ('Y', 'Y', 'Y')]
2124     Dimension_XYType = EnumProperty(name = "XY",
2125                 description = "XY",
2126                 items = XYTypes)
2127     XZTypes = [
2128                 ('X', 'X', 'X'),
2129                 ('Z', 'Z', 'Z')]
2130     Dimension_XZType = EnumProperty(name = "XZ",
2131                 description = "XZ",
2132                 items = XZTypes)
2133     YZTypes = [
2134                 ('Y', 'Y', 'Y'),
2135                 ('Z', 'Z', 'Z')]
2136     Dimension_YZType = EnumProperty(name = "YZ",
2137                 description = "YZ",
2138                 items = YZTypes)
2139     Dimension_startlocation = FloatVectorProperty(name = "",
2140                 description = "Start location",
2141                 default = (0.0, 0.0, 0.0),
2142                 subtype = 'XYZ')
2143     Dimension_endlocation = FloatVectorProperty(name = "",
2144                 description = "End location",
2145                 default = (2.0, 2.0, 2.0),
2146                 subtype = 'XYZ')
2147     Dimension_endanglelocation = FloatVectorProperty(name = "",
2148                 description = "End angle location",
2149                 default = (4.0, 4.0, 4.0),
2150                 subtype = 'XYZ')
2151     width_or_location_items = [
2152                 ('width', 'width', 'width'),
2153                 ('location', 'location', 'location')]
2154     Dimension_width_or_location = EnumProperty(name = "width or location",
2155                 items = width_or_location_items,
2156                 description = "width or location")
2157     libertyItems = [
2158                 ('2D', '2D', '2D'),
2159                 ('3D', '3D', '3D')]
2160     Dimension_liberty = EnumProperty(name = "2D / 3D",
2161                 items = libertyItems,
2162                 description = "2D or 3D Dimension")
2163
2164     ### Arrow
2165     Arrows = [
2166                 ('Arrow1', 'Arrow1', 'Arrow1'),
2167                 ('Arrow2', 'Arrow2', 'Arrow2'),
2168                 ('Serifs1', 'Serifs1', 'Serifs1'),
2169                 ('Serifs2', 'Serifs2', 'Serifs2'),
2170                 ('Without', 'Without', 'Without')]
2171     Dimension_arrow = EnumProperty(name = "Arrow",
2172                 items = Arrows,
2173                 description = "Arrow")
2174     Dimension_arrowdepth = FloatProperty(name = "Depth",
2175                 default = 0.1,
2176                 min = 0, soft_min = 0,
2177                 description = "Arrow depth")
2178     Dimension_arrowlength = FloatProperty(name = "Length",
2179                 default = 0.25,
2180                 min = 0, soft_min = 0,
2181                 description = "Arrow length")
2182
2183     #### Dimension properties
2184     Dimension_resolution = IntProperty(name = "Resolution",
2185                 default = 10,
2186                 min = 1, soft_min = 1,
2187                 description = "Resolution")
2188     Dimension_width = FloatProperty(name = "Width",
2189                 default = 2,
2190                 unit = 'LENGTH',
2191                 description = "Width")
2192     Dimension_length = FloatProperty(name = "Length",
2193                 default = 2,
2194                 description = "Length")
2195     Dimension_dsize = FloatProperty(name = "Size",
2196                 default = 1,
2197                 min = 0, soft_min = 0,
2198                 description = "Size")
2199     Dimension_depth = FloatProperty(name = "Depth",
2200                 default = 0.1,
2201                 min = 0, soft_min = 0,
2202                 description = "Depth")
2203     Dimension_depth_from_center = BoolProperty(name = "Depth from center",
2204                 default = False,
2205                 description = "Depth from center")
2206     Dimension_angle = FloatProperty(name = "Angle",
2207                 default = 45,
2208                 description = "Angle")
2209     Dimension_rotation = FloatProperty(name = "Rotation",
2210                 default = 0,
2211                 description = "Rotation")
2212     Dimension_offset = FloatProperty(name = "Offset",
2213                 default = 0,
2214                 description = "Offset")
2215
2216     #### Dimension units properties
2217     Units = [
2218                 ('None', 'None', 'None'),
2219                 ('\u00b5m', '\u00b5m', '\u00b5m'),
2220                 ('mm', 'mm', 'mm'),
2221                 ('cm', 'cm', 'cm'),
2222                 ('m', 'm', 'm'),
2223                 ('km', 'km', 'km'),
2224                 ('thou', 'thou', 'thou'),
2225                 ('"', '"', '"'),
2226                 ('\'', '\'', '\''),
2227                 ('yd', 'yd', 'yd'),
2228                 ('mi', 'mi', 'mi')]
2229     Dimension_units = EnumProperty(name = "Units",
2230                 items = Units,
2231                 description = "Units")
2232     Dimension_add_units_name = BoolProperty(name = "Add units name",
2233                 default = False,
2234                 description = "Add units name")
2235
2236     #### Dimension text properties
2237     Dimension_textsize = FloatProperty(name = "Size",
2238                 default = 1,
2239                 description = "Size")
2240     Dimension_textdepth = FloatProperty(name = "Depth",
2241                 default = 0.2,
2242                 description = "Depth")
2243     Dimension_textround = IntProperty(name = "Rounding",
2244                 default = 2,
2245                 min = 0, soft_min = 0,
2246                 description = "Rounding")
2247     Dimension_font = StringProperty(name = "Font",
2248                 default = '',
2249                 subtype = 'FILE_PATH',
2250                 description = "Font")
2251
2252     #### Materials properties
2253     Dimension_matname = StringProperty(name = "Name",
2254                 default = 'Dimension_Red',
2255                 description = "Material name")
2256
2257     #### Note properties
2258     Dimension_note = StringProperty(name = "Note",
2259                 default = 'Note',
2260                 description = "Note text")
2261     Dimension_align_to_camera = BoolProperty(name = "Align to camera",
2262                 default = False,
2263                 description = "Align to camera")
2264
2265     TMP_startlocation = FloatVectorProperty(name = "",
2266                 description = "Start location",
2267                 default = (0.0, 0.0, 0.0),
2268                 subtype = 'XYZ')
2269     TMP_endlocation = FloatVectorProperty(name = "",
2270                 description = "Start location",
2271                 default = (2.0, 2.0, 2.0),
2272                 subtype = 'XYZ')
2273     TMP_endanglelocation = FloatVectorProperty(name = "",
2274                 description = "Start location",
2275                 default = (4.0, 4.0, 4.0),
2276                 subtype = 'XYZ')
2277     #### Parent
2278     Dimension_parent = StringProperty(name = "Parent",
2279                 default = '',
2280                 description = "Parent")
2281     Dimension_appoint_parent = BoolProperty(name = "Appoint parent",
2282                 default = False,
2283                 description = "Appoint parent")
2284
2285     ##### DRAW #####
2286     def draw(self, context):
2287         layout = self.layout
2288
2289         # general options
2290         col = layout.column()
2291         col.prop(self, 'Dimension_Type')
2292
2293         # options per Type Linear-1(width = 2, length = 2, dsize = 1, depth = 0.1)
2294         if self.Dimension_Type == 'Linear-1':
2295             row = layout.row()
2296             row.prop(self, 'Dimension_width_or_location', expand = True)
2297             col = layout.column()
2298             col.label(text = "End location:")
2299             row = layout.row()
2300             if self.Dimension_width_or_location == 'width':
2301                 row.prop(self, 'Dimension_width')
2302             else:
2303                 row.prop(self, 'Dimension_endlocation')
2304             box = layout.box()
2305             box.label("Options")
2306             box.prop(self, 'Dimension_length')
2307             box.prop(self, 'Dimension_dsize')
2308             box.prop(self, 'Dimension_depth')
2309             box.prop(self, 'Dimension_depth_from_center')
2310             box.prop(self, 'Dimension_rotation')
2311             box.prop(self, 'Dimension_offset')
2312
2313         # options per Type Linear-2(width = 2, dsize = 1, depth = 0.1)
2314         if self.Dimension_Type == 'Linear-2':
2315             row = layout.row()
2316             row.prop(self, 'Dimension_width_or_location', expand = True)
2317             col = layout.column()
2318             col.label(text = "End location:")
2319             row = layout.row()
2320             if self.Dimension_width_or_location == 'width':
2321                 row.prop(self, 'Dimension_width')
2322             else:
2323                 row.prop(self, 'Dimension_endlocation')
2324             box = layout.box()
2325             box.label("Options")
2326             box.prop(self, 'Dimension_dsize')
2327             box.prop(self, 'Dimension_depth')
2328             box.prop(self, 'Dimension_rotation')
2329             box.prop(self, 'Dimension_offset')
2330
2331         # options per Type Linear-3(width = 2, length = 2, dsize = 1, depth = 0.1)
2332         if self.Dimension_Type == 'Linear-3':
2333             row = layout.row()
2334             row.prop(self, 'Dimension_width_or_location', expand = True)
2335             col = layout.column()
2336             col.label(text = "End location:")
2337             row = layout.row()
2338             if self.Dimension_width_or_location == 'width':
2339                 row.prop(self, 'Dimension_width')
2340             else:
2341                 row.prop(self, 'Dimension_endlocation')
2342             box = layout.box()
2343             box.label("Options")
2344             box.prop(self, 'Dimension_length')
2345             box.prop(self, 'Dimension_dsize')
2346             box.prop(self, 'Dimension_depth')
2347             box.prop(self, 'Dimension_depth_from_center')
2348             box.prop(self, 'Dimension_rotation')
2349             box.prop(self, 'Dimension_offset')
2350
2351         # options per Type Radius(width = 2, length = 2, dsize = 1, depth = 0.1)
2352         if self.Dimension_Type == 'Radius':
2353             row = layout.row()
2354             row.prop(self, 'Dimension_width_or_location', expand = True)
2355             col = layout.column()
2356             col.label(text = "End location:")
2357             row = layout.row()
2358             if self.Dimension_width_or_location == 'width':
2359                 row.prop(self, 'Dimension_width')
2360             else:
2361                 row.prop(self, 'Dimension_endlocation')
2362             box = layout.box()
2363             box.label("Options")
2364             box.prop(self, 'Dimension_length')
2365             box.prop(self, 'Dimension_dsize')
2366             box.prop(self, 'Dimension_depth')
2367             box.prop(self, 'Dimension_rotation')
2368
2369         # options per Type Diameter(width = 2, length = 2, dsize = 1, depth = 0.1)
2370         if self.Dimension_Type == 'Diameter':
2371             row = layout.row()
2372             row.prop(self, 'Dimension_width_or_location', expand = True)
2373             col = layout.column()
2374             col.label(text = "End location:")
2375             row = layout.row()
2376             if self.Dimension_width_or_location == 'width':
2377                 row.prop(self, 'Dimension_width')
2378             else:
2379                 row.prop(self, 'Dimension_endlocation')
2380             box = layout.box()
2381             box.label("Options")
2382             box.prop(self, 'Dimension_length')
2383             box.prop(self, 'Dimension_dsize')
2384             box.prop(self, 'Dimension_depth')
2385             box.prop(self, 'Dimension_rotation')
2386
2387         # options per Type Angular1(width = 2, dsize = 1, depth = 0.1, angle = 45)
2388         if self.Dimension_Type == 'Angular1':
2389             row = layout.row()
2390             row.prop(self, 'Dimension_width_or_location', expand = True)
2391             col = layout.column()
2392             col.label(text = "End location:")
2393             row = layout.row()
2394             if self.Dimension_width_or_location == 'width':
2395                 row.prop(self, 'Dimension_angle')
2396             else:
2397                 row.prop(self, 'Dimension_endlocation')
2398                 col = layout.column()
2399                 col.label(text = "End angle location:")
2400                 row = layout.row()
2401                 row.prop(self, 'Dimension_endanglelocation')
2402                 row = layout.row()
2403                 props = row.operator("curve.dimension", text = 'Change angle')
2404                 props.Dimension_Change = True
2405                 props.Dimension_Delete = self.Dimension_Name
2406                 props.Dimension_width_or_location = self.Dimension_width_or_location
2407                 props.Dimension_startlocation = self.Dimension_endanglelocation
2408                 props.Dimension_endlocation = self.Dimension_startlocation
2409                 props.Dimension_endanglelocation = self.Dimension_endlocation
2410                 props.Dimension_liberty = self.Dimension_liberty
2411                 props.Dimension_Type = self.Dimension_Type
2412                 props.Dimension_XYZType = self.Dimension_XYZType
2413                 props.Dimension_XYType = self.Dimension_XYType
2414                 props.Dimension_XZType = self.Dimension_XZType
2415                 props.Dimension_YZType = self.Dimension_YZType
2416                 props.Dimension_resolution = self.Dimension_resolution
2417                 props.Dimension_width = self.Dimension_width
2418                 props.Dimension_length = self.Dimension_length
2419                 props.Dimension_dsize = self.Dimension_dsize
2420                 props.Dimension_depth = self.Dimension_depth
2421                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2422                 props.Dimension_angle = self.Dimension_angle
2423                 props.Dimension_rotation = self.Dimension_rotation
2424                 props.Dimension_offset = self.Dimension_offset
2425                 props.Dimension_textsize = self.Dimension_textsize
2426                 props.Dimension_textdepth = self.Dimension_textdepth
2427                 props.Dimension_textround = self.Dimension_textround
2428                 props.Dimension_matname = self.Dimension_matname
2429                 props.Dimension_note = self.Dimension_note
2430                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2431                 props.Dimension_arrow = self.Dimension_arrow
2432                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2433                 props.Dimension_arrowlength = self.Dimension_arrowlength
2434                 props.Dimension_parent = self.Dimension_parent
2435                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2436                 props.Dimension_units = self.Dimension_units
2437                 props.Dimension_add_units_name = self.Dimension_add_units_name
2438             box = layout.box()
2439             box.label("Options")
2440             box.prop(self, 'Dimension_width')
2441             box.prop(self, 'Dimension_length')
2442             box.prop(self, 'Dimension_depth')
2443             box.prop(self, 'Dimension_depth_from_center')
2444             box.prop(self, 'Dimension_rotation')
2445             box.prop(self, 'Dimension_resolution')
2446
2447         # options per Type Angular2(width = 2, dsize = 1, depth = 0.1, angle = 45)
2448         if self.Dimension_Type == 'Angular2':
2449             row = layout.row()
2450             row.prop(self, 'Dimension_width_or_location', expand = True)
2451             col = layout.column()
2452             col.label(text = "End location:")
2453             row = layout.row()
2454             if self.Dimension_width_or_location == 'width':
2455                 row.prop(self, 'Dimension_angle')
2456             else:
2457                 row.prop(self, 'Dimension_endlocation')
2458                 col = layout.column()
2459                 col.label(text = "End angle location:")
2460                 row = layout.row()
2461                 row.prop(self, 'Dimension_endanglelocation')
2462                 row = layout.row()
2463                 props = row.operator("curve.dimension", text = 'Change angle')
2464                 props.Dimension_Change = True
2465                 props.Dimension_Delete = self.Dimension_Name
2466                 props.Dimension_width_or_location = self.Dimension_width_or_location
2467                 props.Dimension_startlocation = self.Dimension_endanglelocation
2468                 props.Dimension_endlocation = self.Dimension_startlocation
2469                 props.Dimension_endanglelocation = self.Dimension_endlocation
2470                 props.Dimension_liberty = self.Dimension_liberty
2471                 props.Dimension_Type = self.Dimension_Type
2472                 props.Dimension_XYZType = self.Dimension_XYZType
2473                 props.Dimension_XYType = self.Dimension_XYType
2474                 props.Dimension_XZType = self.Dimension_XZType
2475                 props.Dimension_YZType = self.Dimension_YZType
2476                 props.Dimension_resolution = self.Dimension_resolution
2477                 props.Dimension_width = self.Dimension_width
2478                 props.Dimension_length = self.Dimension_length
2479                 props.Dimension_dsize = self.Dimension_dsize
2480                 props.Dimension_depth = self.Dimension_depth
2481                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2482                 props.Dimension_angle = self.Dimension_angle
2483                 props.Dimension_rotation = self.Dimension_rotation
2484                 props.Dimension_offset = self.Dimension_offset
2485                 props.Dimension_textsize = self.Dimension_textsize
2486                 props.Dimension_textdepth = self.Dimension_textdepth
2487                 props.Dimension_textround = self.Dimension_textround
2488                 props.Dimension_matname = self.Dimension_matname
2489                 props.Dimension_note = self.Dimension_note
2490                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2491                 props.Dimension_arrow = self.Dimension_arrow
2492                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2493                 props.Dimension_arrowlength = self.Dimension_arrowlength
2494                 props.Dimension_parent = self.Dimension_parent
2495                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2496                 props.Dimension_units = self.Dimension_units
2497                 props.Dimension_add_units_name = self.Dimension_add_units_name
2498             box = layout.box()
2499             box.label("Options")
2500             box.prop(self, 'Dimension_width')
2501             box.prop(self, 'Dimension_depth')
2502             box.prop(self, 'Dimension_rotation')
2503             box.prop(self, 'Dimension_resolution')
2504
2505         # options per Type Angular3(width = 2, dsize = 1, depth = 0.1, angle = 45)
2506         if self.Dimension_Type == 'Angular3':
2507             row = layout.row()
2508             row.prop(self, 'Dimension_width_or_location', expand = True)
2509             col = layout.column()
2510             col.label(text = "End location:")
2511             row = layout.row()
2512             if self.Dimension_width_or_location == 'width':
2513                 row.prop(self, 'Dimension_angle')
2514             else:
2515                 row.prop(self, 'Dimension_endlocation')
2516                 col = layout.column()
2517                 col.label(text = "End angle location:")
2518                 row = layout.row()
2519                 row.prop(self, 'Dimension_endanglelocation')
2520                 row = layout.row()
2521                 props = row.operator("curve.dimension", text = 'Change angle')
2522                 props.Dimension_Change = True
2523                 props.Dimension_Delete = self.Dimension_Name
2524                 props.Dimension_width_or_location = self.Dimension_width_or_location
2525                 props.Dimension_startlocation = self.Dimension_endanglelocation
2526                 props.Dimension_endlocation = self.Dimension_startlocation
2527                 props.Dimension_endanglelocation = self.Dimension_endlocation
2528                 props.Dimension_liberty = self.Dimension_liberty
2529                 props.Dimension_Type = self.Dimension_Type
2530                 props.Dimension_XYZType = self.Dimension_XYZType
2531                 props.Dimension_XYType = self.Dimension_XYType
2532                 props.Dimension_XZType = self.Dimension_XZType
2533                 props.Dimension_YZType = self.Dimension_YZType
2534                 props.Dimension_resolution = self.Dimension_resolution
2535                 props.Dimension_width = self.Dimension_width
2536                 props.Dimension_length = self.Dimension_length
2537                 props.Dimension_dsize = self.Dimension_dsize
2538                 props.Dimension_depth = self.Dimension_depth
2539                 props.Dimension_depth_from_center = self.Dimension_depth_from_center
2540                 props.Dimension_angle = self.Dimension_angle
2541                 props.Dimension_rotation = self.Dimension_rotation
2542                 props.Dimension_offset = self.Dimension_offset
2543                 props.Dimension_textsize = self.Dimension_textsize
2544                 props.Dimension_textdepth = self.Dimension_textdepth
2545                 props.Dimension_textround = self.Dimension_textround
2546                 props.Dimension_matname = self.Dimension_matname
2547                 props.Dimension_note = self.Dimension_note
2548                 props.Dimension_align_to_camera = self.Dimension_align_to_camera
2549                 props.Dimension_arrow = self.Dimension_arrow
2550                 props.Dimension_arrowdepth = self.Dimension_arrowdepth
2551                 props.Dimension_arrowlength = self.Dimension_arrowlength
2552                 props.Dimension_parent = self.Dimension_parent
2553                 props.Dimension_appoint_parent = self.Dimension_appoint_parent
2554                 props.Dimension_units = self.Dimension_units
2555                 props.Dimension_add_units_name = self.Dimension_add_units_name
2556             box = layout.box()
2557             box.label("Options")
2558             box.prop(self, 'Dimension_width')
2559             box.prop(self, 'Dimension_length')
2560             box.prop(self, 'Dimension_dsize')
2561             box.prop(self, 'Dimension_depth')
2562             box.prop(self, 'Dimension_depth_from_center')
2563             box.prop(self, 'Dimension_rotation')
2564             box.prop(self, 'Dimension_resolution')
2565
2566         # options per Type Note(width = 2, length = 2, dsize = 1, depth = 0.1)
2567         if self.Dimension_Type == 'Note':
2568             row = layout.row()
2569             row.prop(self, 'Dimension_width_or_location', expand = True)
2570             col = layout.column()
2571             col.label(text = "End location:")
2572             row = layout.row()
2573             if self.Dimension_width_or_location == 'width':
2574                 row.prop(self, 'Dimension_width')
2575             else:
2576                 row.prop(self, 'Dimension_endlocation')
2577             box = layout.box()
2578             box.label("Options")
2579             box.prop(self, 'Dimension_length')
2580             box.prop(self, 'Dimension_depth')
2581             box.prop(self, 'Dimension_angle')
2582             box.prop(self, 'Dimension_rotation')
2583             box.prop(self, 'Dimension_note')
2584             box.prop(self, 'Dimension_offset')
2585
2586         col = layout.column()
2587         row = layout.row()
2588         row.prop(self, 'Dimension_align_to_camera')
2589         col = layout.column()
2590         row = layout.row()
2591         row.prop(self, 'Dimension_liberty', expand = True)
2592
2593         if self.Dimension_liberty == '2D':
2594             col = layout.column()
2595             col.label("Coordinate system")
2596             row = layout.row()
2597             row.prop(self, 'Dimension_XYZType', expand = True)
2598             if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
2599                 row = layout.row()
2600                 row.prop(self, 'Dimension_XYType', expand = True)
2601             if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
2602                 row = layout.row()
2603                 row.prop(self, 'Dimension_XZType', expand = True)
2604             if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
2605                 row = layout.row()
2606                 row.prop(self, 'Dimension_YZType', expand = True)
2607
2608         col = layout.column()
2609         col.label("Start location:")
2610         row = layout.row()
2611         row.prop(self, 'Dimension_startlocation')
2612
2613         box = layout.box()
2614         box.prop(self, 'Dimension_units')
2615         box.prop(self, 'Dimension_add_units_name')
2616
2617         if not self.Dimension_parent == '':
2618             box = layout.box()
2619             box.prop(self, 'Dimension_appoint_parent')
2620
2621         box = layout.box()
2622         box.label("Text Options")
2623         box.prop(self, 'Dimension_textsize')
2624         box.prop(self, 'Dimension_textdepth')
2625         box.prop(self, 'Dimension_textround')
2626         box.prop(self, 'Dimension_font')
2627
2628         box = layout.box()
2629         box.label("Arrow Options")
2630         box.prop(self, 'Dimension_arrow')
2631         box.prop(self, 'Dimension_arrowdepth')
2632         box.prop(self, 'Dimension_arrowlength')
2633
2634         box = layout.box()
2635         box.label("Material Option")
2636         box.prop(self, 'Dimension_matname')
2637
2638     ##### POLL #####
2639     @classmethod
2640     def poll(cls, context):
2641         return context.scene !=  None
2642
2643     ##### EXECUTE #####
2644     def execute(self, context):
2645
2646         if self.Dimension_Change:
2647             DimensionDelete(self, context)
2648
2649         #go to object mode
2650         if bpy.ops.object.mode_set.poll():
2651             bpy.ops.object.mode_set(mode = 'OBJECT')
2652             bpy.context.scene.update()
2653
2654         # turn off undo
2655         undo = bpy.context.preferences.edit.use_global_undo
2656         bpy.context.preferences.edit.use_global_undo = False
2657
2658         # main function
2659         self.align_matrix = align_matrix(context, self.Dimension_startlocation)
2660         main(self, self.align_matrix)
2661
2662         # restore pre operator undo state
2663         bpy.context.preferences.edit.use_global_undo = undo
2664
2665         return {'FINISHED'}
2666
2667     ##### INVOKE #####
2668     def invoke(self, context, event):
2669         bpy.context.scene.update()
2670         if self.Dimension_Change:
2671             bpy.context.scene.cursor_location = self.Dimension_startlocation
2672         else:
2673             if self.Dimension_width_or_location == 'width':
2674                 self.Dimension_startlocation = bpy.context.scene.cursor_location
2675
2676             if self.Dimension_width_or_location == 'location':
2677                 if (self.Dimension_endlocation[2] - self.Dimension_startlocation[2]) !=  0 :
2678                     self.Dimension_XYZType = 'FRONT'
2679                     self.Dimension_XZType = 'Z'
2680                 if (self.Dimension_endlocation[1] - self.Dimension_startlocation[1]) !=  0 :
2681                     self.Dimension_XYZType = 'TOP'
2682                     self.Dimension_XYType = 'Y'
2683                 if (self.Dimension_endlocation[0] - self.Dimension_startlocation[0]) !=  0 :
2684                     self.Dimension_XYZType = 'TOP'
2685                     self.Dimension_XYType = 'X'
2686
2687         self.align_matrix = align_matrix(context, self.Dimension_startlocation)
2688
2689         self.execute(context)
2690
2691         return {'FINISHED'}
2692
2693 # Properties class
2694 class DimensionAdd(bpy.types.Panel):
2695     ''''''
2696     bl_idname = "VIEW3D_PT_properties_dimension_add"
2697     bl_label = "Dimension Add"
2698     bl_description = "Dimension Add"
2699     bl_space_type = "PROPERTIES"
2700     bl_region_type = "WINDOW"
2701     bl_context = "object"
2702
2703     @classmethod
2704     def poll(cls, context):
2705         selected = 0
2706         for obj in context.selected_objects :
2707             if obj.type == 'MESH':
2708                 for i in obj.data.vertices :
2709                     if i.select :
2710                         selected  += 1
2711
2712             if obj.type == 'CURVE':
2713                 for i in obj.data.splines :
2714                     for j in i.bezier_points :
2715                         if j.select_control_point :
2716                             selected  += 1
2717
2718         if selected == 1 or selected == 2 or selected == 3:
2719             return context.selected_objects
2720
2721     ##### DRAW #####
2722     def draw(self, context):
2723         vertex = []
2724         for obj in context.selected_objects :
2725             if obj.type == 'MESH':
2726                 for i in obj.data.vertices :
2727                     if i.select :
2728                         vertex.append(obj.matrix_world * i.co)
2729
2730             if obj.type == 'CURVE':
2731                 for i in obj.data.splines :
2732                     for j in i.bezier_points :
2733                         if j.select_control_point :
2734                             vertex.append(obj.matrix_world * j.co)
2735
2736         if len(vertex) == 1:
2737             startvertex = vertex[0]
2738             endvertex = bpy.context.scene.cursor_location
2739             layout = self.layout
2740             col = layout.column()
2741             col.label(text="Note:")
2742             row = layout.row()
2743             props1 = row.operator("curve.dimension", text = 'Add linear note')
2744             props1.Dimension_Change = False
2745             props1.Dimension_Type = 'Note'
2746             props1.Dimension_width_or_location = 'location'
2747             props1.Dimension_startlocation = startvertex
2748             props1.Dimension_liberty = '2D'
2749             props1.Dimension_rotation = 0
2750             props1.Dimension_parent = obj.name
2751
2752             props2 = row.operator("curve.dimension", text = 'Add 3D note')
2753             props2.Dimension_Change = False
2754             props2.Dimension_Type = 'Note'
2755             props2.Dimension_width_or_location = 'location'
2756             props2.Dimension_startlocation = startvertex
2757             props2.Dimension_liberty = '3D'
2758             props2.Dimension_rotation = 0
2759             props2.Dimension_parent = obj.name
2760
2761             col = layout.column()
2762             col.label(text="Distance to 3D cursor:")
2763             row = layout.row()
2764             props3 = row.operator("curve.dimension", text = 'Add linear dimension')
2765             props3.Dimension_Change = False
2766             props3.Dimension_Type = 'Linear-1'
2767             props3.Dimension_width_or_location = 'location'
2768             props3.Dimension_startlocation = endvertex
2769             props3.Dimension_endlocation = startvertex
2770             props3.Dimension_liberty = '2D'
2771             props3.Dimension_rotation = 0
2772             props3.Dimension_parent = obj.name
2773
2774             props4 = row.operator("curve.dimension", text = 'Add 3D dimension')
2775             props4.Dimension_Change = False
2776             props4.Dimension_Type = 'Linear-1'
2777             props4.Dimension_width_or_location = 'location'
2778             props4.Dimension_startlocation = endvertex
2779             props4.Dimension_endlocation = startvertex
2780             props4.Dimension_liberty = '3D'
2781             props4.Dimension_rotation = 0
2782             props4.Dimension_parent = obj.name
2783
2784             col = layout.column()
2785             col.label(text="Radius to 3D cursor:")
2786             row = layout.row()
2787             props7 = row.operator("curve.dimension", text = 'Add linear radius')
2788             props7.Dimension_Change = False
2789             props7.Dimension_Type = 'Radius'
2790             props7.Dimension_width_or_location = 'location'
2791             props7.Dimension_startlocation = endvertex
2792             props7.Dimension_endlocation = startvertex
2793             props7.Dimension_liberty = '2D'
2794             props7.Dimension_rotation = 0
2795             props7.Dimension_parent = obj.name
2796
2797             props8 = row.operator("curve.dimension", text = 'Add 3D radius')
2798             props8.Dimension_Change = False
2799             props8.Dimension_Type = 'Radius'
2800             props8.Dimension_width_or_location = 'location'
2801             props8.Dimension_startlocation = endvertex
2802             props8.Dimension_endlocation = startvertex
2803             props8.Dimension_liberty = '3D'
2804             props8.Dimension_rotation = 0
2805             props8.Dimension_parent = obj.name
2806
2807             col = layout.column()
2808             col.label(text="Diameter to 3D cursor:")
2809             row = layout.row()
2810             props9 = row.operator("curve.dimension", text = 'Add linear diameter')
2811             props9.Dimension_Change = False
2812             props9.Dimension_Type = 'Diameter'
2813             props9.Dimension_width_or_location = 'location'
2814             props9.Dimension_startlocation = endvertex
2815             props9.Dimension_endlocation = startvertex
2816             props9.Dimension_liberty = '2D'
2817             props9.Dimension_rotation = 0
2818             props9.Dimension_parent = obj.name
2819
2820             props10 = row.operator("curve.dimension", text = 'Add 3D diameter')
2821             props10.Dimension_Change = False
2822             props10.Dimension_Type = 'Diameter'
2823             props10.Dimension_width_or_location = 'location'
2824             props10.Dimension_startlocation = endvertex
2825             props10.Dimension_endlocation = startvertex
2826             props10.Dimension_liberty = '3D'
2827             props10.Dimension_rotation = 0
2828             props10.Dimension_parent = obj.name
2829
2830         if len(vertex) == 2:
2831             startvertex = vertex[0]
2832             endvertex = vertex[1]
2833             if endvertex[0] < startvertex[0]:
2834                 startvertex = vertex[1]
2835                 endvertex = vertex[0]
2836
2837             layout = self.layout
2838             col = layout.column()
2839             col.label(text="Distance:")
2840             row = layout.row()
2841             props1 = row.operator("curve.dimension", text = 'Add linear dimension')
2842             props1.Dimension_Change = False
2843             props1.Dimension_Type = 'Linear-1'
2844             props1.Dimension_width_or_location = 'location'
2845             props1.Dimension_startlocation = startvertex
2846             props1.Dimension_endlocation = endvertex
2847             props1.Dimension_liberty = '2D'
2848             props1.Dimension_rotation = 0
2849             props1.Dimension_parent = obj.name
2850
2851             props2 = row.operator("curve.dimension", text = 'Add 3D dimension')
2852             props2.Dimension_Change = False
2853             props2.Dimension_Type = 'Linear-1'
2854             props2.Dimension_width_or_location = 'location'
2855             props2.Dimension_startlocation = startvertex
2856             props2.Dimension_endlocation = endvertex
2857             props2.Dimension_liberty = '3D'
2858             props2.Dimension_rotation = 0
2859             props2.Dimension_parent = obj.name
2860
2861             col = layout.column()
2862             col.label(text="Radius:")
2863             row = layout.row()
2864             props3 = row.operator("curve.dimension", text = 'Add linear radius')
2865             props3.Dimension_Change = False
2866             props3.Dimension_Type = 'Radius'
2867             props3.Dimension_width_or_location = 'location'
2868             props3.Dimension_startlocation = startvertex
2869             props3.Dimension_endlocation = endvertex
2870             props3.Dimension_liberty = '2D'
2871             props3.Dimension_rotation = 0
2872             props3.Dimension_parent = obj.name
2873
2874             props4 = row.operator("curve.dimension", text = 'Add 3D radius')
2875             props4.Dimension_Change = False
2876             props4.Dimension_Type = 'Radius'
2877             props4.Dimension_width_or_location = 'location'
2878             props4.Dimension_startlocation = startvertex
2879             props4.Dimension_endlocation = endvertex
2880             props4.Dimension_liberty = '3D'
2881             props4.Dimension_rotation = 0
2882             props4.Dimension_parent = obj.name
2883
2884             col = layout.column()
2885             col.label(text="Diameter:")
2886             row = layout.row()
2887             props5 = row.operator("curve.dimension", text = 'Add linear diameter')
2888             props5.Dimension_Change = False
2889             props5.Dimension_Type = 'Diameter'
2890             props5.Dimension_width_or_location = 'location'
2891             props5.Dimension_startlocation = startvertex
2892             props5.Dimension_endlocation = endvertex
2893             props5.Dimension_liberty = '2D'
2894             props5.Dimension_rotation = 0
2895             props5.Dimension_parent = obj.name
2896
2897             props6 = row.operator("curve.dimension", text = 'Add 3D diameter')
2898             props6.Dimension_Change = False
2899             props6.Dimension_Type = 'Diameter'
2900             props6.Dimension_width_or_location = 'location'
2901             props6.Dimension_startlocation = startvertex
2902             props6.Dimension_endlocation = endvertex
2903             props6.Dimension_liberty = '3D'
2904             props6.Dimension_rotation = 0
2905             props6.Dimension_parent = obj.name
2906
2907         if len(vertex) == 3:
2908             startvertex = vertex[0]
2909             endvertex = vertex[1]
2910             endanglevertex = vertex[2]
2911             if endvertex[0] < startvertex[0]:
2912                 startvertex = vertex[1]
2913                 endvertex = vertex[0]
2914
2915             layout = self.layout
2916             col = layout.column()
2917             col.label(text="Angle:")
2918             row = layout.row()
2919             props1 = row.operator("curve.dimension", text = 'Add Linear angle dimension')
2920             props1.Dimension_Change = False
2921             props1.Dimension_Type = 'Angular1'
2922             props1.Dimension_width_or_location = 'location'
2923             props1.Dimension_startlocation = startvertex
2924             props1.Dimension_endlocation = endvertex
2925             props1.Dimension_endanglelocation = endanglevertex
2926             props1.Dimension_liberty = '2D'
2927             props1.Dimension_rotation = 0
2928             props1.Dimension_parent = obj.name
2929
2930             props2 = row.operator("curve.dimension", text = 'Add 3D angle dimension')
2931             props2.Dimension_Change = False
2932             props2.Dimension_Type = 'Angular1'
2933             props2.Dimension_width_or_location = 'location'
2934             props2.Dimension_startlocation = startvertex
2935             props2.Dimension_endlocation = endvertex
2936             props2.Dimension_endanglelocation = endanglevertex
2937             props2.Dimension_liberty = '3D'
2938             props2.Dimension_rotation = 0
2939             props2.Dimension_parent = obj.name
2940
2941 # Properties class
2942 class DimensionPanel(bpy.types.Panel):
2943     ''''''
2944     bl_idname = "OBJECT_PT_properties_dimension"
2945     bl_label = "Dimension change"
2946     bl_description = "Dimension change"
2947     bl_space_type = "PROPERTIES"
2948     bl_region_type = "WINDOW"
2949     bl_context = "object"
2950
2951     @classmethod
2952     def poll(cls, context):
2953         if context.object.Dimension == True:
2954             return (context.object)
2955
2956     ##### DRAW #####
2957     def draw(self, context):
2958         if context.object.Dimension == True:
2959             layout = self.layout
2960
2961             obj = context.object
2962             row = layout.row()
2963
2964             props = row.operator("curve.dimension", text = 'Change')
2965             props.Dimension_Change = True
2966             props.Dimension_Delete = obj.name
2967             props.Dimension_width_or_location = obj.Dimension_width_or_location
2968             props.Dimension_startlocation = obj.location
2969             props.Dimension_endlocation = obj.Dimension_endlocation
2970             props.Dimension_endanglelocation = obj.Dimension_endanglelocation
2971             props.Dimension_liberty = obj.Dimension_liberty
2972             props.Dimension_Type = obj.Dimension_Type
2973             props.Dimension_XYZType = obj.Dimension_XYZType
2974             props.Dimension_XYType = obj.Dimension_XYType
2975             props.Dimension_XZType = obj.Dimension_XZType
2976             props.Dimension_YZType = obj.Dimension_YZType
2977             props.Dimension_resolution = obj.Dimension_resolution
2978             props.Dimension_width = obj.Dimension_width
2979             props.Dimension_length = obj.Dimension_length
2980             props.Dimension_dsize = obj.Dimension_dsize
2981             props.Dimension_depth = obj.Dimension_depth
2982             props.Dimension_depth_from_center = obj.Dimension_depth_from_center
2983             props.Dimension_angle = obj.Dimension_angle
2984             props.Dimension_rotation = obj.Dimension_rotation
2985             props.Dimension_offset = 0
2986             props.Dimension_textsize = obj.Dimension_textsize
2987             props.Dimension_textdepth = obj.Dimension_textdepth
2988             props.Dimension_textround = obj.Dimension_textround
2989             props.Dimension_font = obj.Dimension_font
2990             props.Dimension_matname = obj.Dimension_matname
2991             props.Dimension_note = obj.Dimension_note
2992             props.Dimension_align_to_camera = obj.Dimension_align_to_camera
2993             props.Dimension_arrow = obj.Dimension_arrow
2994             props.Dimension_arrowdepth = obj.Dimension_arrowdepth
2995             props.Dimension_arrowlength = obj.Dimension_arrowlength
2996             props.Dimension_parent = obj.Dimension_parent
2997             props.Dimension_appoint_parent = obj.Dimension_appoint_parent
2998             props.Dimension_units = obj.Dimension_units
2999             props.Dimension_add_units_name = obj.Dimension_add_units_name
3000
3001 #location update
3002 def StartLocationUpdate(self, context):
3003
3004     bpy.context.scene.cursor_location = self.Dimension_startlocation
3005
3006     return
3007
3008 # Add properties to objects
3009 def DimensionVariables():
3010
3011     bpy.types.Object.Dimension = bpy.props.BoolProperty()
3012     bpy.types.Object.Dimension_Change = bpy.props.BoolProperty()
3013     bpy.types.Object.Dimension_Name = bpy.props.StringProperty(name = "Name",
3014                 description = "Name")
3015     #### general properties
3016     Types = [('Linear-1', 'Linear-1', 'Linear-1'),
3017              ('Linear-2', 'Linear-2', 'Linear-2'),
3018              ('Linear-3', 'Linear-3', 'Linear-3'),
3019              ('Radius', 'Radius', 'Radius'),
3020              ('Diameter', 'Diameter', 'Diameter'),
3021              ('Angular1', 'Angular1', 'Angular1'),
3022              ('Angular2', 'Angular2', 'Angular2'),
3023              ('Angular3', 'Angular3', 'Angular3'),
3024              ('Note', 'Note', 'Note')]
3025     bpy.types.Object.Dimension_Type = bpy.props.EnumProperty(name = "Type",
3026                 description = "Form of Curve to create",
3027                 items = Types)
3028     XYZTypes = [
3029                 ('TOP', 'Top', 'TOP'),
3030                 ('FRONT', 'Front', 'FRONT'),
3031                 ('RIGHT', 'Right', 'RIGHT'),
3032                 ('BOTTOM', 'Bottom', 'BOTTOM'),
3033                 ('BACK', 'Back', 'BACK'),
3034                 ('LEFT', 'Left', 'LEFT')]
3035     bpy.types.Object.Dimension_XYZType = bpy.props.EnumProperty(name = "Coordinate system",
3036                 description = "Place in a coordinate system",
3037                 items = XYZTypes)
3038     XYTypes = [
3039                 ('X', 'X', 'X'),
3040                 ('Y', 'Y', 'Y')]
3041     bpy.types.Object.Dimension_XYType = bpy.props.EnumProperty(name = "XY",
3042                 description = "XY",
3043                 items = XYTypes)
3044     XZTypes = [
3045                 ('X', 'X', 'X'),
3046                 ('Z', 'Z', 'Z')]
3047     bpy.types.Object.Dimension_XZType = bpy.props.EnumProperty(name = "XZ",
3048                 description = "XZ",
3049                 items = XZTypes)
3050     YZTypes = [
3051                 ('Y', 'Y', 'Y'),
3052                 ('Z', 'Z', 'Z')]
3053     bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "YZ",
3054                 description = "YZ",
3055                 items = YZTypes)
3056     bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "Coordinate system",
3057                 description = "Place in a coordinate system",
3058                 items = YZTypes)
3059     bpy.types.Object.Dimension_startlocation = bpy.props.FloatVectorProperty(name = "Start location",
3060                 description = "",
3061                 subtype = 'XYZ',
3062                 update = StartLocationUpdate)
3063     bpy.types.Object.Dimension_endlocation = bpy.props.FloatVectorProperty(name = "End location",
3064                 description = "",
3065                 subtype = 'XYZ')
3066     bpy.types.Object.Dimension_endanglelocation = bpy.props.FloatVectorProperty(name = "End angle location",
3067                 description = "End angle location",
3068                 subtype = 'XYZ')
3069     width_or_location_items = [
3070                 ('width', 'width', 'width'),
3071                 ('location', 'location', 'location')]
3072     bpy.types.Object.Dimension_width_or_location = bpy.props.EnumProperty(name = "width or location",
3073                 items = width_or_location_items,
3074                 description = "width or location")
3075     libertyItems = [
3076                 ('2D', '2D', '2D'),
3077                 ('3D', '3D', '3D')]
3078     bpy.types.Object.Dimension_liberty = bpy.props.EnumProperty(name = "2D / 3D",
3079                 items = libertyItems,
3080                 description = "2D or 3D Dimension")
3081
3082     ### Arrow
3083     Arrows = [
3084                 ('Arrow1', 'Arrow1', 'Arrow1'),
3085                 ('Arrow2', 'Arrow2', 'Arrow2'),
3086                 ('Serifs1', 'Serifs1', 'Serifs1'),
3087                 ('Serifs2', 'Serifs2', 'Serifs2'),
3088                 ('Without', 'Without', 'Without')]
3089     bpy.types.Object.Dimension_arrow = bpy.props.EnumProperty(name = "Arrow",
3090                 items = Arrows,
3091                 description = "Arrow")
3092     bpy.types.Object.Dimension_arrowdepth = bpy.props.FloatProperty(name = "Depth",
3093                     min = 0, soft_min = 0,
3094                     description = "Arrow depth")
3095     bpy.types.Object.Dimension_arrowlength = bpy.props.FloatProperty(name = "Length",
3096                     min = 0, soft_min = 0,
3097                     description = "Arrow length")
3098
3099     #### Dimension properties
3100     bpy.types.Object.Dimension_resolution = bpy.props.IntProperty(name = "Resolution",
3101                     min = 1, soft_min = 1,
3102                     description = "Resolution")
3103     bpy.types.Object.Dimension_width = bpy.props.FloatProperty(name = "Width",
3104                     unit = 'LENGTH',
3105                     description = "Width")
3106     bpy.types.Object.Dimension_length = bpy.props.FloatProperty(name = "Length",
3107                     description = "Length")
3108     bpy.types.Object.Dimension_dsize = bpy.props.FloatProperty(name = "Size",
3109                     min = 0, soft_min = 0,
3110                     description = "Size")
3111     bpy.types.Object.Dimension_depth = bpy.props.FloatProperty(name = "Depth",
3112                     min = 0, soft_min = 0,
3113                     description = "Depth")
3114     bpy.types.Object.Dimension_depth_from_center = bpy.props.BoolProperty(name = "Depth from center",
3115                     description = "Depth from center")
3116     bpy.types.Object.Dimension_angle = bpy.props.FloatProperty(name = "Angle",
3117                     description = "Angle")
3118     bpy.types.Object.Dimension_rotation = bpy.props.FloatProperty(name = "Rotation",
3119                     description = "Rotation")
3120
3121     #### Dimension units properties
3122     Units = [
3123                 ('None', 'None', 'None'),
3124                 ('\u00b5m', '\u00b5m', '\u00b5m'),
3125                 ('mm', 'mm', 'mm'),
3126                 ('cm', 'cm', 'cm'),
3127                 ('m', 'm', 'm'),
3128                 ('km', 'km', 'km'),
3129                 ('thou', 'thou', 'thou'),
3130                 ('"', '"', '"'),
3131                 ('\'', '\'', '\''),
3132                 ('yd', 'yd', 'yd'),
3133                 ('mi', 'mi', 'mi')]
3134     bpy.types.Object.Dimension_units = bpy.props.EnumProperty(name = "Units",
3135                 items = Units,
3136                 description = "Units")
3137     bpy.types.Object.Dimension_add_units_name = bpy.props.BoolProperty(name = "Add units name",
3138                 description = "Add units name")
3139     bpy.types.Object.Dimension_offset = bpy.props.FloatProperty(name = "Offset",
3140                 description = "Offset")
3141
3142     #### Dimension text properties
3143     bpy.types.Object.Dimension_textsize = bpy.props.FloatProperty(name = "Size",
3144                     description = "Size")
3145     bpy.types.Object.Dimension_textdepth = bpy.props.FloatProperty(name = "Depth",
3146                     description = "Depth")
3147     bpy.types.Object.Dimension_textround = bpy.props.IntProperty(name = "Rounding",
3148                     min = 0, soft_min = 0,
3149                     description = "Rounding")
3150     bpy.types.Object.Dimension_font = bpy.props.StringProperty(name = "Font",
3151                     subtype = 'FILE_PATH',
3152                     description = "Font")
3153
3154     #### Materials properties
3155     bpy.types.Object.Dimension_matname = bpy.props.StringProperty(name = "Name",
3156                     default = 'Dimension_Red',
3157                     description = "Material name")
3158
3159     #### Note text
3160     bpy.types.Object.Dimension_note = bpy.props.StringProperty(name = "Note",
3161                     default = 'Note',
3162                     description = "Note text")
3163     bpy.types.Object.Dimension_align_to_camera = bpy.props.BoolProperty(name = "Align to camera",
3164                 description = "Align to camera")
3165
3166     #### Parent
3167     bpy.types.Object.Dimension_parent = bpy.props.StringProperty(name = "Parent",
3168                     default = '',
3169                     description = "Parent")
3170     bpy.types.Object.Dimension_appoint_parent = bpy.props.BoolProperty(name = "Appoint parent",
3171                 description = "Appoint parent")
3172
3173 ################################################################################
3174 ##### REGISTER #####
3175
3176 def Dimension_button(self, context):
3177     oper = self.layout.operator(Dimension.bl_idname, text = "Dimension", icon = "PLUGIN")
3178     oper.Dimension_Change = False
3179     oper.Dimension_width_or_location = 'width'
3180     oper.Dimension_liberty = '2D'
3181
3182 def register():
3183     bpy.utils.register_module(__name__)
3184
3185     bpy.types.VIEW3D_MT_curve_add.append(Dimension_button)
3186
3187     DimensionVariables()
3188
3189 def unregister():
3190     bpy.utils.unregister_module(__name__)
3191
3192     bpy.types.VIEW3D_MT_curve_add.remove(Dimension_button)
3193
3194 if __name__ == "__main__":
3195     register()