Newer
Older
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and / or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
'name': 'Dimension',
'author': 'Spivak Vladimir (http://cwolf3d.korostyshev.net)',
cwolf3d@yandex.ru
committed
'version': (3, 9, 5),
'location': 'View3D > Add > Curve',
'description': 'Adds Dimension',
'warning': '', # used for warning icon and text in addons panel
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Dimension',
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
'category': 'Add Curve'}
##------------------------------------------------------------
#### import modules
import bpy
from bpy.props import *
from mathutils import *
from math import *
from bpy.app.handlers import persistent
# Add a TextCurve
def addText(string = '', loc = ((0, 0, 0)), textsize = 1, align = 'CENTER', offset_y = 0, font = ''):
tcu = bpy.data.curves.new(string + 'Data', 'FONT')
text = bpy.data.objects.new(string + 'Text', tcu)
tcu.body = string
cwolf3d@yandex.ru
committed
tcu.align_x = align
tcu.size = textsize
tcu.offset_y = offset_y
if font == '':
fnt = bpy.data.fonts[0]
else:
fnt = bpy.data.fonts.load(font)
tcu.font = fnt
text.location = loc
bpy.context.scene.objects.link(text)
return text
##------------------------------------------------------------
# Dimension: Linear-1
def Linear1(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.1, arrowlength = 0.25):
newpoints = []
w = 1
if width < 0:
w = -1
l = 1
if length < 0:
l = -1
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
if arrow == 'Arrow1' or arrow == 'Arrow2':
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize, 0]) #3
newpoints.append([center2, length + l * dsize, 0]) #4
newpoints.append([center2, length + l * dsize / 2 + l * depth / 100, 0]) #5
newpoints.append([center2 + w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #6
if arrow == 'Arrow1':
newpoints.append([center2 + w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #7
newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #8
else:
newpoints.append([center2 + w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #7
newpoints.append([width-center2-w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #9
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 100, 0]) #10
newpoints.append([width-center2, length + l * dsize, 0]) #11
newpoints.append([width + center1, length + l * dsize, 0]) #12
newpoints.append([width + center1, length, 0]) #13
newpoints.append([width + center1, 0, 0]) #14
newpoints.append([width-center2, 0, 0]) #15
newpoints.append([width-center2, length, 0]) #16
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 100, 0]) #17
newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #18
if arrow == 'Arrow1':
newpoints.append([width-center2-w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #19
newpoints.append([center2 + w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #20
else:
newpoints.append([width-center2-w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #19
newpoints.append([center2 + w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #20
newpoints.append([center2 + w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #21
newpoints.append([center2, length + l * dsize / 2-l * depth / 100, 0]) #22
newpoints.append([center2, length, 0]) #23
newpoints.append([center2, 0, 0]) #24
if arrow == 'Serifs1' or arrow == 'Serifs2':
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength * l
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize / 2-l * depth / 2-l * b, 0]) #3
newpoints.append([-center1-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #4
newpoints.append([-center1-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #5
if arrow == 'Serifs2':
newpoints.append([-center1-w * b, length + l * dsize / 2-l * depth / 2, 0]) #6
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #7
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #9
newpoints.append([-center1, length + l * dsize, 0]) #10
newpoints.append([center2, length + l * dsize, 0]) #11
newpoints.append([center2, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #12
newpoints.append([center2 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #13
newpoints.append([center2 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #14
newpoints.append([center2 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #15
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #16
newpoints.append([width-center2, length + l * dsize, 0]) #17
newpoints.append([width + center1, length + l * dsize, 0]) #18
newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #19
newpoints.append([width + center1 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #21
if arrow == 'Serifs2':
newpoints.append([width + center1 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #22
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #23
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #24
newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #25
newpoints.append([width + center1, length, 0]) #26
newpoints.append([width + center1, 0, 0]) #27
newpoints.append([width-center2, 0, 0]) #28
newpoints.append([width-center2, length, 0]) #29
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2-l * b, 0]) #30
newpoints.append([width-center2-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #31
newpoints.append([width-center2-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, length + l * dsize / 2-l * depth / 2, 0]) #33
newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #34
newpoints.append([center2, length, 0]) #35
newpoints.append([center2, 0, 0]) #36
if arrow == 'Without':
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize, 0]) #3
newpoints.append([center2, length + l * dsize, 0]) #4
newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #7
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([width-center2, length + l * dsize, 0]) #11
newpoints.append([width + center1, length + l * dsize, 0]) #12
newpoints.append([width + center1, length, 0]) #13
newpoints.append([width + center1, 0, 0]) #14
newpoints.append([width-center2, 0, 0]) #15
newpoints.append([width-center2, length, 0]) #16
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #19
newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #20
newpoints.append([center2, length, 0]) #23
newpoints.append([center2, 0, 0]) #24
return newpoints
##------------------------------------------------------------
# Dimension: Linear-2
def Linear2(width = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
w = 1
if width < 0:
w = -1
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
if arrow == 'Arrow1' or arrow == 'Arrow2':
newpoints.append([0, 0, 0]) #1
newpoints.append([w * arrowlength, arrowdepth + depth / 2, 0]) #2
if arrow == 'Arrow1':
newpoints.append([w * arrowlength, depth / 2, 0]) #3
newpoints.append([width-w * arrowlength, depth / 2, 0]) #4
else:
newpoints.append([w * arrowlength * 3 / 4, depth / 2, 0]) #3
newpoints.append([width-w * arrowlength * 3 / 4, depth / 2, 0]) #4
newpoints.append([width-w * arrowlength, arrowdepth + depth / 2, 0]) #5
newpoints.append([width, 0, 0]) #6
newpoints.append([width-w * arrowlength, -arrowdepth-depth / 2, 0]) #7
if arrow == 'Arrow1':
newpoints.append([width-w * arrowlength, -depth / 2, 0]) #8
newpoints.append([w * arrowlength, -depth / 2, 0]) #9
else:
newpoints.append([width-w * arrowlength * 3 / 4, -depth / 2, 0]) #8
newpoints.append([w * arrowlength * 3 / 4, -depth / 2, 0]) #9
newpoints.append([w * arrowlength, -arrowdepth-depth / 2, 0]) #10
if arrow == 'Serifs1':
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength
newpoints.append([-center1, -dsize / 2, 0]) #2
newpoints.append([-center1, -depth / 2-b, 0]) #3
newpoints.append([-center1-x, -depth / 2-b-y, 0]) #4
newpoints.append([-center1-w * b-x, -depth / 2-y, 0]) #5
newpoints.append([-center1-w * b, -depth / 2, 0]) #6
newpoints.append([-center1-w * dsize / 2, -depth / 2, 0]) #7
newpoints.append([-center1-w * dsize / 2, depth / 2, 0]) #8
newpoints.append([-center1, depth / 2, 0]) #9
newpoints.append([-center1, dsize / 2, 0]) #10
newpoints.append([center2, dsize / 2, 0]) #11
newpoints.append([center2, depth / 2 + b, 0]) #12
newpoints.append([center2 + x, depth / 2 + b + y, 0]) #13
newpoints.append([center2 + w * b + x, depth / 2 + y, 0]) #14
newpoints.append([center2 + w * b, depth / 2, 0]) #15
newpoints.append([width-center2, depth / 2, 0]) #16
newpoints.append([width-center2, dsize / 2, 0]) #17
newpoints.append([width + center1, dsize / 2, 0]) #18
newpoints.append([width + center1, depth / 2 + b, 0]) #19
newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
newpoints.append([width + center1 + w * dsize / 2, depth / 2, 0]) #23
newpoints.append([width + center1 + w * dsize / 2, -depth / 2, 0]) #24
newpoints.append([width + center1, -depth / 2, 0]) #25
newpoints.append([width + center1, -dsize / 2, 0]) #26
newpoints.append([width-center2, -dsize / 2, 0]) #29
newpoints.append([width-center2, -depth / 2-b, 0]) #30
newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
newpoints.append([center2, -depth / 2, 0]) #34
newpoints.append([center2, -dsize / 2, 0]) #35
if arrow == 'Serifs2':
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength
newpoints.append([-center1 + w * b, -depth / 2, 0]) #3
newpoints.append([-center1-x, -depth / 2-b-y, 0]) #4
newpoints.append([-center1-w * b-x, -depth / 2-y, 0]) #5
newpoints.append([center2 + x, depth / 2 + b + y, 0]) #13
newpoints.append([center2 + w * b + x, depth / 2 + y, 0]) #14
newpoints.append([center2 + w * b, depth / 2, 0]) #15
newpoints.append([width + center1-w * b, depth / 2, 0]) #19
newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
if arrow == 'Without':
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
newpoints.append([0, depth / 2, 0]) #3
newpoints.append([width, depth / 2, 0]) #4
newpoints.append([width, -depth / 2, 0]) #8
newpoints.append([0, -depth / 2, 0]) #9
return newpoints
##------------------------------------------------------------
# Dimension: Linear-3
def Linear3(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
w = 1
if width < 0:
w = -1
l = 1
if length < 0:
l = -1
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
if arrow == 'Arrow1' or arrow == 'Arrow2':
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize / 2-l * depth / 100, 0]) #3
newpoints.append([-center1-w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #4
if arrow == 'Arrow1':
newpoints.append([-center1-w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #5
else:
newpoints.append([-center1-w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #5
newpoints.append([-center1-w * arrowlength-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #6
newpoints.append([-center1-w * arrowlength-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #7
if arrow == 'Arrow1':
newpoints.append([-center1-w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #8
else:
newpoints.append([-center1-w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([-center1-w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #9
newpoints.append([-center1, length + l * dsize / 2 + l * depth / 100, 0]) #10
newpoints.append([-center1, length + l * dsize, 0]) #11
newpoints.append([center2, length + l * dsize, 0]) #12
newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #13
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #14
newpoints.append([width-center2, length + l * dsize, 0]) #15
newpoints.append([width + center1, length + l * dsize, 0]) #16
newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 100, 0]) #17
newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2 + l * arrowdepth + l * depth / 2, 0]) #18
if arrow == 'Arrow1':
newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2 + l * depth / 2, 0]) #19
else:
newpoints.append([width + center1 + w * arrowlength * 3 / 4, length + l * dsize / 2 + l * depth / 2, 0]) #19
newpoints.append([width + center1 + w * arrowlength + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #20
newpoints.append([width + center1 + w * arrowlength + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #21
if arrow == 'Arrow1':
newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2-l * depth / 2, 0]) #22
else:
newpoints.append([width + center1 + w * arrowlength * 3 / 4, length + l * dsize / 2-l * depth / 2, 0]) #22
newpoints.append([width + center1 + w * arrowlength, length + l * dsize / 2-l * arrowdepth-l * depth / 2, 0]) #23
newpoints.append([width + center1, length + l * dsize / 2-l * depth / 100, 0]) #24
newpoints.append([width + center1, length, 0]) #25
newpoints.append([width + center1, 0, 0]) #26
newpoints.append([width-center2, 0, 0]) #27
newpoints.append([width-center2, length, 0]) #28
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #29
newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #30
newpoints.append([center2, length, 0]) #31
newpoints.append([center2, 0, 0]) #32
if arrow == 'Serifs1' or arrow == 'Serifs2':
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength * l
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize / 2-l * depth / 2-l * b, 0]) #3
newpoints.append([-center1-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #4
newpoints.append([-center1-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #5
newpoints.append([-center1-w * b, length + l * dsize / 2-l * depth / 2, 0]) #6
if arrow == 'Serifs1':
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #7
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #8
else:
newpoints.append([-center1-w * dsize, length + l * dsize / 2-l * depth / 2, 0]) #7
newpoints.append([-center1-w * dsize, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #9
newpoints.append([-center1, length + l * dsize, 0]) #10
newpoints.append([center2, length + l * dsize, 0]) #11
newpoints.append([center2, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #12
newpoints.append([center2 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #13
newpoints.append([center2 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #14
newpoints.append([center2 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #15
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #16
newpoints.append([width-center2, length + l * dsize, 0]) #17
newpoints.append([width + center1, length + l * dsize, 0]) #18
newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2 + l * b, 0]) #19
newpoints.append([width + center1 + x, length + l * dsize / 2 + l * depth / 2 + l * b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, length + l * dsize / 2 + l * depth / 2 + y, 0]) #21
newpoints.append([width + center1 + w * b, length + l * dsize / 2 + l * depth / 2, 0]) #22
if arrow == 'Serifs1':
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #23
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #24
else:
newpoints.append([width + center1 + w * dsize, length + l * dsize / 2 + l * depth / 2, 0]) #23
newpoints.append([width + center1 + w * dsize, length + l * dsize / 2-l * depth / 2, 0]) #24
newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #25
newpoints.append([width + center1, length, 0]) #26
newpoints.append([width + center1, 0, 0]) #27
newpoints.append([width-center2, 0, 0]) #28
newpoints.append([width-center2, length, 0]) #29
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2-l * b, 0]) #30
newpoints.append([width-center2-x, length + l * dsize / 2-l * depth / 2-l * b-y, 0]) #31
newpoints.append([width-center2-w * b-x, length + l * dsize / 2-l * depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, length + l * dsize / 2-l * depth / 2, 0]) #33
newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #34
newpoints.append([center2, length, 0]) #35
newpoints.append([center2, 0, 0]) #36
if arrow == 'Without':
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
newpoints.append([-center1, 0, 0]) #1
newpoints.append([-center1, length, 0]) #2
newpoints.append([-center1, length + l * dsize / 2-l * depth / 2, 0]) #5
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #6
newpoints.append([-center1-w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #7
newpoints.append([-center1, length + l * dsize / 2 + l * depth / 2, 0]) #8
newpoints.append([-center1, length + l * dsize, 0]) #11
newpoints.append([center2, length + l * dsize, 0]) #12
newpoints.append([center2, length + l * dsize / 2 + l * depth / 2, 0]) #13
newpoints.append([width-center2, length + l * dsize / 2 + l * depth / 2, 0]) #14
newpoints.append([width-center2, length + l * dsize, 0]) #15
newpoints.append([width + center1, length + l * dsize, 0]) #16
newpoints.append([width + center1, length + l * dsize / 2 + l * depth / 2, 0]) #19
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2 + l * depth / 2, 0]) #20
newpoints.append([width + center1 + w * dsize / 2, length + l * dsize / 2-l * depth / 2, 0]) #21
newpoints.append([width + center1, length + l * dsize / 2-l * depth / 2, 0]) #22
newpoints.append([width + center1, length, 0]) #25
newpoints.append([width + center1, 0, 0]) #26
newpoints.append([width-center2, 0, 0]) #27
newpoints.append([width-center2, length, 0]) #28
newpoints.append([width-center2, length + l * dsize / 2-l * depth / 2, 0]) #29
newpoints.append([center2, length + l * dsize / 2-l * depth / 2, 0]) #30
newpoints.append([center2, length, 0]) #31
newpoints.append([center2, 0, 0]) #32
return newpoints
##------------------------------------------------------------
# Dimension: Radius
def Radius(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
w = 1
if width < 0:
w = -1
length = abs(length)
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
if arrow == 'Arrow1' or arrow == 'Arrow2':
newpoints.append([0, depth / 2, 0]) #1
newpoints.append([width, depth / 2, 0]) #2
newpoints.append([width + w * arrowlength, depth / 2 + arrowdepth, 0]) #3
if arrow == 'Arrow1':
newpoints.append([width + w * arrowlength, depth / 2, 0]) #4
else:
newpoints.append([width + w * arrowlength * 3 / 4, depth / 2, 0]) #4
newpoints.append([width + w * arrowlength + w * length, depth / 2, 0]) #5
newpoints.append([width + w * arrowlength + w * length, -depth / 2, 0]) #6
if arrow == 'Arrow1':
newpoints.append([width + w * arrowlength, -depth / 2, 0]) #7
else:
newpoints.append([width + w * arrowlength * 3 / 4, -depth / 2, 0]) #7
newpoints.append([width + w * arrowlength, -depth / 2-arrowdepth, 0]) #8
newpoints.append([width, -depth / 2, 0]) #9
newpoints.append([0, -depth / 2, 0]) #10
if arrow == 'Serifs1' or arrow == 'Serifs2':
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength
newpoints.append([0, depth / 2, 0]) #1
if arrow == 'Serifs1':
newpoints.append([width-center2, depth / 2, 0]) #16
newpoints.append([width-center2, dsize / 2, 0]) #17
newpoints.append([width + center1, dsize / 2, 0]) #18
newpoints.append([width + center1, depth / 2 + b, 0]) #19
else:
newpoints.append([width + center1-w * b, depth / 2, 0]) #19
newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
newpoints.append([width + center1 + w * length, depth / 2, 0]) #23
newpoints.append([width + center1 + w * length, -depth / 2, 0]) #24
if arrow == 'Serifs1':
newpoints.append([width + center1, -depth / 2, 0]) #25
newpoints.append([width + center1, -dsize / 2, 0]) #26
newpoints.append([width-center2, -dsize / 2, 0]) #29
newpoints.append([width-center2, -depth / 2-b, 0]) #30
else:
newpoints.append([width-center2 + w * b, -depth / 2, 0]) #30
newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
newpoints.append([0, -depth / 2, 0]) #10
if arrow == 'Without':
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
newpoints.append([0, depth / 2, 0]) #1
newpoints.append([width, depth / 2, 0]) #2
newpoints.append([width, -depth / 2, 0]) #9
newpoints.append([0, -depth / 2, 0]) #10
return newpoints
##------------------------------------------------------------
# Dimension: Diameter
def Diameter(width = 2, length = 2, dsize = 1, depth = 0.1, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
width = width / 2
w = 1
if width < 0:
w = -1
length = abs(length)
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
if arrow == 'Arrow1' or arrow == 'Arrow2':
newpoints.append([0, depth / 2, 0]) #1
newpoints.append([width, depth / 2, 0]) #2
newpoints.append([width + w * arrowlength, depth / 2 + arrowdepth, 0]) #3
if arrow == 'Arrow1':
newpoints.append([width + w * arrowlength, depth / 2, 0]) #4
else:
newpoints.append([width + w * arrowlength * 3 / 4, depth / 2, 0]) #4
newpoints.append([width + w * arrowlength + w * length, depth / 2, 0]) #5
newpoints.append([width + w * arrowlength + w * length, -depth / 2, 0]) #6
if arrow == 'Arrow1':
newpoints.append([width + w * arrowlength, -depth / 2, 0]) #7
else:
newpoints.append([width + w * arrowlength * 3 / 4, -depth / 2, 0]) #7
newpoints.append([width + w * arrowlength, -depth / 2-arrowdepth, 0]) #8
newpoints.append([width, -depth / 2, 0]) #9
newpoints.append([0, -depth / 2, 0]) #10
newpoints.append([-width, -depth / 2, 0]) #11
newpoints.append([-width-w * arrowlength, -depth / 2-arrowdepth, 0]) #12
if arrow == 'Arrow1':
newpoints.append([-width-w * arrowlength, -depth / 2, 0]) #13
else:
newpoints.append([-width-w * arrowlength * 3 / 4, -depth / 2, 0]) #13
newpoints.append([-width-w * arrowlength-w * length, -depth / 2, 0]) #14
newpoints.append([-width-w * arrowlength-w * length, depth / 2, 0]) #15
if arrow == 'Arrow1':
newpoints.append([-width-w * arrowlength, depth / 2, 0]) #16
else:
newpoints.append([-width-w * arrowlength * 3 / 4, depth / 2, 0]) #16
newpoints.append([-width-w * arrowlength, depth / 2 + arrowdepth, 0]) #17
newpoints.append([-width, depth / 2, 0]) #18
if arrow == 'Serifs1' or arrow == 'Serifs2':
b = sqrt(depth * depth / 2)
x = sin(radians(45)) * arrowlength * w
y = cos(radians(45)) * arrowlength
newpoints.append([0, depth / 2, 0]) #1
if arrow == 'Serifs1':
newpoints.append([width-center2, depth / 2, 0]) #16
newpoints.append([width-center2, dsize / 2, 0]) #17
newpoints.append([width + center1, dsize / 2, 0]) #18
newpoints.append([width + center1, depth / 2 + b, 0]) #19
else:
newpoints.append([width + center1-w * b, depth / 2, 0]) #19
newpoints.append([width + center1 + x, depth / 2 + b + y, 0]) #20
newpoints.append([width + center1 + w * b + x, depth / 2 + y, 0]) #21
newpoints.append([width + center1 + w * b, depth / 2, 0]) #22
newpoints.append([width + center1 + w * length, depth / 2, 0]) #23
newpoints.append([width + center1 + w * length, -depth / 2, 0]) #24
if arrow == 'Serifs1':
newpoints.append([width + center1, -depth / 2, 0]) #25
newpoints.append([width + center1, -dsize / 2, 0]) #26
newpoints.append([width-center2, -dsize / 2, 0]) #29
newpoints.append([width-center2, -depth / 2-b, 0]) #30
else:
newpoints.append([width-center2 + w * b, -depth / 2, 0]) #30
newpoints.append([width-center2-x, -depth / 2-b-y, 0]) #31
newpoints.append([width-center2-w * b-x, -depth / 2-y, 0]) #32
newpoints.append([width-center2-w * b, -depth / 2, 0]) #33
newpoints.append([0, -depth / 2, 0]) #10
if arrow == 'Serifs1':
newpoints.append([-width + center2, -depth / 2, 0]) #25
newpoints.append([-width + center2, -dsize / 2, 0]) #26
newpoints.append([-width-center1, -dsize / 2, 0]) #29
newpoints.append([-width-center1, -depth / 2-b, 0]) #30
else:
newpoints.append([-width-center1 + w * b, -depth / 2, 0]) #30
newpoints.append([-width-center1-x, -depth / 2-b-y, 0]) #31
newpoints.append([-width-center1-w * b-x, -depth / 2-y, 0]) #32
newpoints.append([-width-center1-w * b, -depth / 2, 0]) #33
newpoints.append([-width + center2-w * length, -depth / 2, 0]) #24
newpoints.append([-width + center2-w * length, depth / 2, 0]) #23
if arrow == 'Serifs1':
newpoints.append([-width-center1, depth / 2, 0]) #16
newpoints.append([-width-center1, dsize / 2, 0]) #17
newpoints.append([-width + center2, dsize / 2, 0]) #18
newpoints.append([-width + center2, depth / 2 + b, 0]) #19
else:
newpoints.append([-width + center2-w * b, depth / 2, 0]) #19
newpoints.append([-width + center2 + x, depth / 2 + b + y, 0]) #20
newpoints.append([-width + center2 + w * b + x, depth / 2 + y, 0]) #21
newpoints.append([-width + center2 + w * b, depth / 2, 0]) #22
if arrow == 'Without':
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
newpoints.append([0, depth / 2, 0]) #1
newpoints.append([width, depth / 2, 0]) #2
newpoints.append([width, -depth / 2, 0]) #9
newpoints.append([0, -depth / 2, 0]) #10
newpoints.append([-width, -depth / 2, 0]) #11
newpoints.append([-width, depth / 2, 0]) #18
return newpoints
##------------------------------------------------------------
# Dimension: Angular1
def Angular1(width = 2, length = 2, depth = 0.1, angle = 45, resolution = 10, center = False, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
if arrow == 'Serifs1' or arrow == 'Serifs2':
arrow = 'Without'
w = 1
if width < 0:
w = -1
if resolution == 0:
resolution = 1
if arrow == 'Without':
arrowdepth = 0.0
arrowlength = 0.0
length = abs(length)
angle = radians(angle)
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
g = hypot(width + w * length, center2)
u_depth = asin((center2) / g)
g = hypot(width, center2)
u_depth_min = asin((center2 + center2/4) / g)
g = hypot(width, arrowlength + w * center2)
u_arrow = asin((arrowlength + w * center2) / g)
if width < 0:
u_depth = -u_depth
u_depth_min = -u_depth_min
a = 1
if angle < 0 :
a = -1
u_depth = -u_depth
u_depth_min = -u_depth_min
u_arrow = -u_arrow
x = (a * center1) / tan(angle / 2)
newpoints.append([-x, -a * center1, 0]) #1
newpoints.append([width + w * length, -a * center1, 0]) #2
newpoints.append([width + w * length, a * center2, 0]) #3
if arrow == 'Without':
newpoints.append([width + w * depth / 2, a * center2, 0]) #4
else:
newpoints.append([width + w * depth / 100, a * center2, 0]) #4
g = width + w * arrowdepth + w * depth / 2
x = cos(u_arrow + u_depth) * g
y = sin(u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #5
if arrow == 'Arrow1':
g = width + w * depth / 2
x = cos(u_arrow + u_depth) * g
y = sin(u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #6
if arrow == 'Arrow2':
g = width + w * depth / 2
x = cos(u_arrow * 3 / 4 + u_depth) * g
y = sin(u_arrow * 3 / 4 + u_depth) * g
newpoints.append([x, y, 0]) #6
i = 1
while i < resolution :
u = i * (angle - u_arrow * 2 - u_depth * 2) / resolution
g = width + w * depth / 2
x = cos(u + u_arrow + u_depth) * g
y = sin(u + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #n
i += 1
if arrow == 'Arrow1':
g = width + w * depth / 2
x = cos(angle - u_arrow - u_depth) * g
y = sin(angle - u_arrow - u_depth) * g
newpoints.append([x, y, 0]) #7
if arrow == 'Arrow2':
g = width + w * depth / 2
x = cos(angle - u_arrow * 3 / 4 - u_depth) * g
y = sin(angle - u_arrow * 3 / 4 - u_depth) * g
newpoints.append([x, y, 0]) #7
u = angle - u_arrow - u_depth
g = width + w * arrowdepth + w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #8
if arrow == 'Without':
g = width + w * depth / 2
x = cos(angle-u_depth_min) * g
y = sin(angle-u_depth_min) * g
newpoints.append([x, y, 0]) #9
else:
g = width + w * depth / 100
x = cos(angle-u_depth_min) * g
y = sin(angle-u_depth_min) * g
newpoints.append([x, y, 0]) #9
if arrow == 'Without':
g = width-w * depth / 2
x = cos(angle-u_depth_min) * g
y = sin(angle-u_depth_min) * g
newpoints.append([x, y, 0]) #10
else:
g = width-w * depth / 100
x = cos(angle-u_depth_min) * g
y = sin(angle-u_depth_min) * g
newpoints.append([x, y, 0]) #10
g = width-w * arrowdepth-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #11
if arrow == 'Arrow1':
u = angle - u_arrow - u_depth
g = width-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #12
if arrow == 'Arrow2':
u = angle - u_arrow * 3 / 4 - u_depth
g = width-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #12
i = resolution - 1
while i >= 1 :
u = i * (angle - u_arrow * 2 - u_depth * 2) / resolution
g = width-w * depth / 2
x = cos(u + u_arrow + u_depth) * g
y = sin(u + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #n
i -= 1
if arrow == 'Arrow1':
g = width-w * depth / 2
x = cos(u_arrow + u_depth) * g
y = sin(u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #13
if arrow == 'Arrow2':
g = width-w * depth / 2
x = cos(u_arrow * 3 / 4 + u_depth) * g
y = sin(u_arrow * 3 / 4 + u_depth) * g
newpoints.append([x, y, 0]) #13
g = width-w * arrowdepth-w * depth / 2
x = cos(u_arrow + u_depth) * g
y = sin(u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #14
if arrow == 'Without':
newpoints.append([width-w * depth / 2, a * center2, 0]) #15
else:
newpoints.append([width-w * depth / 100, a * center2, 0]) #15
x = (a * center2) / tan(angle / 2)
newpoints.append([x, a * center2, 0]) #16
g = width + w * length
x = cos(angle-u_depth) * g
y = sin(angle-u_depth) * g
newpoints.append([x, y, 0]) #17
if center:
g = width + w * length
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #18
else:
g = width + w * length
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #18
return newpoints
##------------------------------------------------------------
# Dimension: Angular2
def Angular2(width = 2, depth = 0.1, angle = 45, resolution = 10, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
if arrow == 'Serifs1' or arrow == 'Serifs2':
arrow = 'Without'
w = 1
if width < 0:
w = -1
if resolution == 0:
resolution = 1
if arrow == 'Without':
arrowdepth = 0.0
arrowlength = 0.0
angle = radians(angle)
newpoints.append([width, 0, 0]) #1
g = hypot(width + w * depth / 2, arrowlength)
u_arrow = asin((arrowlength) / g)
if angle < 0 :
u_arrow = -u_arrow
g = width + w * arrowdepth + w * depth / 2
x = cos(u_arrow) * g
y = sin(u_arrow) * g
newpoints.append([x, y, 0]) #2
if arrow == 'Arrow1':
g = width + w * depth / 2
x = cos(u_arrow) * g
y = sin(u_arrow) * g
newpoints.append([x, y, 0]) #3
if arrow == 'Arrow2':
g = width + w * depth / 2
x = cos(u_arrow * 3 / 4) * g
y = sin(u_arrow * 3 / 4) * g
newpoints.append([x, y, 0]) #3
i = 1
while i < resolution :
u = i * (angle - u_arrow * 2) / resolution
g = width + w * depth / 2
x = cos(u + u_arrow) * g
y = sin(u + u_arrow) * g
newpoints.append([x, y, 0]) #n
i += 1
if arrow == 'Arrow1':
u = angle - u_arrow
g = width + w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #4
if arrow == 'Arrow2':
u = angle - u_arrow * 3 / 4
g = width + w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #4
u = angle - u_arrow
g = width + w * arrowdepth + w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #5
g = width
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #6
g = width-w * arrowdepth-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #7
if arrow == 'Arrow1':
u = angle - u_arrow
g = width-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #8
if arrow == 'Arrow2':
u = angle - u_arrow * 3 / 4
g = width-w * depth / 2
x = cos(u) * g
y = sin(u) * g
newpoints.append([x, y, 0]) #8
i = resolution - 1
while i > 0 :
u = i * (angle - u_arrow * 2) / resolution
g = width-w * depth / 2
x = cos(u + u_arrow) * g
y = sin(u + u_arrow) * g
newpoints.append([x, y, 0]) #n
i -= 1
if arrow == 'Arrow1':
g = width-w * depth / 2
x = cos(u_arrow) * g
y = sin(u_arrow) * g
newpoints.append([x, y, 0]) #9
if arrow == 'Arrow2':
g = width-w * depth / 2
x = cos(u_arrow * 3 / 4) * g
y = sin(u_arrow * 3 / 4) * g
newpoints.append([x, y, 0]) #9
g = width-w * arrowdepth-w * depth / 2
x = cos(u_arrow) * g
y = sin(u_arrow) * g
newpoints.append([x, y, 0]) #10
return newpoints
##------------------------------------------------------------
# Dimension: Angular3
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):
newpoints = []
if arrow == 'Serifs1' or arrow == 'Serifs2':
arrow = 'Without'
w = 1
if width < 0:
w = -1
if resolution == 0:
resolution = 1
if arrow == 'Without':
arrowdepth = 0.0
arrowlength = 0.0
resolution_2 = floor(resolution / 2)
length = abs(length)
angle = radians(angle)
if center:
center1 = w * depth / 2
center2 = w * depth / 2
else:
center1 = 0
center2 = w * depth
g = hypot(width + w * length, center2)
u_depth = asin((center2) / g)
g = hypot(width + depth / 2, center2)
u_depth_13 = asin((center2 + center2/4) / g)
g = hypot(width-depth / 2, center2)
u_depth_14 = asin((center2 + center2/4) / g)
g = hypot(width, center2)
u_depth_min = asin((center2) / g)
g = hypot(width, arrowlength + w * center2)
u_arrow = asin((arrowlength + w * center2) / g)
g = hypot(width, arrowlength + w * center2 + dsize)
u_dsize = asin((arrowlength + w * center2 + dsize) / g)
if width < 0:
u_depth = -u_depth
u_depth_min = -u_depth_min
u_depth_13 = -u_depth_13
u_depth_14 = -u_depth_14
a = 1
if angle < 0 :
a = -1
u_depth = -u_depth
u_depth_min = -u_depth_min
u_arrow = -u_arrow
u_depth_13 = -u_depth_13
u_depth_14 = -u_depth_14
x = (a * center1) / tan(angle / 2)
newpoints.append([-x, -a * center1, 0]) #1
if arrow == 'Without':
newpoints.append([width-w * depth / 2, -a * center1, 0]) #2
else:
newpoints.append([width-w * depth / 100, -a * center1, 0]) #2
g = width-w * arrowdepth-w * depth / 2
x = cos(-u_arrow-u_depth) * g
y = sin(-u_arrow-u_depth) * g
newpoints.append([x, y, 0]) #3
if arrow == 'Arrow1':
g = width-w * depth / 2
x = cos(-u_arrow-u_depth) * g
y = sin(-u_arrow-u_depth) * g
newpoints.append([x, y, 0]) #4
if arrow == 'Arrow2':
g = width-w * depth / 2
x = cos(-u_arrow * 3 / 4-u_depth) * g
y = sin(-u_arrow * 3 / 4-u_depth) * g
newpoints.append([x, y, 0]) #4
i = 1
while i < resolution_2 :
u = i * (-u_dsize) / resolution_2
g = width-w * depth / 2
x = cos(u-u_arrow) * g
y = sin(u-u_arrow) * g
newpoints.append([x, y, 0]) #n
i += 1
g = width-w * depth / 2
x = cos(-u_arrow-u_depth-u_dsize) * g
y = sin(-u_arrow-u_depth-u_dsize) * g
newpoints.append([x, y, 0]) #5
g = width + w * depth / 2
x = cos(-u_arrow-u_depth-u_dsize) * g
y = sin(-u_arrow-u_depth-u_dsize) * g
newpoints.append([x, y, 0]) #6
i = resolution_2
while i >= 1 :
u = i * (-u_dsize) / resolution_2
g = width + w * depth / 2
x = cos(u-u_arrow) * g
y = sin(u-u_arrow) * g
newpoints.append([x, y, 0]) #n
i -= 1
if arrow == 'Arrow1':
g = width + w * depth / 2
x = cos(-u_arrow-u_depth) * g
y = sin(-u_arrow-u_depth) * g
newpoints.append([x, y, 0]) #7
if arrow == 'Arrow2':
g = width + w * depth / 2
x = cos(-u_arrow * 3 / 4-u_depth) * g
y = sin(-u_arrow * 3 / 4-u_depth) * g
newpoints.append([x, y, 0]) #7
g = width + w * arrowdepth + w * depth / 2
x = cos(-u_arrow-u_depth) * g
y = sin(-u_arrow-u_depth) * g
newpoints.append([x, y, 0]) #8
if arrow == 'Without':
newpoints.append([width + w * depth / 2, -a * center1, 0]) #9
else:
newpoints.append([width + w * depth / 100, -a * center1, 0]) #9
newpoints.append([width + w * length, -a * center1, 0]) #10
newpoints.append([width + w * length, a * center2, 0]) #11
g = width + w * depth / 2
x = cos(u_depth_min) * g
y = sin(u_depth_min) * g
newpoints.append([x, y, 0]) #12
i = 1
while i < resolution :
u = i * (angle - u_depth * 2) / resolution
g = width + w * depth / 2
x = cos(u + u_depth) * g
y = sin(u + u_depth) * g
newpoints.append([x, y, 0]) #n
i += 1
if width > 0 :
g = width + w * depth / 2
x = cos(angle - u_depth_13) * g
y = sin(angle - u_depth_13) * g
newpoints.append([x, y, 0]) #13
g = width-w * depth / 2
x = cos(angle - u_depth_14) * g
y = sin(angle - u_depth_14) * g
newpoints.append([x, y, 0]) #14
else:
g = width + w * depth / 2
x = cos(angle - u_depth_14) * g
y = sin(angle - u_depth_14) * g
newpoints.append([x, y, 0]) #13
g = width-w * depth / 2
x = cos(angle - u_depth_13) * g
y = sin(angle - u_depth_13) * g
newpoints.append([x, y, 0]) #14
i = resolution - 1
while i >= 1 :
u = i * (angle - u_depth * 2) / resolution
g = width-w * depth / 2
x = cos(u + u_depth) * g
y = sin(u + u_depth) * g
newpoints.append([x, y, 0]) #n
i -= 1
g = width-w * depth / 2
x = cos(u_depth_min) * g
y = sin(u_depth_min) * g
newpoints.append([x, y, 0]) #15
x = (a * center2) / tan(angle / 2)
newpoints.append([x, a * center2, 0]) #16
g = width + w * length
x = cos(angle-u_depth) * g
y = sin(angle-u_depth) * g
newpoints.append([x, y, 0]) #17
if center:
g = width + w * length
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #18
if arrow == 'Without':
g = width + w * depth / 2
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #19
else:
g = width + w * depth / 100
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #19
else:
g = width + w * length
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #18
if arrow == 'Without':
g = width + w * depth / 2
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #19
else:
g = width + w * depth / 100
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #19
g = width + w * arrowdepth + w * depth / 2
x = cos(angle + u_arrow + u_depth) * g
y = sin(angle + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #20
if arrow == 'Arrow1':
g = width + w * depth / 2
x = cos(angle + u_arrow + u_depth) * g
y = sin(angle + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #21
if arrow == 'Arrow2':
g = width + w * depth / 2
x = cos(angle + u_arrow * 3 / 4 + u_depth) * g
y = sin(angle + u_arrow * 3 / 4 + u_depth) * g
newpoints.append([x, y, 0]) #21
i = 1
while i < resolution_2 :
u = i * (u_dsize) / resolution_2
g = width + w * depth / 2
x = cos(u + angle + u_arrow) * g
y = sin(u + angle + u_arrow) * g
newpoints.append([x, y, 0]) #n
i += 1
g = width + w * depth / 2
x = cos(angle + u_arrow + u_depth + u_dsize) * g
y = sin(angle + u_arrow + u_depth + u_dsize) * g
newpoints.append([x, y, 0]) #22
g = width-w * depth / 2
x = cos(angle + u_arrow + u_depth + u_dsize) * g
y = sin(angle + u_arrow + u_depth + u_dsize) * g
newpoints.append([x, y, 0]) #23
i = resolution_2
while i >= 1 :
u = i * (u_dsize) / resolution_2
g = width-w * depth / 2
x = cos(u + angle + u_arrow) * g
y = sin(u + angle + u_arrow) * g
newpoints.append([x, y, 0]) #n
i -= 1
if arrow == 'Arrow1':
g = width-w * depth / 2
x = cos(angle + u_arrow + u_depth) * g
y = sin(angle + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #24
if arrow == 'Arrow2':
g = width-w * depth / 2
x = cos(angle + u_arrow * 3 / 4 + u_depth) * g
y = sin(angle + u_arrow * 3 / 4 + u_depth) * g
newpoints.append([x, y, 0]) #24
g = width-w * arrowdepth-w * depth / 2
x = cos(angle + u_arrow + u_depth) * g
y = sin(angle + u_arrow + u_depth) * g
newpoints.append([x, y, 0]) #25
if center:
if arrow == 'Without':
g = width-w * depth / 2
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #26
else:
g = width-w * depth / 100
x = cos(angle + u_depth) * g
y = sin(angle + u_depth) * g
newpoints.append([x, y, 0]) #26
else:
if arrow == 'Without':
g = width-w * depth / 2
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #26
else:
g = width-w * depth / 100
x = cos(angle) * g
y = sin(angle) * g
newpoints.append([x, y, 0]) #26
return newpoints
##------------------------------------------------------------
# Dimension: Note
def Note(width = 2, length = 2, depth = 0.1, angle = 45, arrow = 'Arrow1', arrowdepth = 0.25, arrowlength = 0.25):
newpoints = []
if arrow == 'Serifs1' or arrow == 'Serifs2':
arrow = 'Without'
w = 1
if width < 0:
w = -1
angle = radians(angle)
length = abs(length)
if cos(angle) > 0:
newpoints.append([0, 0, 0]) #1
if arrow == 'Arrow1':
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #2
g = hypot(arrowlength, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #3
if arrow == 'Arrow2':
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #2
g = hypot(arrowlength * 3 / 4, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #3
if arrow == 'Without':
g = w * depth / 2
x = cos(angle + radians(90)) * g
y = sin(angle + radians(90)) * g
newpoints.append([x, y, 0]) #2
g = hypot(width, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle + u) * g
y = sin(angle) * width
newpoints.append([w * x, y + w * depth / 2, 0]) #4
newpoints.append([w * x + w * length, y + w * depth / 2, 0]) #5
newpoints.append([w * x + w * length, y-w * depth / 2, 0]) #6
g = hypot(width, depth / 2)
u = asin((depth / 2) / g)
y = sin(angle) * width
x = cos(angle-u) * g
newpoints.append([w * x, y-w * depth / 2, 0]) #7
if arrow == 'Arrow1':
g = hypot(arrowlength, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #8
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #9
if arrow == 'Arrow2':
g = hypot(arrowlength * 3 / 4, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #8
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #9
if arrow == 'Without':
g = -w * depth / 2
x = cos(angle + radians(90)) * g
y = sin(angle + radians(90)) * g
newpoints.append([x, y, 0]) #6
else:
newpoints.append([0, 0, 0]) #1
if arrow == 'Arrow1':
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #2
g = hypot(arrowlength, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #3
if arrow == 'Arrow2':
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #2
g = hypot(arrowlength * 3 / 4, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle-u) * g
y = sin(angle-u) * g
newpoints.append([w * x, y, 0]) #3
if arrow == 'Without':
g = -w * depth / 2
x = cos(angle + radians(90)) * g
y = sin(angle + radians(90)) * g
newpoints.append([x, y, 0]) #2
g = hypot(width, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle-u) * g
y = sin(angle) * width
newpoints.append([w * x, y + w * depth / 2, 0]) #4
newpoints.append([w * x-w * length, y + w * depth / 2, 0]) #5
newpoints.append([w * x-w * length, y-w * depth / 2, 0]) #6
g = hypot(width, depth / 2)
u = asin((depth / 2) / g)
y = sin(angle) * width
x = cos(angle + u) * g
newpoints.append([w * x, y-w * depth / 2, 0]) #7
if arrow == 'Arrow1':
g = hypot(arrowlength, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #8
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #9
if arrow == 'Arrow2':
g = hypot(arrowlength * 3 / 4, depth / 2)
u = asin((depth / 2) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #8
g = hypot(arrowlength, depth / 2 + arrowdepth)
u = asin((depth / 2 + arrowdepth) / g)
x = cos(angle + u) * g
y = sin(angle + u) * g
newpoints.append([w * x, y, 0]) #9
if arrow == 'Without':
g = w * depth / 2
x = cos(angle + radians(90)) * g
y = sin(angle + radians(90)) * g
newpoints.append([x, y, 0]) #6
return newpoints
##------------------------------------------------------------
# make and set Material
def makeMaterial(name, diffuse, specular, alpha):
mat = bpy.data.materials.new(name)
mat.diffuse_color = diffuse
mat.diffuse_shader = 'LAMBERT'
mat.diffuse_intensity = 1.0
mat.specular_color = specular
mat.specular_shader = 'COOKTORR'
mat.specular_intensity = 1.0
mat.alpha = alpha
mat.ambient = 1
mat.specular_hardness = 1
mat.use_shadeless = True
return mat
def setMaterial(ob, mat):
me = ob.data
me.materials.append(mat)
def ablength(x1 = 0.0, y1 = 0.0, z1 = 0.0, x2 = 0.0, y2 = 0.0, z2 = 0.0):
return sqrt( (x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2 )
##------------------------------------------------------------
# calculates the matrix for the new object
# depending on user pref
def align_matrix(context, location):
loc = Matrix.Translation(location)
obj_align = context.preferences.edit.object_align
if (context.space_data.type == 'VIEW_3D'
and obj_align == 'VIEW'):
rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
else:
rot = Matrix()
align_matrix = loc * rot
return align_matrix
##------------------------------------------------------------
#### Curve creation functions
# sets bezierhandles to auto
def setBezierHandles(obj, mode = 'VECTOR'):
view_layer = bpy.context.view_layer
if obj.type != 'CURVE':
return
bpy.ops.object.mode_set(mode = 'EDIT', toggle = True)
bpy.ops.curve.select_all(action = 'SELECT')
bpy.ops.curve.handle_type_set(type = mode)
bpy.ops.object.mode_set(mode = 'OBJECT', toggle = True)
bpy.context.scene.update()
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
##------------------------------------------------------------
#### Add units
def addUnits(stext, units):
scale = bpy.context.scene.unit_settings.scale_length
unit_system = bpy.context.scene.unit_settings.system
separate_units = bpy.context.scene.unit_settings.use_separate
if unit_system == 'METRIC':
if units == 'None': scale_steps = 1
if units == '\u00b5m': scale_steps = 1000000
if units == 'mm': scale_steps = 1000
if units == 'cm': scale_steps = 100
if units == 'm': scale_steps = 1
if units == 'km': scale_steps = 1/1000
if units == 'thou': scale_steps = 36000 * 1.0936133
if units == '"': scale_steps = 36 * 1.0936133
if units == '\'': scale_steps = 3 * 1.0936133
if units == 'yd': scale_steps = 1 * 1.0936133
if units == 'mi': scale_steps = 1/1760 * 1.0936133
dval = stext * scale_steps * scale
elif unit_system == 'IMPERIAL':
if units == 'None': scale_steps = 3 * 1.0936133
if units == '\u00b5m': scale_steps = 1000000
if units == 'mm': scale_steps = 1000
if units == 'cm': scale_steps = 100
if units == 'm': scale_steps = 1
if units == 'km': scale_steps = 1/1000
if units == 'thou': scale_steps = 36000 * 1.0936133
if units == '"': scale_steps = 36 * 1.0936133
if units == '\'': scale_steps = 3 * 1.0936133
if units == 'yd': scale_steps = 1 * 1.0936133
if units == 'mi': scale_steps = 1/1760 * 1.0936133
dval = stext * scale_steps * scale
else:
dval = stext
return dval
##------------------------------------------------------------
# create new CurveObject from vertarray and splineType
def createCurve(vertArray, self, align_matrix):
# options to vars
name = self.Dimension_Type # Type as name
# create curve
scene = bpy.context.scene
newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
newSpline = newCurve.splines.new('BEZIER') # spline
newSpline.bezier_points.add(int(len(vertArray) * 0.333333333))
newSpline.bezier_points.foreach_set('co', vertArray)
# set curveOptions
newCurve.dimensions = '2D'
newSpline.use_cyclic_u = True
newSpline.use_endpoint_u = True
# create object with newCurve
DimensionCurve = bpy.data.objects.new(name, newCurve) # object
scene.objects.link(DimensionCurve) # place in active scene
DimensionCurve.Dimension = True
DimensionCurve.matrix_world = align_matrix # apply matrix
self.Dimension_Name = DimensionCurve.name
# creat DimensionText and rotation
w = 1
if self.Dimension_width < 0 :
w = -1
l = 1
if self.Dimension_length < 0 :
l = -1
x = self.Dimension_width / 2
y = self.Dimension_length + l * self.Dimension_dsize / 2 + self.Dimension_depth / 2 + self.Dimension_textdepth
gettextround = int(self.Dimension_textround)
stext = addUnits(self.Dimension_width, self.Dimension_units)
stext = abs(round(stext, gettextround))
if gettextround == 0:
stext = abs(int(stext))
align = 'CENTER'
offset_y = 0
if self.Dimension_Type == 'Linear-2':
y = self.Dimension_depth / 2 + self.Dimension_textdepth
if self.Dimension_Type == 'Radius':
x = self.Dimension_width + w * self.Dimension_dsize / 2 + w * abs(self.Dimension_length) / 2
y = self.Dimension_depth / 2 + self.Dimension_textdepth
if self.Dimension_Type == 'Diameter':
x = 0
y = self.Dimension_depth / 2 + self.Dimension_textdepth
g = hypot(x, y)
c = self.Dimension_startlocation
u = asin(y / g)
if self.Dimension_width < 0 :
u = radians(180) - u
xx = cos(u) * g
yy = sin(u) * g
stext = str(stext)
cwolf3d@yandex.ru
committed
if self.Dimension_units != 'None' and self.Dimension_add_units_name:
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
stext += self.Dimension_units
if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
xx = cos(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
yy = sin(radians(self.Dimension_angle / 2)) * (self.Dimension_width + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth)
system_rotation = bpy.context.scene.unit_settings.system_rotation
if system_rotation == 'DEGREES':
stext = abs(round(self.Dimension_angle, gettextround))
if gettextround == 0:
stext = abs(int(stext))
stext = str(stext) + '°'
else:
stext = abs(round(self.Dimension_angle * pi / 180, gettextround))
if gettextround == 0:
stext = abs(int(stext))
stext = str(stext)
align = 'LEFT'
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'RIGHT'
if self.Dimension_width < 0 :
offset_y = 0
align = 'RIGHT'
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'LEFT'
if self.Dimension_Type == 'Note':
if cos(radians(self.Dimension_angle)) > 0:
xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
stext = self.Dimension_note
align = 'LEFT'
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'RIGHT'
if self.Dimension_width < 0 :
align = 'RIGHT'
xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) + l * w * self.Dimension_depth / 2 + l * w * self.Dimension_textdepth
yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'LEFT'
else:
xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) + w * self.Dimension_depth / 2 + w * self.Dimension_textdepth
stext = self.Dimension_note
align = 'RIGHT'
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'LEFT'
if self.Dimension_width < 0 :
align = 'LEFT'
xx = cos(radians(self.Dimension_angle)) * (self.Dimension_width) - l * w * self.Dimension_depth / 2 - l * w * self.Dimension_textdepth
yy = sin(radians(self.Dimension_angle)) * (self.Dimension_width) - w * self.Dimension_depth / 2 - w * self.Dimension_textdepth
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
align = 'RIGHT'
if self.Dimension_liberty == '2D':
tv = Vector((xx, yy, 0))
DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
DimensionCurve.rotation_euler[0] = radians(0)
DimensionCurve.rotation_euler[1] = radians(0)
if self.Dimension_XYType == 'X':
DimensionCurve.rotation_euler[2] = radians(self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[1] += self.Dimension_offset
if self.Dimension_XYType == 'Y':
DimensionCurve.rotation_euler[2] = radians(90+self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[0] += self.Dimension_offset
if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
DimensionCurve.rotation_euler[0] = radians(90)
if self.Dimension_XZType == 'X':
DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[1] += self.Dimension_offset
if self.Dimension_XZType == 'Z':
DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[0] += self.Dimension_offset
DimensionCurve.rotation_euler[2] = radians(0)
if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
DimensionCurve.rotation_euler[0] = radians(90)
if self.Dimension_YZType == 'Y':
DimensionCurve.rotation_euler[1] = -radians(self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[0] += self.Dimension_offset
if self.Dimension_YZType == 'Z':
DimensionCurve.rotation_euler[1] = -radians(90+self.Dimension_rotation)
cwolf3d@yandex.ru
committed
DimensionCurve.location[1] += self.Dimension_offset
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
DimensionCurve.rotation_euler[2] = radians(90)
if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'RIGHT':
DimensionText.rotation_euler[1] = radians(0)
if self.Dimension_XYZType == 'BOTTOM' or self.Dimension_XYZType == 'BACK' or self.Dimension_XYZType == 'LEFT':
DimensionText.rotation_euler[1] = radians(180)
if self.Dimension_width_or_location == 'location':
if self.Dimension_Type == 'Angular1' or self.Dimension_Type == 'Angular2' or self.Dimension_Type == 'Angular3':
vx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
vy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
vz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
g = hypot(vx, vy)
if g != 0 :
u2 = acos(vx / g)
u1 = asin(vy / g)
if u1 < 0 :
u2 = u1
else:
u2 = 0
DimensionCurve.rotation_euler[2] = u2
if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
g = hypot(vx, vz)
if g != 0 :
u2 = acos(vx / g)
u1 = asin(vz / g)
if u1 < 0 :
u2 = u1
else:
u2 = 0
DimensionCurve.rotation_euler[1] = -u2
if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
g = hypot(vy, vz)
if g != 0 :
u2 = acos(vy / g)
u1 = asin(vz / g)
if u1 < 0 :
u2 = u1
else:
u2 = 0
DimensionCurve.rotation_euler[1] = -u2
if self.Dimension_liberty == '3D':
tv = Vector((xx, yy, 0))
DimensionText = addText(stext, tv, self.Dimension_textsize, align, offset_y, self.Dimension_font)
v = self.Dimension_endlocation - self.Dimension_startlocation
if v.length != 0 :
u1 = -asin(v[2] / v.length)
else:
u1 = 0
g = hypot(v[0], v[1])
if g != 0 :
u2 = asin(v[1] / g)
if self.Dimension_endlocation.x < self.Dimension_startlocation.x :
u2 = radians(180)-asin(v[1] / g)
else:
u2 = 0
DimensionCurve.rotation_euler[0] = radians(self.Dimension_rotation)
DimensionCurve.rotation_euler[1] = u1
DimensionCurve.rotation_euler[2] = u2
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
# Align to view
if self.Dimension_align_to_camera :
obj_camera = bpy.context.scene.camera
DimensionCurve.rotation_euler[0] = obj_camera.rotation_euler[0]
DimensionCurve.rotation_euler[1] = obj_camera.rotation_euler[1]
DimensionCurve.rotation_euler[2] = obj_camera.rotation_euler[2]
# set materials
if self.Dimension_matname in bpy.data.materials :
setMaterial(DimensionCurve, bpy.data.materials[self.Dimension_matname])
setMaterial(DimensionText, bpy.data.materials[self.Dimension_matname])
else:
red = makeMaterial(self.Dimension_matname, (1, 0, 0), (1, 0, 0), 1)
setMaterial(DimensionCurve, red)
setMaterial(DimensionText, red)
setBezierHandles(DimensionCurve, 'VECTOR')
setBezierHandles(DimensionText, 'VECTOR')
group_name = 'Dimensions'
bpy.ops.object.mode_set(mode = 'OBJECT')
if group_name in bpy.data.collections:
group = bpy.data.collections[group_name]
group = bpy.data.collections.new(group_name)
if not DimensionCurve.name in group.objects:
group.objects.link(DimensionCurve)
if not DimensionText.name in group.objects:
group.objects.link(DimensionText)
DimensionText.parent = DimensionCurve
if self.Dimension_appoint_parent and not self.Dimension_parent == '':
const = DimensionCurve.constraints.new(type='CHILD_OF')
const.target = bpy.data.objects[self.Dimension_parent]
const.inverse_matrix = bpy.data.objects[self.Dimension_parent].matrix_world.inverted()
bpy.context.scene.update()
bpy.ops.object.select_all(action='DESELECT')
DimensionCurve.select_set(True)
DimensionText.select_set(True)
bpy.context.view_layer.objects.active = DimensionCurve
bpy.context.scene.update()
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
DimensionCurve.Dimension_Name = self.Dimension_Name
DimensionCurve.Dimension_Type = self.Dimension_Type
DimensionCurve.Dimension_XYZType = self.Dimension_XYZType
DimensionCurve.Dimension_XYType = self.Dimension_XYType
DimensionCurve.Dimension_XZType = self.Dimension_XZType
DimensionCurve.Dimension_YZType = self.Dimension_YZType
DimensionCurve.Dimension_startlocation = c
DimensionCurve.Dimension_endlocation = self.Dimension_endlocation
DimensionCurve.Dimension_endanglelocation = self.Dimension_endanglelocation
DimensionCurve.Dimension_width_or_location = self.Dimension_width_or_location
DimensionCurve.Dimension_liberty = self.Dimension_liberty
DimensionCurve.Dimension_Change = False
#### Dimension properties
DimensionCurve.Dimension_resolution = self.Dimension_resolution
DimensionCurve.Dimension_width = self.Dimension_width
DimensionCurve.Dimension_length = self.Dimension_length
DimensionCurve.Dimension_dsize = self.Dimension_dsize
DimensionCurve.Dimension_depth = self.Dimension_depth
DimensionCurve.Dimension_depth_from_center = self.Dimension_depth_from_center
DimensionCurve.Dimension_angle = self.Dimension_angle
DimensionCurve.Dimension_rotation = self.Dimension_rotation
cwolf3d@yandex.ru
committed
DimensionCurve.Dimension_offset = self.Dimension_offset
#### Dimension text properties
DimensionCurve.Dimension_textsize = self.Dimension_textsize
DimensionCurve.Dimension_textdepth = self.Dimension_textdepth
DimensionCurve.Dimension_textround = self.Dimension_textround
DimensionCurve.Dimension_font = self.Dimension_font
#### Dimension Arrow properties
DimensionCurve.Dimension_arrow = self.Dimension_arrow
DimensionCurve.Dimension_arrowdepth = self.Dimension_arrowdepth
DimensionCurve.Dimension_arrowlength = self.Dimension_arrowlength
#### Materials properties
DimensionCurve.Dimension_matname = self.Dimension_matname
#### Note properties
DimensionCurve.Dimension_note = self.Dimension_note
DimensionCurve.Dimension_align_to_camera = self.Dimension_align_to_camera
#### Parent
DimensionCurve.Dimension_parent = self.Dimension_parent
DimensionCurve.Dimension_appoint_parent = self.Dimension_appoint_parent
cwolf3d@yandex.ru
committed
#### Units
DimensionCurve.Dimension_units = self.Dimension_units
DimensionCurve.Dimension_add_units_name = self.Dimension_add_units_name
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
return
##------------------------------------------------------------
# Main Function
def main(self, align_matrix):
# deselect all objects
bpy.ops.object.select_all(action = 'DESELECT')
# options
Type = self.Dimension_Type
if self.Dimension_width_or_location == 'location':
if self.Dimension_liberty == '2D':
if self.Dimension_XYZType == 'TOP':
if self.Dimension_XYType == 'X':
self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
if self.Dimension_XYType == 'Y':
self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
if self.Dimension_XYZType == 'FRONT':
if self.Dimension_XZType == 'X':
self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
if self.Dimension_XZType == 'Z':
self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
if self.Dimension_XYZType == 'RIGHT':
if self.Dimension_YZType == 'Y':
self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
if self.Dimension_YZType == 'Z':
self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
if self.Dimension_XYZType == 'BOTTOM':
if self.Dimension_XYType == 'X':
self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
if self.Dimension_XYType == 'Y':
self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
if self.Dimension_XYZType == 'BACK':
if self.Dimension_XZType == 'X':
self.Dimension_width = self.Dimension_endlocation[0] - self.Dimension_startlocation[0]
if self.Dimension_XZType == 'Z':
self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
if self.Dimension_XYZType == 'LEFT':
if self.Dimension_YZType == 'Y':
self.Dimension_width = self.Dimension_endlocation[1] - self.Dimension_startlocation[1]
if self.Dimension_YZType == 'Z':
self.Dimension_width = self.Dimension_endlocation[2] - self.Dimension_startlocation[2]
if self.Dimension_liberty == '3D':
v = self.Dimension_endlocation - self.Dimension_startlocation
self.Dimension_width = v.length
if Type == 'Angular1' or Type == 'Angular2' or Type == 'Angular3':
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)
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)
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)
self.Dimension_width = max(a, b, c)
vanglex = self.Dimension_endanglelocation.x - self.Dimension_startlocation.x
vangley = self.Dimension_endanglelocation.y - self.Dimension_startlocation.y
vanglez = self.Dimension_endanglelocation.z - self.Dimension_startlocation.z
vendx = self.Dimension_endlocation.x - self.Dimension_startlocation.x
vendy = self.Dimension_endlocation.y - self.Dimension_startlocation.y
vendz = self.Dimension_endlocation.z - self.Dimension_startlocation.z
if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
self.Dimension_XYType = 'X'
g = hypot(vanglex, vangley)
if g != 0 :
u2 = acos(vanglex / g)
u1 = asin(vangley / g)
if u1 < 0 :
u2 = -u2
else:
u2 = 0
g = hypot(vendx, vendy)
if g != 0 :
uu2 = acos(vendx / g)
uu1 = asin(vendy / g)
if uu1 < 0 :
uu2 = -uu2
else:
uu2 = 0
self.Dimension_angle = degrees(u2 - uu2)
if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
self.Dimension_XZType = 'Z'
g = hypot(vanglex, vanglez)
if g != 0 :
u2 = acos(vanglex / g)
u1 = asin(vanglez / g)
if u1 < 0 :
u2 = -u2
else:
u2 = 0
g = hypot(vendx, vendz)
if g != 0 :
uu2 = acos(vendx / g)
uu1 = asin(vendz / g)
if uu1 < 0 :
uu2 = -uu2
else:
uu2 = 0
self.Dimension_angle = degrees(u2 - uu2)
if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
self.Dimension_YZType = 'Z'
g = hypot(vangley, vanglez)
if g != 0 :
u2 = acos(vangley / g)
u1 = asin(vanglez / g)
if u1 < 0 :
u2 = -u2
else:
u2 = 0
g = hypot(vendy, vendz)
if g != 0 :
uu2 = acos(vendy / g)
uu1 = asin(vendz / g)
if uu1 < 0 :
uu2 = -uu2
else:
uu2 = 0
self.Dimension_angle = degrees(u2 - uu2)
if self.Dimension_liberty == '3D':
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)
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)
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)
if b != 0 and c != 0 :
self.Dimension_angle = degrees(acos((b**2 + c**2 - a**2)/(2*b*c)))
else:
self.Dimension_angle = 0
#
if self.Dimension_width == 0:
return {'FINISHED'}
# get verts
if Type == 'Linear-1':
verts = Linear1(self.Dimension_width,
self.Dimension_length,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Linear-2':
verts = Linear2(self.Dimension_width,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Linear-3':
verts = Linear3(self.Dimension_width,
self.Dimension_length,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Radius':
verts = Radius(self.Dimension_width,
self.Dimension_length,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Diameter':
verts = Diameter(self.Dimension_width,
self.Dimension_length,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Angular1':
if self.Dimension_angle == 0:
return {'FINISHED'}
verts = Angular1(self.Dimension_width,
self.Dimension_length,
self.Dimension_depth,
self.Dimension_angle,
self.Dimension_resolution,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Angular2':
if self.Dimension_angle == 0:
return {'FINISHED'}
verts = Angular2(self.Dimension_width,
self.Dimension_depth,
self.Dimension_angle,
self.Dimension_resolution,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Angular3':
if self.Dimension_angle == 0:
return {'FINISHED'}
verts = Angular3(self.Dimension_width,
self.Dimension_length,
self.Dimension_dsize,
self.Dimension_depth,
self.Dimension_angle,
self.Dimension_resolution,
self.Dimension_depth_from_center,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
if Type == 'Note':
verts = Note(self.Dimension_width,
self.Dimension_length,
self.Dimension_depth,
self.Dimension_angle,
self.Dimension_arrow,
self.Dimension_arrowdepth,
self.Dimension_arrowlength)
vertArray = []
# turn verts into array
for v in verts:
vertArray += v
# create object
createCurve(vertArray, self, align_matrix)
return
#### Delete dimension group
def DimensionDelete(self, context):
bpy.context.scene.update()
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
bpy.ops.object.delete()
bpy.context.scene.update()
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
return
class Dimension(bpy.types.Operator):
''''''
bl_idname = "curve.dimension"
bl_label = "Dimension"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "add dimension"
# align_matrix for the invoke
align_matrix = Matrix()
Dimension = BoolProperty(name = "Dimension",
default = True,
description = "dimension")
#### change properties
Dimension_Name = StringProperty(name = "Name",
description = "Name")
Dimension_Change = BoolProperty(name = "Change",
default = False,
description = "change dimension")
Dimension_Delete = StringProperty(name = "Delete",
description = "Delete dimension")
#### general properties
Types = [('Linear-1', 'Linear-1', 'Linear-1'),
('Linear-2', 'Linear-2', 'Linear-2'),
('Linear-3', 'Linear-3', 'Linear-3'),
('Radius', 'Radius', 'Radius'),
('Diameter', 'Diameter', 'Diameter'),
('Angular1', 'Angular1', 'Angular1'),
('Angular2', 'Angular2', 'Angular2'),
('Angular3', 'Angular3', 'Angular3'),
('Note', 'Note', 'Note')]
Dimension_Type = EnumProperty(name = "Type",
description = "Form of Curve to create",
items = Types)
XYZTypes = [
('TOP', 'Top', 'TOP'),
('FRONT', 'Front', 'FRONT'),
('RIGHT', 'Right', 'RIGHT'),
('BOTTOM', 'Bottom', 'BOTTOM'),
('BACK', 'Back', 'BACK'),
('LEFT', 'Left', 'LEFT')]
Dimension_XYZType = EnumProperty(name = "Coordinate system",
description = "Place in a coordinate system",
items = XYZTypes)
XYTypes = [
('X', 'X', 'X'),
('Y', 'Y', 'Y')]
Dimension_XYType = EnumProperty(name = "XY",
description = "XY",
items = XYTypes)
XZTypes = [
('X', 'X', 'X'),
('Z', 'Z', 'Z')]
Dimension_XZType = EnumProperty(name = "XZ",
description = "XZ",
items = XZTypes)
YZTypes = [
('Y', 'Y', 'Y'),
('Z', 'Z', 'Z')]
Dimension_YZType = EnumProperty(name = "YZ",
description = "YZ",
items = YZTypes)
Dimension_startlocation = FloatVectorProperty(name = "",
description = "Start location",
default = (0.0, 0.0, 0.0),
subtype = 'XYZ')
Dimension_endlocation = FloatVectorProperty(name = "",
description = "End location",
default = (2.0, 2.0, 2.0),
subtype = 'XYZ')
Dimension_endanglelocation = FloatVectorProperty(name = "",
description = "End angle location",
default = (4.0, 4.0, 4.0),
subtype = 'XYZ')
width_or_location_items = [
('width', 'width', 'width'),
('location', 'location', 'location')]
Dimension_width_or_location = EnumProperty(name = "width or location",
items = width_or_location_items,
description = "width or location")
libertyItems = [
('2D', '2D', '2D'),
('3D', '3D', '3D')]
Dimension_liberty = EnumProperty(name = "2D / 3D",
items = libertyItems,
description = "2D or 3D Dimension")
### Arrow
Arrows = [
('Arrow1', 'Arrow1', 'Arrow1'),
('Arrow2', 'Arrow2', 'Arrow2'),
('Serifs1', 'Serifs1', 'Serifs1'),
('Serifs2', 'Serifs2', 'Serifs2'),
('Without', 'Without', 'Without')]
Dimension_arrow = EnumProperty(name = "Arrow",
items = Arrows,
description = "Arrow")
Dimension_arrowdepth = FloatProperty(name = "Depth",
default = 0.1,
min = 0, soft_min = 0,
description = "Arrow depth")
Dimension_arrowlength = FloatProperty(name = "Length",
default = 0.25,
min = 0, soft_min = 0,
description = "Arrow length")
#### Dimension properties
Dimension_resolution = IntProperty(name = "Resolution",
default = 10,
min = 1, soft_min = 1,
description = "Resolution")
Dimension_width = FloatProperty(name = "Width",
default = 2,
unit = 'LENGTH',
description = "Width")
Dimension_length = FloatProperty(name = "Length",
default = 2,
description = "Length")
Dimension_dsize = FloatProperty(name = "Size",
default = 1,
min = 0, soft_min = 0,
description = "Size")
Dimension_depth = FloatProperty(name = "Depth",
min = 0, soft_min = 0,
description = "Depth")
Dimension_depth_from_center = BoolProperty(name = "Depth from center",
default = False,
description = "Depth from center")
Dimension_angle = FloatProperty(name = "Angle",
default = 45,
description = "Angle")
Dimension_rotation = FloatProperty(name = "Rotation",
default = 0,
description = "Rotation")
cwolf3d@yandex.ru
committed
Dimension_offset = FloatProperty(name = "Offset",
default = 0,
description = "Offset")
#### Dimension units properties
Units = [
('None', 'None', 'None'),
('\u00b5m', '\u00b5m', '\u00b5m'),
('mm', 'mm', 'mm'),
('cm', 'cm', 'cm'),
('m', 'm', 'm'),
('km', 'km', 'km'),
('thou', 'thou', 'thou'),
('"', '"', '"'),
('\'', '\'', '\''),
('yd', 'yd', 'yd'),
('mi', 'mi', 'mi')]
Dimension_units = EnumProperty(name = "Units",
items = Units,
description = "Units")
cwolf3d@yandex.ru
committed
Dimension_add_units_name = BoolProperty(name = "Add units name",
default = False,
description = "Add units name")
#### Dimension text properties
Dimension_textsize = FloatProperty(name = "Size",
default = 1,
description = "Size")
Dimension_textdepth = FloatProperty(name = "Depth",
default = 0.2,
description = "Depth")
Dimension_textround = IntProperty(name = "Rounding",
default = 2,
min = 0, soft_min = 0,
description = "Rounding")
Dimension_font = StringProperty(name = "Font",
default = '',
subtype = 'FILE_PATH',
description = "Font")
#### Materials properties
Dimension_matname = StringProperty(name = "Name",
default = 'Dimension_Red',
description = "Material name")
#### Note properties
Dimension_note = StringProperty(name = "Note",
default = 'Note',
description = "Note text")
Dimension_align_to_camera = BoolProperty(name = "Align to camera",
default = False,
description = "Align to camera")
TMP_startlocation = FloatVectorProperty(name = "",
description = "Start location",
default = (0.0, 0.0, 0.0),
subtype = 'XYZ')
TMP_endlocation = FloatVectorProperty(name = "",
description = "Start location",
default = (2.0, 2.0, 2.0),
subtype = 'XYZ')
TMP_endanglelocation = FloatVectorProperty(name = "",
description = "Start location",
default = (4.0, 4.0, 4.0),
subtype = 'XYZ')
#### Parent
Dimension_parent = StringProperty(name = "Parent",
default = '',
description = "Parent")
Dimension_appoint_parent = BoolProperty(name = "Appoint parent",
default = False,
description = "Appoint parent")
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
##### DRAW #####
def draw(self, context):
layout = self.layout
# general options
col = layout.column()
col.prop(self, 'Dimension_Type')
# options per Type Linear-1(width = 2, length = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Linear-1':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_depth_from_center')
box.prop(self, 'Dimension_rotation')
cwolf3d@yandex.ru
committed
box.prop(self, 'Dimension_offset')
# options per Type Linear-2(width = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Linear-2':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_rotation')
cwolf3d@yandex.ru
committed
box.prop(self, 'Dimension_offset')
# options per Type Linear-3(width = 2, length = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Linear-3':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_depth_from_center')
box.prop(self, 'Dimension_rotation')
cwolf3d@yandex.ru
committed
box.prop(self, 'Dimension_offset')
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
# options per Type Radius(width = 2, length = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Radius':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_rotation')
# options per Type Diameter(width = 2, length = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Diameter':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_rotation')
# options per Type Angular1(width = 2, dsize = 1, depth = 0.1, angle = 45)
if self.Dimension_Type == 'Angular1':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_angle')
else:
row.prop(self, 'Dimension_endlocation')
col = layout.column()
col.label(text = "End angle location:")
row = layout.row()
row.prop(self, 'Dimension_endanglelocation')
row = layout.row()
props = row.operator("curve.dimension", text = 'Change angle')
props.Dimension_Change = True
props.Dimension_Delete = self.Dimension_Name
props.Dimension_width_or_location = self.Dimension_width_or_location
props.Dimension_startlocation = self.Dimension_endanglelocation
props.Dimension_endlocation = self.Dimension_startlocation
props.Dimension_endanglelocation = self.Dimension_endlocation
props.Dimension_liberty = self.Dimension_liberty
props.Dimension_Type = self.Dimension_Type
props.Dimension_XYZType = self.Dimension_XYZType
props.Dimension_XYType = self.Dimension_XYType
props.Dimension_XZType = self.Dimension_XZType
props.Dimension_YZType = self.Dimension_YZType
props.Dimension_resolution = self.Dimension_resolution
props.Dimension_width = self.Dimension_width
props.Dimension_length = self.Dimension_length
props.Dimension_dsize = self.Dimension_dsize
props.Dimension_depth = self.Dimension_depth
props.Dimension_depth_from_center = self.Dimension_depth_from_center
props.Dimension_angle = self.Dimension_angle
props.Dimension_rotation = self.Dimension_rotation
cwolf3d@yandex.ru
committed
props.Dimension_offset = self.Dimension_offset
props.Dimension_textsize = self.Dimension_textsize
props.Dimension_textdepth = self.Dimension_textdepth
props.Dimension_textround = self.Dimension_textround
props.Dimension_matname = self.Dimension_matname
props.Dimension_note = self.Dimension_note
props.Dimension_align_to_camera = self.Dimension_align_to_camera
props.Dimension_arrow = self.Dimension_arrow
props.Dimension_arrowdepth = self.Dimension_arrowdepth
props.Dimension_arrowlength = self.Dimension_arrowlength
props.Dimension_parent = self.Dimension_parent
props.Dimension_appoint_parent = self.Dimension_appoint_parent
cwolf3d@yandex.ru
committed
props.Dimension_units = self.Dimension_units
props.Dimension_add_units_name = self.Dimension_add_units_name
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_width')
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_depth_from_center')
box.prop(self, 'Dimension_rotation')
box.prop(self, 'Dimension_resolution')
# options per Type Angular2(width = 2, dsize = 1, depth = 0.1, angle = 45)
if self.Dimension_Type == 'Angular2':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_angle')
else:
row.prop(self, 'Dimension_endlocation')
col = layout.column()
col.label(text = "End angle location:")
row = layout.row()
row.prop(self, 'Dimension_endanglelocation')
row = layout.row()
props = row.operator("curve.dimension", text = 'Change angle')
props.Dimension_Change = True
props.Dimension_Delete = self.Dimension_Name
props.Dimension_width_or_location = self.Dimension_width_or_location
props.Dimension_startlocation = self.Dimension_endanglelocation
props.Dimension_endlocation = self.Dimension_startlocation
props.Dimension_endanglelocation = self.Dimension_endlocation
props.Dimension_liberty = self.Dimension_liberty
props.Dimension_Type = self.Dimension_Type
props.Dimension_XYZType = self.Dimension_XYZType
props.Dimension_XYType = self.Dimension_XYType
props.Dimension_XZType = self.Dimension_XZType
props.Dimension_YZType = self.Dimension_YZType
props.Dimension_resolution = self.Dimension_resolution
props.Dimension_width = self.Dimension_width
props.Dimension_length = self.Dimension_length
props.Dimension_dsize = self.Dimension_dsize
props.Dimension_depth = self.Dimension_depth
props.Dimension_depth_from_center = self.Dimension_depth_from_center
props.Dimension_angle = self.Dimension_angle
props.Dimension_rotation = self.Dimension_rotation
cwolf3d@yandex.ru
committed
props.Dimension_offset = self.Dimension_offset
props.Dimension_textsize = self.Dimension_textsize
props.Dimension_textdepth = self.Dimension_textdepth
props.Dimension_textround = self.Dimension_textround
props.Dimension_matname = self.Dimension_matname
props.Dimension_note = self.Dimension_note
props.Dimension_align_to_camera = self.Dimension_align_to_camera
props.Dimension_arrow = self.Dimension_arrow
props.Dimension_arrowdepth = self.Dimension_arrowdepth
props.Dimension_arrowlength = self.Dimension_arrowlength
props.Dimension_parent = self.Dimension_parent
props.Dimension_appoint_parent = self.Dimension_appoint_parent
cwolf3d@yandex.ru
committed
props.Dimension_units = self.Dimension_units
props.Dimension_add_units_name = self.Dimension_add_units_name
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_width')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_rotation')
box.prop(self, 'Dimension_resolution')
# options per Type Angular3(width = 2, dsize = 1, depth = 0.1, angle = 45)
if self.Dimension_Type == 'Angular3':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_angle')
else:
row.prop(self, 'Dimension_endlocation')
col = layout.column()
col.label(text = "End angle location:")
row = layout.row()
row.prop(self, 'Dimension_endanglelocation')
row = layout.row()
props = row.operator("curve.dimension", text = 'Change angle')
props.Dimension_Change = True
props.Dimension_Delete = self.Dimension_Name
props.Dimension_width_or_location = self.Dimension_width_or_location
props.Dimension_startlocation = self.Dimension_endanglelocation
props.Dimension_endlocation = self.Dimension_startlocation
props.Dimension_endanglelocation = self.Dimension_endlocation
props.Dimension_liberty = self.Dimension_liberty
props.Dimension_Type = self.Dimension_Type
props.Dimension_XYZType = self.Dimension_XYZType
props.Dimension_XYType = self.Dimension_XYType
props.Dimension_XZType = self.Dimension_XZType
props.Dimension_YZType = self.Dimension_YZType
props.Dimension_resolution = self.Dimension_resolution
props.Dimension_width = self.Dimension_width
props.Dimension_length = self.Dimension_length
props.Dimension_dsize = self.Dimension_dsize
props.Dimension_depth = self.Dimension_depth
props.Dimension_depth_from_center = self.Dimension_depth_from_center
props.Dimension_angle = self.Dimension_angle
props.Dimension_rotation = self.Dimension_rotation
cwolf3d@yandex.ru
committed
props.Dimension_offset = self.Dimension_offset
props.Dimension_textsize = self.Dimension_textsize
props.Dimension_textdepth = self.Dimension_textdepth
props.Dimension_textround = self.Dimension_textround
props.Dimension_matname = self.Dimension_matname
props.Dimension_note = self.Dimension_note
props.Dimension_align_to_camera = self.Dimension_align_to_camera
props.Dimension_arrow = self.Dimension_arrow
props.Dimension_arrowdepth = self.Dimension_arrowdepth
props.Dimension_arrowlength = self.Dimension_arrowlength
props.Dimension_parent = self.Dimension_parent
props.Dimension_appoint_parent = self.Dimension_appoint_parent
cwolf3d@yandex.ru
committed
props.Dimension_units = self.Dimension_units
props.Dimension_add_units_name = self.Dimension_add_units_name
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_width')
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_dsize')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_depth_from_center')
box.prop(self, 'Dimension_rotation')
box.prop(self, 'Dimension_resolution')
# options per Type Note(width = 2, length = 2, dsize = 1, depth = 0.1)
if self.Dimension_Type == 'Note':
row = layout.row()
row.prop(self, 'Dimension_width_or_location', expand = True)
col = layout.column()
col.label(text = "End location:")
row = layout.row()
if self.Dimension_width_or_location == 'width':
row.prop(self, 'Dimension_width')
else:
row.prop(self, 'Dimension_endlocation')
box = layout.box()
box.label("Options")
box.prop(self, 'Dimension_length')
box.prop(self, 'Dimension_depth')
box.prop(self, 'Dimension_angle')
box.prop(self, 'Dimension_rotation')
box.prop(self, 'Dimension_note')
cwolf3d@yandex.ru
committed
box.prop(self, 'Dimension_offset')
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
col = layout.column()
row = layout.row()
row.prop(self, 'Dimension_align_to_camera')
col = layout.column()
row = layout.row()
row.prop(self, 'Dimension_liberty', expand = True)
if self.Dimension_liberty == '2D':
col = layout.column()
col.label("Coordinate system")
row = layout.row()
row.prop(self, 'Dimension_XYZType', expand = True)
if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
row = layout.row()
row.prop(self, 'Dimension_XYType', expand = True)
if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
row = layout.row()
row.prop(self, 'Dimension_XZType', expand = True)
if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
row = layout.row()
row.prop(self, 'Dimension_YZType', expand = True)
col = layout.column()
col.label("Start location:")
row = layout.row()
row.prop(self, 'Dimension_startlocation')
box = layout.box()
box.prop(self, 'Dimension_units')
cwolf3d@yandex.ru
committed
box.prop(self, 'Dimension_add_units_name')
if not self.Dimension_parent == '':
box = layout.box()
box.prop(self, 'Dimension_appoint_parent')
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
box = layout.box()
box.label("Text Options")
box.prop(self, 'Dimension_textsize')
box.prop(self, 'Dimension_textdepth')
box.prop(self, 'Dimension_textround')
box.prop(self, 'Dimension_font')
box = layout.box()
box.label("Arrow Options")
box.prop(self, 'Dimension_arrow')
box.prop(self, 'Dimension_arrowdepth')
box.prop(self, 'Dimension_arrowlength')
box = layout.box()
box.label("Material Option")
box.prop(self, 'Dimension_matname')
##### POLL #####
@classmethod
def poll(cls, context):
return context.scene != None
##### EXECUTE #####
def execute(self, context):
if self.Dimension_Change:
DimensionDelete(self, context)
#go to object mode
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.context.scene.update()
# turn off undo
undo = bpy.context.preferences.edit.use_global_undo
bpy.context.preferences.edit.use_global_undo = False
# main function
self.align_matrix = align_matrix(context, self.Dimension_startlocation)
main(self, self.align_matrix)
# restore pre operator undo state
bpy.context.preferences.edit.use_global_undo = undo
return {'FINISHED'}
##### INVOKE #####
def invoke(self, context, event):
bpy.context.scene.update()
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
if self.Dimension_Change:
bpy.context.scene.cursor_location = self.Dimension_startlocation
else:
if self.Dimension_width_or_location == 'width':
self.Dimension_startlocation = bpy.context.scene.cursor_location
if self.Dimension_width_or_location == 'location':
if (self.Dimension_endlocation[2] - self.Dimension_startlocation[2]) != 0 :
self.Dimension_XYZType = 'FRONT'
self.Dimension_XZType = 'Z'
if (self.Dimension_endlocation[1] - self.Dimension_startlocation[1]) != 0 :
self.Dimension_XYZType = 'TOP'
self.Dimension_XYType = 'Y'
if (self.Dimension_endlocation[0] - self.Dimension_startlocation[0]) != 0 :
self.Dimension_XYZType = 'TOP'
self.Dimension_XYType = 'X'
self.align_matrix = align_matrix(context, self.Dimension_startlocation)
self.execute(context)
return {'FINISHED'}
# Properties class
class DimensionAdd(bpy.types.Panel):
''''''
bl_idname = "VIEW3D_PT_properties_dimension_add"
bl_label = "Dimension Add"
bl_description = "Dimension Add"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
@classmethod
def poll(cls, context):
selected = 0
for obj in context.selected_objects :
if obj.type == 'MESH':
for i in obj.data.vertices :
if i.select :
selected += 1
if obj.type == 'CURVE':
for i in obj.data.splines :
for j in i.bezier_points :
if j.select_control_point :
selected += 1
if selected == 1 or selected == 2 or selected == 3:
return context.selected_objects
##### DRAW #####
def draw(self, context):
vertex = []
for obj in context.selected_objects :
if obj.type == 'MESH':
for i in obj.data.vertices :
if i.select :
vertex.append(obj.matrix_world * i.co)
if obj.type == 'CURVE':
for i in obj.data.splines :
for j in i.bezier_points :
if j.select_control_point :
vertex.append(obj.matrix_world * j.co)
if len(vertex) == 1:
startvertex = vertex[0]
endvertex = bpy.context.scene.cursor_location
layout = self.layout
col = layout.column()
row = layout.row()
props1 = row.operator("curve.dimension", text = 'Add linear note')
props1.Dimension_Change = False
props1.Dimension_Type = 'Note'
props1.Dimension_width_or_location = 'location'
props1.Dimension_startlocation = startvertex
props1.Dimension_liberty = '2D'
props1.Dimension_rotation = 0
props1.Dimension_parent = obj.name
props2 = row.operator("curve.dimension", text = 'Add 3D note')
props2.Dimension_Change = False
props2.Dimension_Type = 'Note'
props2.Dimension_width_or_location = 'location'
props2.Dimension_startlocation = startvertex
props2.Dimension_liberty = '3D'
props2.Dimension_rotation = 0
props2.Dimension_parent = obj.name
col = layout.column()
col.label(text="Distance to 3D cursor:")
row = layout.row()
props3 = row.operator("curve.dimension", text = 'Add linear dimension')
props3.Dimension_Change = False
props3.Dimension_Type = 'Linear-1'
props3.Dimension_width_or_location = 'location'
props3.Dimension_startlocation = endvertex
props3.Dimension_endlocation = startvertex
props3.Dimension_liberty = '2D'
props3.Dimension_rotation = 0
props3.Dimension_parent = obj.name
props4 = row.operator("curve.dimension", text = 'Add 3D dimension')
props4.Dimension_Change = False
props4.Dimension_Type = 'Linear-1'
props4.Dimension_width_or_location = 'location'
props4.Dimension_startlocation = endvertex
props4.Dimension_endlocation = startvertex
props4.Dimension_liberty = '3D'
props4.Dimension_rotation = 0
props4.Dimension_parent = obj.name
col = layout.column()
col.label(text="Radius to 3D cursor:")
row = layout.row()
props7 = row.operator("curve.dimension", text = 'Add linear radius')
props7.Dimension_Change = False
props7.Dimension_Type = 'Radius'
props7.Dimension_width_or_location = 'location'
props7.Dimension_startlocation = endvertex
props7.Dimension_endlocation = startvertex
props7.Dimension_liberty = '2D'
props7.Dimension_rotation = 0
props7.Dimension_parent = obj.name
props8 = row.operator("curve.dimension", text = 'Add 3D radius')
props8.Dimension_Change = False
props8.Dimension_Type = 'Radius'
props8.Dimension_width_or_location = 'location'
props8.Dimension_startlocation = endvertex
props8.Dimension_endlocation = startvertex
props8.Dimension_liberty = '3D'
props8.Dimension_rotation = 0
props8.Dimension_parent = obj.name
col = layout.column()
col.label(text="Diameter to 3D cursor:")
row = layout.row()
props9 = row.operator("curve.dimension", text = 'Add linear diameter')
props9.Dimension_Change = False
props9.Dimension_Type = 'Diameter'
props9.Dimension_width_or_location = 'location'
props9.Dimension_startlocation = endvertex
props9.Dimension_endlocation = startvertex
props9.Dimension_liberty = '2D'
props9.Dimension_rotation = 0
props9.Dimension_parent = obj.name
props10 = row.operator("curve.dimension", text = 'Add 3D diameter')
props10.Dimension_Change = False
props10.Dimension_Type = 'Diameter'
props10.Dimension_width_or_location = 'location'
props10.Dimension_startlocation = endvertex
props10.Dimension_endlocation = startvertex
props10.Dimension_liberty = '3D'
props10.Dimension_rotation = 0
props10.Dimension_parent = obj.name
if len(vertex) == 2:
startvertex = vertex[0]
endvertex = vertex[1]
if endvertex[0] < startvertex[0]:
startvertex = vertex[1]
endvertex = vertex[0]
layout = self.layout
col = layout.column()
col.label(text="Distance:")
row = layout.row()
props1 = row.operator("curve.dimension", text = 'Add linear dimension')
props1.Dimension_Change = False
props1.Dimension_Type = 'Linear-1'
props1.Dimension_width_or_location = 'location'
props1.Dimension_startlocation = startvertex
props1.Dimension_endlocation = endvertex
props1.Dimension_liberty = '2D'
props1.Dimension_rotation = 0
props1.Dimension_parent = obj.name
props2 = row.operator("curve.dimension", text = 'Add 3D dimension')
props2.Dimension_Change = False
props2.Dimension_Type = 'Linear-1'
props2.Dimension_width_or_location = 'location'
props2.Dimension_startlocation = startvertex
props2.Dimension_endlocation = endvertex
props2.Dimension_liberty = '3D'
props2.Dimension_rotation = 0
props2.Dimension_parent = obj.name
col = layout.column()
col.label(text="Radius:")
row = layout.row()
props3 = row.operator("curve.dimension", text = 'Add linear radius')
props3.Dimension_Change = False
props3.Dimension_Type = 'Radius'
props3.Dimension_width_or_location = 'location'
props3.Dimension_startlocation = startvertex
props3.Dimension_endlocation = endvertex
props3.Dimension_liberty = '2D'
props3.Dimension_rotation = 0
props3.Dimension_parent = obj.name
props4 = row.operator("curve.dimension", text = 'Add 3D radius')
props4.Dimension_Change = False
props4.Dimension_Type = 'Radius'
props4.Dimension_width_or_location = 'location'
props4.Dimension_startlocation = startvertex
props4.Dimension_endlocation = endvertex
props4.Dimension_liberty = '3D'
props4.Dimension_rotation = 0
props4.Dimension_parent = obj.name
col = layout.column()
col.label(text="Diameter:")
row = layout.row()
props5 = row.operator("curve.dimension", text = 'Add linear diameter')
props5.Dimension_Change = False
props5.Dimension_Type = 'Diameter'
props5.Dimension_width_or_location = 'location'
props5.Dimension_startlocation = startvertex
props5.Dimension_endlocation = endvertex
props5.Dimension_liberty = '2D'
props5.Dimension_rotation = 0
props5.Dimension_parent = obj.name
props6 = row.operator("curve.dimension", text = 'Add 3D diameter')
props6.Dimension_Change = False
props6.Dimension_Type = 'Diameter'
props6.Dimension_width_or_location = 'location'
props6.Dimension_startlocation = startvertex
props6.Dimension_endlocation = endvertex
props6.Dimension_liberty = '3D'
props6.Dimension_rotation = 0
props6.Dimension_parent = obj.name
if len(vertex) == 3:
startvertex = vertex[0]
endvertex = vertex[1]
endanglevertex = vertex[2]
if endvertex[0] < startvertex[0]:
startvertex = vertex[1]
endvertex = vertex[0]
layout = self.layout
col = layout.column()
row = layout.row()
props1 = row.operator("curve.dimension", text = 'Add Linear angle dimension')
props1.Dimension_Change = False
props1.Dimension_Type = 'Angular1'
props1.Dimension_width_or_location = 'location'
props1.Dimension_startlocation = startvertex
props1.Dimension_endlocation = endvertex
props1.Dimension_endanglelocation = endanglevertex
props1.Dimension_liberty = '2D'
props1.Dimension_rotation = 0
props1.Dimension_parent = obj.name
props2 = row.operator("curve.dimension", text = 'Add 3D angle dimension')
props2.Dimension_Change = False
props2.Dimension_Type = 'Angular1'
props2.Dimension_width_or_location = 'location'
props2.Dimension_startlocation = startvertex
props2.Dimension_endlocation = endvertex
props2.Dimension_endanglelocation = endanglevertex
props2.Dimension_liberty = '3D'
props2.Dimension_rotation = 0
props2.Dimension_parent = obj.name
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
# Properties class
class DimensionPanel(bpy.types.Panel):
''''''
bl_idname = "OBJECT_PT_properties_dimension"
bl_label = "Dimension change"
bl_description = "Dimension change"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
@classmethod
def poll(cls, context):
if context.object.Dimension == True:
return (context.object)
##### DRAW #####
def draw(self, context):
if context.object.Dimension == True:
layout = self.layout
obj = context.object
row = layout.row()
props = row.operator("curve.dimension", text = 'Change')
props.Dimension_Change = True
props.Dimension_Delete = obj.name
props.Dimension_width_or_location = obj.Dimension_width_or_location
props.Dimension_startlocation = obj.location
props.Dimension_endlocation = obj.Dimension_endlocation
props.Dimension_endanglelocation = obj.Dimension_endanglelocation
props.Dimension_liberty = obj.Dimension_liberty
props.Dimension_Type = obj.Dimension_Type
props.Dimension_XYZType = obj.Dimension_XYZType
props.Dimension_XYType = obj.Dimension_XYType
props.Dimension_XZType = obj.Dimension_XZType
props.Dimension_YZType = obj.Dimension_YZType
props.Dimension_resolution = obj.Dimension_resolution
props.Dimension_width = obj.Dimension_width
props.Dimension_length = obj.Dimension_length
props.Dimension_dsize = obj.Dimension_dsize
props.Dimension_depth = obj.Dimension_depth
props.Dimension_depth_from_center = obj.Dimension_depth_from_center
props.Dimension_angle = obj.Dimension_angle
props.Dimension_rotation = obj.Dimension_rotation
cwolf3d@yandex.ru
committed
props.Dimension_offset = 0
props.Dimension_textsize = obj.Dimension_textsize
props.Dimension_textdepth = obj.Dimension_textdepth
props.Dimension_textround = obj.Dimension_textround
props.Dimension_font = obj.Dimension_font
props.Dimension_matname = obj.Dimension_matname
props.Dimension_note = obj.Dimension_note
props.Dimension_align_to_camera = obj.Dimension_align_to_camera
props.Dimension_arrow = obj.Dimension_arrow
props.Dimension_arrowdepth = obj.Dimension_arrowdepth
props.Dimension_arrowlength = obj.Dimension_arrowlength
props.Dimension_parent = obj.Dimension_parent
props.Dimension_appoint_parent = obj.Dimension_appoint_parent
cwolf3d@yandex.ru
committed
props.Dimension_units = obj.Dimension_units
props.Dimension_add_units_name = obj.Dimension_add_units_name
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
#location update
def StartLocationUpdate(self, context):
bpy.context.scene.cursor_location = self.Dimension_startlocation
return
# Add properties to objects
def DimensionVariables():
bpy.types.Object.Dimension = bpy.props.BoolProperty()
bpy.types.Object.Dimension_Change = bpy.props.BoolProperty()
bpy.types.Object.Dimension_Name = bpy.props.StringProperty(name = "Name",
description = "Name")
#### general properties
Types = [('Linear-1', 'Linear-1', 'Linear-1'),
('Linear-2', 'Linear-2', 'Linear-2'),
('Linear-3', 'Linear-3', 'Linear-3'),
('Radius', 'Radius', 'Radius'),
('Diameter', 'Diameter', 'Diameter'),
('Angular1', 'Angular1', 'Angular1'),
('Angular2', 'Angular2', 'Angular2'),
('Angular3', 'Angular3', 'Angular3'),
('Note', 'Note', 'Note')]
bpy.types.Object.Dimension_Type = bpy.props.EnumProperty(name = "Type",
description = "Form of Curve to create",
items = Types)
XYZTypes = [
('TOP', 'Top', 'TOP'),
('FRONT', 'Front', 'FRONT'),
('RIGHT', 'Right', 'RIGHT'),
('BOTTOM', 'Bottom', 'BOTTOM'),
('BACK', 'Back', 'BACK'),
('LEFT', 'Left', 'LEFT')]
bpy.types.Object.Dimension_XYZType = bpy.props.EnumProperty(name = "Coordinate system",
description = "Place in a coordinate system",
items = XYZTypes)
XYTypes = [
('X', 'X', 'X'),
('Y', 'Y', 'Y')]
bpy.types.Object.Dimension_XYType = bpy.props.EnumProperty(name = "XY",
description = "XY",
items = XYTypes)
XZTypes = [
('X', 'X', 'X'),
('Z', 'Z', 'Z')]
bpy.types.Object.Dimension_XZType = bpy.props.EnumProperty(name = "XZ",
description = "XZ",
items = XZTypes)
YZTypes = [
('Y', 'Y', 'Y'),
('Z', 'Z', 'Z')]
bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "YZ",
description = "YZ",
items = YZTypes)
bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "Coordinate system",
description = "Place in a coordinate system",
items = YZTypes)
bpy.types.Object.Dimension_startlocation = bpy.props.FloatVectorProperty(name = "Start location",
description = "",
subtype = 'XYZ',
update = StartLocationUpdate)
bpy.types.Object.Dimension_endlocation = bpy.props.FloatVectorProperty(name = "End location",
description = "",
subtype = 'XYZ')
bpy.types.Object.Dimension_endanglelocation = bpy.props.FloatVectorProperty(name = "End angle location",
description = "End angle location",
subtype = 'XYZ')
width_or_location_items = [
('width', 'width', 'width'),
('location', 'location', 'location')]
bpy.types.Object.Dimension_width_or_location = bpy.props.EnumProperty(name = "width or location",
items = width_or_location_items,
description = "width or location")
libertyItems = [
('2D', '2D', '2D'),
('3D', '3D', '3D')]
bpy.types.Object.Dimension_liberty = bpy.props.EnumProperty(name = "2D / 3D",
items = libertyItems,
description = "2D or 3D Dimension")
### Arrow
Arrows = [
('Arrow1', 'Arrow1', 'Arrow1'),
('Arrow2', 'Arrow2', 'Arrow2'),
('Serifs1', 'Serifs1', 'Serifs1'),
('Serifs2', 'Serifs2', 'Serifs2'),
('Without', 'Without', 'Without')]
bpy.types.Object.Dimension_arrow = bpy.props.EnumProperty(name = "Arrow",
items = Arrows,
description = "Arrow")
bpy.types.Object.Dimension_arrowdepth = bpy.props.FloatProperty(name = "Depth",
min = 0, soft_min = 0,
description = "Arrow depth")
bpy.types.Object.Dimension_arrowlength = bpy.props.FloatProperty(name = "Length",
min = 0, soft_min = 0,
description = "Arrow length")
#### Dimension properties
bpy.types.Object.Dimension_resolution = bpy.props.IntProperty(name = "Resolution",
min = 1, soft_min = 1,
description = "Resolution")
bpy.types.Object.Dimension_width = bpy.props.FloatProperty(name = "Width",
unit = 'LENGTH',
description = "Width")
bpy.types.Object.Dimension_length = bpy.props.FloatProperty(name = "Length",
description = "Length")
bpy.types.Object.Dimension_dsize = bpy.props.FloatProperty(name = "Size",
min = 0, soft_min = 0,
description = "Size")
bpy.types.Object.Dimension_depth = bpy.props.FloatProperty(name = "Depth",
min = 0, soft_min = 0,
description = "Depth")
bpy.types.Object.Dimension_depth_from_center = bpy.props.BoolProperty(name = "Depth from center",
description = "Depth from center")
bpy.types.Object.Dimension_angle = bpy.props.FloatProperty(name = "Angle",
description = "Angle")
bpy.types.Object.Dimension_rotation = bpy.props.FloatProperty(name = "Rotation",
description = "Rotation")
#### Dimension units properties
Units = [
('None', 'None', 'None'),
('\u00b5m', '\u00b5m', '\u00b5m'),
('mm', 'mm', 'mm'),
('cm', 'cm', 'cm'),
('m', 'm', 'm'),
('km', 'km', 'km'),
('thou', 'thou', 'thou'),
('"', '"', '"'),
('\'', '\'', '\''),
('yd', 'yd', 'yd'),
('mi', 'mi', 'mi')]
bpy.types.Object.Dimension_units = bpy.props.EnumProperty(name = "Units",
items = Units,
description = "Units")
cwolf3d@yandex.ru
committed
bpy.types.Object.Dimension_add_units_name = bpy.props.BoolProperty(name = "Add units name",
description = "Add units name")
bpy.types.Object.Dimension_offset = bpy.props.FloatProperty(name = "Offset",
description = "Offset")
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
#### Dimension text properties
bpy.types.Object.Dimension_textsize = bpy.props.FloatProperty(name = "Size",
description = "Size")
bpy.types.Object.Dimension_textdepth = bpy.props.FloatProperty(name = "Depth",
description = "Depth")
bpy.types.Object.Dimension_textround = bpy.props.IntProperty(name = "Rounding",
min = 0, soft_min = 0,
description = "Rounding")
bpy.types.Object.Dimension_font = bpy.props.StringProperty(name = "Font",
subtype = 'FILE_PATH',
description = "Font")
#### Materials properties
bpy.types.Object.Dimension_matname = bpy.props.StringProperty(name = "Name",
default = 'Dimension_Red',
description = "Material name")
#### Note text
bpy.types.Object.Dimension_note = bpy.props.StringProperty(name = "Note",
default = 'Note',
description = "Note text")
bpy.types.Object.Dimension_align_to_camera = bpy.props.BoolProperty(name = "Align to camera",
description = "Align to camera")
#### Parent
bpy.types.Object.Dimension_parent = bpy.props.StringProperty(name = "Parent",
default = '',
description = "Parent")
bpy.types.Object.Dimension_appoint_parent = bpy.props.BoolProperty(name = "Appoint parent",
description = "Appoint parent")
################################################################################
##### REGISTER #####
def Dimension_button(self, context):
oper = self.layout.operator(Dimension.bl_idname, text = "Dimension", icon = "PLUGIN")
oper.Dimension_Change = False
oper.Dimension_width_or_location = 'width'
oper.Dimension_liberty = '2D'
def register():
bpy.utils.register_module(__name__)
Brecht Van Lommel
committed
bpy.types.VIEW3D_MT_curve_add.append(Dimension_button)
DimensionVariables()
def unregister():
bpy.utils.unregister_module(__name__)
Brecht Van Lommel
committed
bpy.types.VIEW3D_MT_curve_add.remove(Dimension_button)
if __name__ == "__main__":
register()