1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ----------------------------------------------------------
6 # Author: Antonio Vazquez (antonioya)
7 # ----------------------------------------------------------
9 # ----------------------------------------------
11 # ----------------------------------------------
14 "author": "Antonio Vazquez (antonioya)",
15 "location": "View3D > Sidebar > View Tab",
18 "description": "Tools for measuring objects.",
19 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/measureit.html",
24 # ----------------------------------------------
26 # ----------------------------------------------
30 importlib
.reload(measureit_main
)
31 # print("measureit: Reloaded multifiles")
33 from . import measureit_main
34 # print("measureit: Imported multifiles")
36 # noinspection PyUnresolvedReferences
38 from bpy
.types
import (
43 from bpy
.props
import (
52 # --------------------------------------------------------------
53 # Register all operators and panels
54 # --------------------------------------------------------------
56 # Add-ons Preferences Update Panel
58 # Define Panel classes for updating
60 measureit_main
.MEASUREIT_PT_Edit
,
61 measureit_main
.MEASUREIT_PT_Main
,
62 measureit_main
.MEASUREIT_PT_Conf
,
63 measureit_main
.MEASUREIT_PT_Render
,
67 def update_panel(self
, context
):
68 message
= "MeasureIt: Updating Panel locations has failed"
71 if "bl_rna" in panel
.__dict
__:
72 bpy
.utils
.unregister_class(panel
)
75 panel
.bl_category
= context
.preferences
.addons
[__name__
].preferences
.category
76 bpy
.utils
.register_class(panel
)
78 except Exception as e
:
79 print("\n[{}]\n{}\n\nError:\n{}".format(__name__
, message
, e
))
83 class Measure_Pref(AddonPreferences
):
84 # this must match the addon name, use '__package__'
85 # when defining this in a submodule of a python package.
88 category
: StringProperty(
90 description
="Choose a name for the category of the panel",
95 def draw(self
, context
):
100 col
.label(text
="Tab Category:")
101 col
.prop(self
, "category", text
="")
105 # noinspection PyUnusedLocal
107 measureit_main
.MEASUREIT_OT_RunHintDisplay
,
108 measureit_main
.MEASUREIT_OT_AddSegment
,
109 measureit_main
.MEASUREIT_OT_AddArea
,
110 measureit_main
.MEASUREIT_OT_AddSegmentOrto
,
111 measureit_main
.MEASUREIT_OT_AddAngle
,
112 measureit_main
.MEASUREIT_OT_AddArc
,
113 measureit_main
.MEASUREIT_OT_AddLabel
,
114 measureit_main
.MEASUREIT_OT_AddNote
,
115 measureit_main
.MEASUREIT_OT_AddLink
,
116 measureit_main
.MEASUREIT_OT_AddOrigin
,
117 measureit_main
.MEASUREIT_OT_DeleteSegment
,
118 measureit_main
.MEASUREIT_OT_DeleteAllSegment
,
119 measureit_main
.MEASUREIT_OT_DeleteAllSum
,
120 measureit_main
.MEASUREIT_OT_RenderSegment
,
121 measureit_main
.MEASUREIT_OT_ExpandAllSegment
,
122 measureit_main
.MEASUREIT_OT_CollapseAllSegment
,
123 measureit_main
.MEASUREIT_PT_Main
,
124 measureit_main
.MEASUREIT_PT_Edit
,
125 measureit_main
.MEASUREIT_PT_Conf
,
126 measureit_main
.MEASUREIT_PT_Render
,
131 from bpy
.utils
import register_class
136 Scene
.measureit_default_color
= FloatVectorProperty(
137 name
="Default color",
138 description
="Default Color",
139 default
=(0.173, 0.545, 1.0, 1.0),
144 Scene
.measureit_font_size
= IntProperty(name
="Text Size",
145 description
="Default text size",
146 default
=14, min=10, max=150)
147 Scene
.measureit_hint_space
= FloatProperty(name
='Separation', min=0, max=100, default
=0.1,
149 description
="Default distance to display measure")
150 Scene
.measureit_gl_ghost
= BoolProperty(name
="All",
151 description
="Display measures for all objects,"
152 " not only selected",
154 Scene
.measureit_gl_txt
= StringProperty(name
="Text", maxlen
=256,
155 description
="Short description (use | for line break)")
157 Scene
.measureit_gl_precision
= IntProperty(name
='Precision', min=0, max=5, default
=2,
158 description
="Number of decimal precision")
159 Scene
.measureit_gl_show_d
= BoolProperty(name
="ShowDist",
160 description
="Display distances",
162 Scene
.measureit_gl_show_n
= BoolProperty(name
="ShowName",
163 description
="Display texts",
165 Scene
.measureit_scale
= BoolProperty(name
="Scale",
166 description
="Use scale factor",
168 Scene
.measureit_scale_factor
= FloatProperty(name
='Factor', min=0.001, max=9999999,
171 description
="Scale factor 1:x")
172 Scene
.measureit_scale_color
= FloatVectorProperty(name
="Scale color",
173 description
="Scale Color",
174 default
=(1, 1, 0, 1.0),
179 Scene
.measureit_scale_font
= IntProperty(name
="Font",
180 description
="Text size",
181 default
=14, min=10, max=150)
182 Scene
.measureit_scale_pos_x
= IntProperty(name
="X Position",
183 description
="Margin on the X axis",
187 Scene
.measureit_scale_pos_y
= IntProperty(name
="Y Position",
188 description
="Margin on the Y axis",
192 Scene
.measureit_gl_scaletxt
= StringProperty(name
="ScaleText", maxlen
=48,
193 description
="Scale title",
195 Scene
.measureit_scale_precision
= IntProperty(name
='Precision', min=0, max=5, default
=0,
196 description
="Number of decimal precision")
197 Scene
.measureit_ovr
= BoolProperty(name
="Override",
198 description
="Override colors and fonts",
200 Scene
.measureit_ovr_font
= IntProperty(name
="Font",
201 description
="Override text size",
202 default
=14, min=10, max=150)
203 Scene
.measureit_ovr_color
= FloatVectorProperty(name
="Override color",
204 description
="Override Color",
205 default
=(1, 0, 0, 1.0),
210 Scene
.measureit_ovr_width
= IntProperty(name
='Override width', min=1, max=10, default
=1,
211 description
='override line width')
213 Scene
.measureit_ovr_font_rotation
= IntProperty(name
='Rotate', min=0, max=360, default
=0,
214 description
="Text rotation in degrees")
215 Scene
.measureit_ovr_font_align
= EnumProperty(items
=(('L', "Left Align", "Use current render"),
216 ('C', "Center Align", ""),
217 ('R', "Right Align", "")),
219 description
="Set Font Alignment")
220 Scene
.measureit_units
= EnumProperty(items
=(('1', "Automatic", "Use scene units"),
222 ('3', "Centimeters", ""),
223 ('4', "Millimeters", ""),
225 ('6', "Inches", "")),
229 Scene
.measureit_hide_units
= BoolProperty(name
="hide_units",
230 description
="Do not display unit of measurement on viewport",
232 Scene
.measureit_render
= BoolProperty(name
="Render",
233 description
="Save an image with measures over"
236 Scene
.measureit_render_type
= EnumProperty(items
=(('1', "Frame", "Render current frame"),
237 ('2', "Animation", "")),
239 description
="Type of render image")
240 Scene
.measureit_sum
= EnumProperty(items
=(('99', "-", "Select a group for sum"),
268 description
="Add segment length in selected group")
270 Scene
.measureit_rf
= BoolProperty(name
="render_frame",
271 description
="Add a frame in render output",
273 Scene
.measureit_rf_color
= FloatVectorProperty(name
="Fcolor",
274 description
="Frame Color",
275 default
=(0.9, 0.9, 0.9, 1.0),
280 Scene
.measureit_rf_border
= IntProperty(name
='fborder ', min=1, max=1000, default
=10,
281 description
='Frame space from border')
282 Scene
.measureit_rf_line
= IntProperty(name
='fline', min=1, max=10, default
=1,
283 description
='Line width for border')
285 Scene
.measureit_glarrow_a
= EnumProperty(items
=(('99', "--", "No arrow"),
287 "The point of the arrow are lines"),
289 "The point of the arrow is triangle"),
291 "The point of the arrow is a T")),
293 description
="Add arrows to point A")
294 Scene
.measureit_glarrow_b
= EnumProperty(items
=(('99', "--", "No arrow"),
296 "The point of the arrow are lines"),
298 "The point of the arrow is triangle"),
300 "The point of the arrow is a T")),
302 description
="Add arrows to point B")
303 Scene
.measureit_glarrow_s
= IntProperty(name
="Size",
304 description
="Arrow size",
305 default
=15, min=6, max=500)
307 Scene
.measureit_debug
= BoolProperty(name
="Debug",
308 description
="Display information for debugging"
309 " (expand/collapse for enabling or disabling)"
310 " this information is only rendered for "
313 Scene
.measureit_debug_select
= BoolProperty(name
="Selected",
314 description
="Display information "
315 "only for selected items",
317 Scene
.measureit_debug_vertices
= BoolProperty(name
="Vertices",
318 description
="Display vertex index number",
320 Scene
.measureit_debug_objects
= BoolProperty(name
="Objects",
321 description
="Display object scene index number",
323 Scene
.measureit_debug_vert_loc
= BoolProperty(name
="Location",
324 description
="Display vertex location",
326 Scene
.measureit_debug_object_loc
= BoolProperty(name
="Location",
327 description
="Display object location",
329 Scene
.measureit_debug_edges
= BoolProperty(name
="Edges",
330 description
="Display edge index number",
332 Scene
.measureit_debug_faces
= BoolProperty(name
="Faces",
333 description
="Display face index number",
335 Scene
.measureit_debug_normals
= BoolProperty(name
="Normals",
336 description
="Display face normal "
337 "vector and creation order",
339 Scene
.measureit_debug_normal_details
= BoolProperty(name
="Details",
340 description
="Display face normal details",
342 Scene
.measureit_debug_font
= IntProperty(name
="Font",
343 description
="Debug text size",
344 default
=14, min=10, max=150)
345 Scene
.measureit_debug_vert_color
= FloatVectorProperty(name
="Debug color",
346 description
="Debug Color",
347 default
=(1, 0, 0, 1.0),
352 Scene
.measureit_debug_face_color
= FloatVectorProperty(name
="Debug face color",
353 description
="Debug face Color",
354 default
=(0, 1, 0, 1.0),
359 Scene
.measureit_debug_norm_color
= FloatVectorProperty(name
="Debug vector color",
360 description
="Debug vector Color",
361 default
=(1.0, 1.0, 0.1, 1.0),
366 Scene
.measureit_debug_edge_color
= FloatVectorProperty(name
="Debug vector color",
367 description
="Debug vector Color",
368 default
=(0.1, 1.0, 1.0, 1.0),
373 Scene
.measureit_debug_obj_color
= FloatVectorProperty(name
="Debug vector color",
374 description
="Debug vector Color",
375 default
=(1.0, 1.0, 1.0, 1.0),
380 Scene
.measureit_debug_normal_size
= FloatProperty(name
='Len', min=0.001, max=9,
383 description
="Normal arrow size")
384 Scene
.measureit_debug_width
= IntProperty(name
='Debug width', min=1, max=10, default
=2,
385 description
='Vector line thickness')
386 Scene
.measureit_debug_precision
= IntProperty(name
='Precision', min=0, max=5, default
=1,
387 description
="Number of decimal precision")
388 Scene
.measureit_debug_vert_loc_toggle
= EnumProperty(items
=(('1', "Local",
389 "Uses local coordinates"),
391 "Uses global coordinates")),
393 description
="Choose coordinate system")
394 Scene
.measureit_font_rotation
= IntProperty(name
='Rotate', min=0, max=360, default
=0,
395 description
="Default text rotation in degrees")
396 Scene
.measureit_font_align
= EnumProperty(items
=(('L', "Left Align", "Use current render"),
397 ('C', "Center Align", ""),
398 ('R', "Right Align", "")),
400 description
="Set Font Alignment")
404 # register internal property
405 wm
.measureit_run_opengl
= BoolProperty(default
=False)
409 from bpy
.utils
import unregister_class
410 for cls
in reversed(classes
):
411 unregister_class(cls
)
414 del Scene
.measureit_default_color
415 del Scene
.measureit_font_size
416 del Scene
.measureit_hint_space
417 del Scene
.measureit_gl_ghost
418 del Scene
.measureit_gl_txt
419 del Scene
.measureit_gl_precision
420 del Scene
.measureit_gl_show_d
421 del Scene
.measureit_gl_show_n
422 del Scene
.measureit_scale
423 del Scene
.measureit_scale_factor
424 del Scene
.measureit_scale_color
425 del Scene
.measureit_scale_font
426 del Scene
.measureit_scale_pos_x
427 del Scene
.measureit_scale_pos_y
428 del Scene
.measureit_gl_scaletxt
429 del Scene
.measureit_scale_precision
430 del Scene
.measureit_ovr
431 del Scene
.measureit_ovr_font
432 del Scene
.measureit_ovr_color
433 del Scene
.measureit_ovr_width
434 del Scene
.measureit_ovr_font_rotation
435 del Scene
.measureit_ovr_font_align
436 del Scene
.measureit_units
437 del Scene
.measureit_hide_units
438 del Scene
.measureit_render
439 del Scene
.measureit_render_type
440 del Scene
.measureit_sum
441 del Scene
.measureit_rf
442 del Scene
.measureit_rf_color
443 del Scene
.measureit_rf_border
444 del Scene
.measureit_rf_line
445 del Scene
.measureit_glarrow_a
446 del Scene
.measureit_glarrow_b
447 del Scene
.measureit_glarrow_s
448 del Scene
.measureit_debug
449 del Scene
.measureit_debug_select
450 del Scene
.measureit_debug_vertices
451 del Scene
.measureit_debug_objects
452 del Scene
.measureit_debug_edges
453 del Scene
.measureit_debug_faces
454 del Scene
.measureit_debug_normals
455 del Scene
.measureit_debug_normal_details
456 del Scene
.measureit_debug_font
457 del Scene
.measureit_debug_vert_color
458 del Scene
.measureit_debug_face_color
459 del Scene
.measureit_debug_norm_color
460 del Scene
.measureit_debug_edge_color
461 del Scene
.measureit_debug_obj_color
462 del Scene
.measureit_debug_normal_size
463 del Scene
.measureit_debug_width
464 del Scene
.measureit_debug_precision
465 del Scene
.measureit_debug_vert_loc
466 del Scene
.measureit_debug_object_loc
467 del Scene
.measureit_debug_vert_loc_toggle
468 del Scene
.measureit_font_rotation
469 del Scene
.measureit_font_align
472 measureit_main
.MEASUREIT_OT_RunHintDisplay
.handle_remove(measureit_main
.MEASUREIT_OT_RunHintDisplay
, bpy
.context
)
473 wm
= bpy
.context
.window_manager
474 p
= 'measureit_run_opengl'
479 if __name__
== '__main__':