Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2016-08-09 17:25:28 +0300
committerAntonioya <blendergit@gmail.com>2016-08-09 17:25:28 +0300
commit53e4e3c39dd04bfcf0ed42666b9883bdd52ff558 (patch)
tree62012fbd82389ea9ab004050af0d7d3894c903a0 /measureit
parentf476cfdd3149e75d7ee40887230339b927d52da9 (diff)
MeasureIt: Cleanup - Replace generic import
Diffstat (limited to 'measureit')
-rw-r--r--measureit/__init__.py188
-rw-r--r--measureit/measureit_geometry.py122
-rw-r--r--measureit/measureit_main.py179
-rw-r--r--measureit/measureit_render.py32
4 files changed, 257 insertions, 264 deletions
diff --git a/measureit/__init__.py b/measureit/__init__.py
index 6513dfcf..93e97c5b 100644
--- a/measureit/__init__.py
+++ b/measureit/__init__.py
@@ -55,8 +55,8 @@ else:
# noinspection PyUnresolvedReferences
import bpy
-# noinspection PyUnresolvedReferences
-from bpy.props import *
+from bpy.types import Scene, WindowManager
+from bpy.props import FloatVectorProperty, IntProperty, BoolProperty, StringProperty, FloatProperty, EnumProperty
# --------------------------------------------------------------
@@ -83,7 +83,7 @@ def register():
bpy.utils.register_class(measureit_main.RenderSegmentButton)
# Define properties
- bpy.types.Scene.measureit_default_color = bpy.props.FloatVectorProperty(
+ Scene.measureit_default_color = FloatVectorProperty(
name="Default color",
description="Default Color",
default=(0.173, 0.545, 1.0, 1.0),
@@ -91,77 +91,77 @@ def register():
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_font_size = bpy.props.IntProperty(name="Text Size",
+ Scene.measureit_font_size = IntProperty(name="Text Size",
description="Default text size",
default=14, min=10, max=150)
- bpy.types.Scene.measureit_hint_space = bpy.props.FloatProperty(name='Separation', min=0, max=100, default=0.1,
+ Scene.measureit_hint_space = FloatProperty(name='Separation', min=0, max=100, default=0.1,
precision=3,
description="Default distance to display measure")
- bpy.types.Scene.measureit_gl_ghost = bpy.props.BoolProperty(name="All",
+ Scene.measureit_gl_ghost = BoolProperty(name="All",
description="Display measures for all objects,"
" not only selected",
default=True)
- bpy.types.Scene.measureit_gl_txt = bpy.props.StringProperty(name="Text", maxlen=256,
+ Scene.measureit_gl_txt = StringProperty(name="Text", maxlen=256,
description="Short description (use | for line break)")
- bpy.types.Scene.measureit_gl_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=2,
+ Scene.measureit_gl_precision = IntProperty(name='Precision', min=0, max=5, default=2,
description="Number of decimal precision")
- bpy.types.Scene.measureit_gl_show_d = bpy.props.BoolProperty(name="ShowDist",
+ Scene.measureit_gl_show_d = BoolProperty(name="ShowDist",
description="Display distances",
default=True)
- bpy.types.Scene.measureit_gl_show_n = bpy.props.BoolProperty(name="ShowName",
+ Scene.measureit_gl_show_n = BoolProperty(name="ShowName",
description="Display texts",
default=False)
- bpy.types.Scene.measureit_scale = bpy.props.BoolProperty(name="Scale",
+ Scene.measureit_scale = BoolProperty(name="Scale",
description="Use scale factor",
default=False)
- bpy.types.Scene.measureit_scale_factor = bpy.props.FloatProperty(name='Factor', min=0.001, max=9999999,
+ Scene.measureit_scale_factor = FloatProperty(name='Factor', min=0.001, max=9999999,
default=1.0,
precision=3,
description="Scale factor 1:x")
- bpy.types.Scene.measureit_scale_color = bpy.props.FloatVectorProperty(name="Scale color",
+ Scene.measureit_scale_color = FloatVectorProperty(name="Scale color",
description="Scale Color",
default=(1, 1, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_scale_font = bpy.props.IntProperty(name="Font",
+ Scene.measureit_scale_font = IntProperty(name="Font",
description="Text size",
default=14, min=10, max=150)
- bpy.types.Scene.measureit_scale_pos_x = bpy.props.IntProperty(name="Position X",
+ Scene.measureit_scale_pos_x = IntProperty(name="Position X",
description="Margin on the X axis",
default=5,
min=0,
max=100)
- bpy.types.Scene.measureit_scale_pos_y = bpy.props.IntProperty(name="Position Y",
+ Scene.measureit_scale_pos_y = IntProperty(name="Position Y",
description="Margin on the Y axis",
default=5,
min=0,
max=100)
- bpy.types.Scene.measureit_gl_scaletxt = bpy.props.StringProperty(name="ScaleText", maxlen=48,
+ Scene.measureit_gl_scaletxt = StringProperty(name="ScaleText", maxlen=48,
description="Scale title",
default="Scale:")
- bpy.types.Scene.measureit_scale_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=0,
+ Scene.measureit_scale_precision = IntProperty(name='Precision', min=0, max=5, default=0,
description="Number of decimal precision")
- bpy.types.Scene.measureit_ovr = bpy.props.BoolProperty(name="Override",
+ Scene.measureit_ovr = BoolProperty(name="Override",
description="Override colors and fonts",
default=False)
- bpy.types.Scene.measureit_ovr_font = bpy.props.IntProperty(name="Font",
+ Scene.measureit_ovr_font = IntProperty(name="Font",
description="Override text size",
default=14, min=10, max=150)
- bpy.types.Scene.measureit_ovr_color = bpy.props.FloatVectorProperty(name="Override color",
+ Scene.measureit_ovr_color = FloatVectorProperty(name="Override color",
description="Override Color",
default=(1, 0, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_ovr_width = bpy.props.IntProperty(name='Override width', min=1, max=10, default=1,
+ Scene.measureit_ovr_width = IntProperty(name='Override width', min=1, max=10, default=1,
description='override line width')
- bpy.types.Scene.measureit_units = bpy.props.EnumProperty(items=(('1', "Automatic", "Use scene units"),
+ Scene.measureit_units = EnumProperty(items=(('1', "Automatic", "Use scene units"),
('2', "Meters", ""),
('3', "Centimeters", ""),
('4', "Milimiters", ""),
@@ -170,18 +170,18 @@ def register():
name="Units",
default="2",
description="Units")
- bpy.types.Scene.measureit_render = bpy.props.BoolProperty(name="Render",
+ Scene.measureit_render = BoolProperty(name="Render",
description="Save an image with measures over"
" render image",
default=False)
- bpy.types.Scene.measureit_render_type = bpy.props.EnumProperty(items=(('1', "*Current", "Use current render"),
+ Scene.measureit_render_type = EnumProperty(items=(('1', "*Current", "Use current render"),
('2', "OpenGL", ""),
('3', "Animation OpenGL", ""),
('4', "Image", ""),
('5', "Animation", "")),
name="Render type",
description="Type of render image")
- bpy.types.Scene.measureit_sum = bpy.props.EnumProperty(items=(('99', "-", "Select a group for sum"),
+ Scene.measureit_sum = EnumProperty(items=(('99', "-", "Select a group for sum"),
('0', "A", ""),
('1', "B", ""),
('2', "C", ""),
@@ -211,22 +211,22 @@ def register():
name="Sum in Group",
description="Add segment length in selected group")
- bpy.types.Scene.measureit_rf = bpy.props.BoolProperty(name="render_frame",
+ Scene.measureit_rf = BoolProperty(name="render_frame",
description="Add a frame in render output",
default=False)
- bpy.types.Scene.measureit_rf_color = bpy.props.FloatVectorProperty(name="Fcolor",
+ Scene.measureit_rf_color = FloatVectorProperty(name="Fcolor",
description="Frame Color",
default=(0.9, 0.9, 0.9, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_rf_border = bpy.props.IntProperty(name='fborder ', min=1, max=1000, default=10,
+ Scene.measureit_rf_border = IntProperty(name='fborder ', min=1, max=1000, default=10,
description='Frame space from border')
- bpy.types.Scene.measureit_rf_line = bpy.props.IntProperty(name='fline', min=1, max=10, default=1,
+ Scene.measureit_rf_line = IntProperty(name='fline', min=1, max=10, default=1,
description='Line width for border')
- bpy.types.Scene.measureit_glarrow_a = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ Scene.measureit_glarrow_a = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line",
"The point of the arrow are lines"),
('2', "Triangle",
@@ -235,7 +235,7 @@ def register():
"The point of the arrow is a T")),
name="A end",
description="Add arrows to point A")
- bpy.types.Scene.measureit_glarrow_b = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ Scene.measureit_glarrow_b = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line",
"The point of the arrow are lines"),
('2', "Triangle",
@@ -244,73 +244,73 @@ def register():
"The point of the arrow is a T")),
name="B end",
description="Add arrows to point B")
- bpy.types.Scene.measureit_glarrow_s = bpy.props.IntProperty(name="Size",
+ Scene.measureit_glarrow_s = IntProperty(name="Size",
description="Arrow size",
default=15, min=6, max=500)
- bpy.types.Scene.measureit_debug = bpy.props.BoolProperty(name="Debug",
+ Scene.measureit_debug = BoolProperty(name="Debug",
description="Display information for debuging"
" (expand/collapse for enabling or disabling)"
" this information is only renderered for "
"selected objects",
default=False)
- bpy.types.Scene.measureit_debug_select = bpy.props.BoolProperty(name="Selected",
+ Scene.measureit_debug_select = BoolProperty(name="Selected",
description="Display information "
"for selected vertices/faces",
default=False)
- bpy.types.Scene.measureit_debug_vertices = bpy.props.BoolProperty(name="Vertices",
+ Scene.measureit_debug_vertices = BoolProperty(name="Vertices",
description="Display vertex number",
default=True)
- bpy.types.Scene.measureit_debug_location = bpy.props.BoolProperty(name="Location",
+ Scene.measureit_debug_location = BoolProperty(name="Location",
description="Display vertex location",
default=False)
- bpy.types.Scene.measureit_debug_faces = bpy.props.BoolProperty(name="Faces",
+ Scene.measureit_debug_faces = BoolProperty(name="Faces",
description="Display face number",
default=False)
- bpy.types.Scene.measureit_debug_normals = bpy.props.BoolProperty(name="Normals",
+ Scene.measureit_debug_normals = BoolProperty(name="Normals",
description="Display face normal "
"vector and creation order",
default=False)
- bpy.types.Scene.measureit_debug_normal_details = bpy.props.BoolProperty(name="Details",
+ Scene.measureit_debug_normal_details = BoolProperty(name="Details",
description="Display face normal details",
default=True)
- bpy.types.Scene.measureit_debug_font = bpy.props.IntProperty(name="Font",
+ Scene.measureit_debug_font = IntProperty(name="Font",
description="Debug text size",
default=14, min=10, max=150)
- bpy.types.Scene.measureit_debug_color = bpy.props.FloatVectorProperty(name="Debug color",
+ Scene.measureit_debug_color = FloatVectorProperty(name="Debug color",
description="Debug Color",
default=(1, 0, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_debug_color2 = bpy.props.FloatVectorProperty(name="Debug face color",
+ Scene.measureit_debug_color2 = FloatVectorProperty(name="Debug face color",
description="Debug face Color",
default=(0, 1, 0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_debug_color3 = bpy.props.FloatVectorProperty(name="Debug vector color",
+ Scene.measureit_debug_color3 = FloatVectorProperty(name="Debug vector color",
description="Debug vector Color",
default=(1.0, 1.0, 0.1, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- bpy.types.Scene.measureit_debug_normal_size = bpy.props.FloatProperty(name='Len', min=0.001, max=9,
+ Scene.measureit_debug_normal_size = FloatProperty(name='Len', min=0.001, max=9,
default=0.5,
precision=2,
description="Normal arrow size")
- bpy.types.Scene.measureit_debug_width = bpy.props.IntProperty(name='Debug width', min=1, max=10, default=2,
+ Scene.measureit_debug_width = IntProperty(name='Debug width', min=1, max=10, default=2,
description='Vector line thickness')
- bpy.types.Scene.measureit_debug_precision = bpy.props.IntProperty(name='Precision', min=0, max=5, default=1,
+ Scene.measureit_debug_precision = IntProperty(name='Precision', min=0, max=5, default=1,
description="Number of decimal precision")
# OpenGL flag
- wm = bpy.types.WindowManager
+ wm = WindowManager
# register internal property
- wm.measureit_run_opengl = bpy.props.BoolProperty(default=False)
+ wm.measureit_run_opengl = BoolProperty(default=False)
def unregister():
@@ -334,51 +334,51 @@ def unregister():
bpy.utils.unregister_class(measureit_main.RenderSegmentButton)
# Remove properties
- del bpy.types.Scene.measureit_default_color
- del bpy.types.Scene.measureit_font_size
- del bpy.types.Scene.measureit_hint_space
- del bpy.types.Scene.measureit_gl_ghost
- del bpy.types.Scene.measureit_gl_txt
- del bpy.types.Scene.measureit_gl_precision
- del bpy.types.Scene.measureit_gl_show_d
- del bpy.types.Scene.measureit_gl_show_n
- del bpy.types.Scene.measureit_scale
- del bpy.types.Scene.measureit_scale_factor
- del bpy.types.Scene.measureit_scale_color
- del bpy.types.Scene.measureit_scale_font
- del bpy.types.Scene.measureit_scale_pos_x
- del bpy.types.Scene.measureit_scale_pos_y
- del bpy.types.Scene.measureit_gl_scaletxt
- del bpy.types.Scene.measureit_scale_precision
- del bpy.types.Scene.measureit_ovr
- del bpy.types.Scene.measureit_ovr_font
- del bpy.types.Scene.measureit_ovr_color
- del bpy.types.Scene.measureit_ovr_width
- del bpy.types.Scene.measureit_units
- del bpy.types.Scene.measureit_render
- del bpy.types.Scene.measureit_render_type
- del bpy.types.Scene.measureit_sum
- del bpy.types.Scene.measureit_rf
- del bpy.types.Scene.measureit_rf_color
- del bpy.types.Scene.measureit_rf_border
- del bpy.types.Scene.measureit_rf_line
- del bpy.types.Scene.measureit_glarrow_a
- del bpy.types.Scene.measureit_glarrow_b
- del bpy.types.Scene.measureit_glarrow_s
- del bpy.types.Scene.measureit_debug
- del bpy.types.Scene.measureit_debug_select
- del bpy.types.Scene.measureit_debug_vertices
- del bpy.types.Scene.measureit_debug_faces
- del bpy.types.Scene.measureit_debug_normals
- del bpy.types.Scene.measureit_debug_normal_details
- del bpy.types.Scene.measureit_debug_font
- del bpy.types.Scene.measureit_debug_color
- del bpy.types.Scene.measureit_debug_color2
- del bpy.types.Scene.measureit_debug_color3
- del bpy.types.Scene.measureit_debug_normal_size
- del bpy.types.Scene.measureit_debug_width
- del bpy.types.Scene.measureit_debug_precision
- del bpy.types.Scene.measureit_debug_location
+ del Scene.measureit_default_color
+ del Scene.measureit_font_size
+ del Scene.measureit_hint_space
+ del Scene.measureit_gl_ghost
+ del Scene.measureit_gl_txt
+ del Scene.measureit_gl_precision
+ del Scene.measureit_gl_show_d
+ del Scene.measureit_gl_show_n
+ del Scene.measureit_scale
+ del Scene.measureit_scale_factor
+ del Scene.measureit_scale_color
+ del Scene.measureit_scale_font
+ del Scene.measureit_scale_pos_x
+ del Scene.measureit_scale_pos_y
+ del Scene.measureit_gl_scaletxt
+ del Scene.measureit_scale_precision
+ del Scene.measureit_ovr
+ del Scene.measureit_ovr_font
+ del Scene.measureit_ovr_color
+ del Scene.measureit_ovr_width
+ del Scene.measureit_units
+ del Scene.measureit_render
+ del Scene.measureit_render_type
+ del Scene.measureit_sum
+ del Scene.measureit_rf
+ del Scene.measureit_rf_color
+ del Scene.measureit_rf_border
+ del Scene.measureit_rf_line
+ del Scene.measureit_glarrow_a
+ del Scene.measureit_glarrow_b
+ del Scene.measureit_glarrow_s
+ del Scene.measureit_debug
+ del Scene.measureit_debug_select
+ del Scene.measureit_debug_vertices
+ del Scene.measureit_debug_faces
+ del Scene.measureit_debug_normals
+ del Scene.measureit_debug_normal_details
+ del Scene.measureit_debug_font
+ del Scene.measureit_debug_color
+ del Scene.measureit_debug_color2
+ del Scene.measureit_debug_color3
+ del Scene.measureit_debug_normal_size
+ del Scene.measureit_debug_width
+ del Scene.measureit_debug_precision
+ del Scene.measureit_debug_location
# remove OpenGL data
measureit_main.RunHintDisplayButton.handle_remove(measureit_main.RunHintDisplayButton, bpy.context)
diff --git a/measureit/measureit_geometry.py b/measureit/measureit_geometry.py
index c8c6170d..7f4032ee 100644
--- a/measureit/measureit_geometry.py
+++ b/measureit/measureit_geometry.py
@@ -29,16 +29,12 @@ import bpy
import bgl
# noinspection PyUnresolvedReferences
import blf
-import math
-# noinspection PyUnresolvedReferences
-import mathutils
-# noinspection PyUnresolvedReferences
-import bmesh
-# noinspection PyUnresolvedReferences
+from math import fabs, degrees, radians, sqrt, cos, sin, pi
+from mathutils import Vector, Matrix
+from bmesh import from_edit_mesh
from bpy_extras import view3d_utils, mesh_utils
-# noinspection PyUnresolvedReferences
import bpy_extras.object_utils as object_utils
-import sys
+from sys import exc_info
# -------------------------------------------------------------
@@ -173,8 +169,8 @@ def draw_segments(context, myobj, op, region, rv3d):
an_p2 = get_point(obverts[ms.glpointb].co, myobj)
an_p3 = get_point(obverts[ms.glpointc].co, myobj)
- ang_1 = mathutils.Vector((an_p1[0] - an_p2[0], an_p1[1] - an_p2[1], an_p1[2] - an_p2[2]))
- ang_2 = mathutils.Vector((an_p3[0] - an_p2[0], an_p3[1] - an_p2[1], an_p3[2] - an_p2[2]))
+ ang_1 = Vector((an_p1[0] - an_p2[0], an_p1[1] - an_p2[1], an_p1[2] - an_p2[2]))
+ ang_2 = Vector((an_p3[0] - an_p2[0], an_p3[1] - an_p2[1], an_p3[2] - an_p2[2]))
ang_3 = ang_1 + ang_2 # Result vector
@@ -197,12 +193,12 @@ def draw_segments(context, myobj, op, region, rv3d):
an_p2 = get_point(obverts[ms.glpointb].co, myobj)
an_p3 = get_point(obverts[ms.glpointc].co, myobj)
# reference for maths: http://en.wikipedia.org/wiki/Circumscribed_circle
- an_p12 = mathutils.Vector((an_p1[0] - an_p2[0], an_p1[1] - an_p2[1], an_p1[2] - an_p2[2]))
- an_p13 = mathutils.Vector((an_p1[0] - an_p3[0], an_p1[1] - an_p3[1], an_p1[2] - an_p3[2]))
- an_p21 = mathutils.Vector((an_p2[0] - an_p1[0], an_p2[1] - an_p1[1], an_p2[2] - an_p1[2]))
- an_p23 = mathutils.Vector((an_p2[0] - an_p3[0], an_p2[1] - an_p3[1], an_p2[2] - an_p3[2]))
- an_p31 = mathutils.Vector((an_p3[0] - an_p1[0], an_p3[1] - an_p1[1], an_p3[2] - an_p1[2]))
- an_p32 = mathutils.Vector((an_p3[0] - an_p2[0], an_p3[1] - an_p2[1], an_p3[2] - an_p2[2]))
+ an_p12 = Vector((an_p1[0] - an_p2[0], an_p1[1] - an_p2[1], an_p1[2] - an_p2[2]))
+ an_p13 = Vector((an_p1[0] - an_p3[0], an_p1[1] - an_p3[1], an_p1[2] - an_p3[2]))
+ an_p21 = Vector((an_p2[0] - an_p1[0], an_p2[1] - an_p1[1], an_p2[2] - an_p1[2]))
+ an_p23 = Vector((an_p2[0] - an_p3[0], an_p2[1] - an_p3[1], an_p2[2] - an_p3[2]))
+ an_p31 = Vector((an_p3[0] - an_p1[0], an_p3[1] - an_p1[1], an_p3[2] - an_p1[2]))
+ an_p32 = Vector((an_p3[0] - an_p2[0], an_p3[1] - an_p2[1], an_p3[2] - an_p2[2]))
an_p12xp23 = an_p12.copy().cross(an_p23)
# radius = an_p12.length * an_p23.length * an_p31.length / (2 * an_p12xp23.length)
@@ -241,12 +237,12 @@ def draw_segments(context, myobj, op, region, rv3d):
vn = a_n # if arc, vector is perpendicular to surface of the three vertices
else:
loc = get_location(myobj)
- midpoint3d = interpolate3d(a_p1, b_p1, math.fabs(dist / 2))
- vn = mathutils.Vector((midpoint3d[0] - loc[0],
+ midpoint3d = interpolate3d(a_p1, b_p1, fabs(dist / 2))
+ vn = Vector((midpoint3d[0] - loc[0],
midpoint3d[1] - loc[1],
midpoint3d[2] - loc[2]))
else:
- vn = mathutils.Vector((ms.glnormalx, ms.glnormaly, ms.glnormalz))
+ vn = Vector((ms.glnormalx, ms.glnormaly, ms.glnormalz))
vn.normalize()
# ------------------------------------
@@ -329,7 +325,7 @@ def draw_segments(context, myobj, op, region, rv3d):
if ms.gltype != 2 and ms.gltype != 9 and ms.gltype != 10 and ms.gltype != 11 and ms.gltype != 20:
# noinspection PyBroadException
try:
- midpoint3d = interpolate3d(v1, v2, math.fabs(dist / 2))
+ midpoint3d = interpolate3d(v1, v2, fabs(dist / 2))
gap3d = (midpoint3d[0], midpoint3d[1], midpoint3d[2] + s / 2)
txtpoint2d = get_2d_point(region, rv3d, gap3d)
# Scale
@@ -393,7 +389,7 @@ def draw_segments(context, myobj, op, region, rv3d):
ang = ang_1.angle(ang_2)
right = True
if bpy.context.scene.unit_settings.system_rotation == "DEGREES":
- ang = math.degrees(ang)
+ ang = degrees(ang)
tx_dist = " " + fmt % ang
# Add degree symbol
@@ -411,7 +407,7 @@ def draw_segments(context, myobj, op, region, rv3d):
tx_dist = " "
if bpy.context.scene.unit_settings.system_rotation == "DEGREES":
- arc_d = math.degrees(arc_angle)
+ arc_d = degrees(arc_angle)
else:
arc_d = arc_angle
@@ -430,7 +426,7 @@ def draw_segments(context, myobj, op, region, rv3d):
if scene.measureit_gl_show_d is True or scene.measureit_gl_show_n is True:
# Normal vector
- vna = mathutils.Vector((b_p1[0] - a_p1[0],
+ vna = Vector((b_p1[0] - a_p1[0],
b_p1[1] - a_p1[1],
b_p1[2] - a_p1[2]))
vna.normalize()
@@ -496,10 +492,10 @@ def draw_segments(context, myobj, op, region, rv3d):
if ms.gltype == 9: # Angle
dist, distloc = distance(an_p1, an_p2)
- mp1 = interpolate3d(an_p1, an_p2, math.fabs(dist / 1.1))
+ mp1 = interpolate3d(an_p1, an_p2, fabs(dist / 1.1))
dist, distloc = distance(an_p3, an_p2)
- mp2 = interpolate3d(an_p3, an_p2, math.fabs(dist / 1.1))
+ mp2 = interpolate3d(an_p3, an_p2, fabs(dist / 1.1))
screen_point_an_p1 = get_2d_point(region, rv3d, mp1)
screen_point_an_p2 = get_2d_point(region, rv3d, an_p2)
@@ -511,12 +507,12 @@ def draw_segments(context, myobj, op, region, rv3d):
if ms.gltype == 11: # arc
# draw line from center of arc second point
- c = mathutils.Vector(a_p1)
+ c = Vector(a_p1)
if ms.glarc_rad is True:
if ms.glarc_extrad is False:
draw_arrow(screen_point_ap1, screen_point_bp1, a_size, a_type, b_type)
else:
- vne = mathutils.Vector((b_p1[0] - a_p1[0],
+ vne = Vector((b_p1[0] - a_p1[0],
b_p1[1] - a_p1[1],
b_p1[2] - a_p1[2]))
vne.normalize()
@@ -527,19 +523,19 @@ def draw_segments(context, myobj, op, region, rv3d):
# create arc around the centerpoint
# rotation matrix around normal vector at center point
- mat_trans1 = mathutils.Matrix.Translation(-c)
+ mat_trans1 = Matrix.Translation(-c)
# get step
n_step = 36.0
if ms.glarc_full is False:
step = arc_angle / n_step
else:
- step = math.radians(360.0) / n_step
+ step = radians(360.0) / n_step
#
- mat_rot1 = mathutils.Matrix.Rotation(step, 4, vn)
- mat_trans2 = mathutils.Matrix.Translation(c)
- p1 = mathutils.Vector(an_p1) # first point of arc
+ mat_rot1 = Matrix.Rotation(step, 4, vn)
+ mat_trans2 = Matrix.Translation(c)
+ p1 = Vector(an_p1) # first point of arc
# Normal vector
- vn = mathutils.Vector((p1[0] - a_p1[0],
+ vn = Vector((p1[0] - a_p1[0],
p1[1] - a_p1[1],
p1[2] - a_p1[2]))
vn.normalize()
@@ -559,7 +555,7 @@ def draw_segments(context, myobj, op, region, rv3d):
p_01b = (p1[0], p1[1], p1[2])
# Normal vector
- vn = mathutils.Vector((p2[0] - a_p1[0],
+ vn = Vector((p2[0] - a_p1[0],
p2[1] - a_p1[1],
p2[2] - a_p1[2]))
vn.normalize()
@@ -613,7 +609,7 @@ def draw_segments(context, myobj, op, region, rv3d):
p2 = get_point(obverts[b].co, myobj)
d1, dn = distance(p1, p2)
- midpoint3d = interpolate3d(p1, p2, math.fabs(d1 / 2))
+ midpoint3d = interpolate3d(p1, p2, fabs(d1 / 2))
txtpoint2d = get_2d_point(region, rv3d, midpoint3d)
# Scale
if scene.measureit_scale is True:
@@ -639,7 +635,7 @@ def draw_segments(context, myobj, op, region, rv3d):
except IndexError:
ms.glfree = True
except:
- # print("Unexpected error:" + str(sys.exc_info()))
+ # print("Unexpected error:" + str(exc_info()))
# if error, disable segment
pass
@@ -658,7 +654,7 @@ def get_area_and_paint(myvertices, myobj, obverts, region, rv3d):
if myobj.mode != 'EDIT':
tris = mesh_utils.ngon_tessellate(mymesh, myvertices)
else:
- bm = bmesh.from_edit_mesh(myobj.data)
+ bm = from_edit_mesh(myobj.data)
myv = []
for v in bm.verts:
myv.extend([v.co])
@@ -708,7 +704,7 @@ def get_triangle_area(p1, p2, p3):
d2, dn = distance(p2, p3)
d3, dn = distance(p1, p3)
per = (d1 + d2 + d3) / 2.0
- area = math.sqrt(per * (per - d1) * (per - d2) * (per - d3))
+ area = sqrt(per * (per - d1) * (per - d2) * (per - d3))
return area
@@ -877,10 +873,10 @@ def draw_triangle(v1, v2, v3):
# -------------------------------------------------------------
def draw_arrow(v1, v2, size=20, a_typ="1", b_typ="1"):
- rad45 = math.radians(45)
- rad315 = math.radians(315)
- rad90 = math.radians(90)
- rad270 = math.radians(270)
+ rad45 = radians(45)
+ rad315 = radians(315)
+ rad90 = radians(90)
+ rad270 = radians(270)
v = interpolate3d((v1[0], v1[1], 0.0), (v2[0], v2[1], 0.0), size)
@@ -897,10 +893,10 @@ def draw_arrow(v1, v2, size=20, a_typ="1", b_typ="1"):
rad_a = rad45
rad_b = rad315
- v1a = (int(v1i[0] * math.cos(rad_a) - v1i[1] * math.sin(rad_a) + v1[0]),
- int(v1i[1] * math.cos(rad_a) + v1i[0] * math.sin(rad_a)) + v1[1])
- v1b = (int(v1i[0] * math.cos(rad_b) - v1i[1] * math.sin(rad_b) + v1[0]),
- int(v1i[1] * math.cos(rad_b) + v1i[0] * math.sin(rad_b) + v1[1]))
+ v1a = (int(v1i[0] * cos(rad_a) - v1i[1] * sin(rad_a) + v1[0]),
+ int(v1i[1] * cos(rad_a) + v1i[0] * sin(rad_a)) + v1[1])
+ v1b = (int(v1i[0] * cos(rad_b) - v1i[1] * sin(rad_b) + v1[0]),
+ int(v1i[1] * cos(rad_b) + v1i[0] * sin(rad_b) + v1[1]))
# Point B
if b_typ == "3":
@@ -910,10 +906,10 @@ def draw_arrow(v1, v2, size=20, a_typ="1", b_typ="1"):
rad_a = rad45
rad_b = rad315
- v2a = (int(v2i[0] * math.cos(rad_a) - v2i[1] * math.sin(rad_a) + v2[0]),
- int(v2i[1] * math.cos(rad_a) + v2i[0] * math.sin(rad_a)) + v2[1])
- v2b = (int(v2i[0] * math.cos(rad_b) - v2i[1] * math.sin(rad_b) + v2[0]),
- int(v2i[1] * math.cos(rad_b) + v2i[0] * math.sin(rad_b) + v2[1]))
+ v2a = (int(v2i[0] * cos(rad_a) - v2i[1] * sin(rad_a) + v2[0]),
+ int(v2i[1] * cos(rad_a) + v2i[0] * sin(rad_a)) + v2[1])
+ v2b = (int(v2i[0] * cos(rad_b) - v2i[1] * sin(rad_b) + v2[0]),
+ int(v2i[1] * cos(rad_b) + v2i[0] * sin(rad_b) + v2[1]))
# Triangle o Lines
if a_typ == "1" or a_typ == "3":
@@ -986,7 +982,7 @@ def draw_vertices(context, myobj, region, rv3d):
# vertex Loop
# --------------------
if myobj.mode == 'EDIT':
- bm = bmesh.from_edit_mesh(myobj.data)
+ bm = from_edit_mesh(myobj.data)
obverts = bm.verts
else:
obverts = myobj.data.vertices
@@ -1009,7 +1005,7 @@ def draw_vertices(context, myobj, region, rv3d):
txt += format_point(v.co, precision)
draw_text(myobj, txtpoint2d[0], txtpoint2d[1], txt, rgb, fsize)
except:
- print("Unexpected error:" + str(sys.exc_info()))
+ print("Unexpected error:" + str(exc_info()))
pass
return
@@ -1037,7 +1033,7 @@ def draw_faces(context, myobj, region, rv3d):
# face Loop
# --------------------
if myobj.mode == 'EDIT':
- bm = bmesh.from_edit_mesh(myobj.data)
+ bm = from_edit_mesh(myobj.data)
obverts = bm.verts
myfaces = bm.faces
else:
@@ -1099,7 +1095,7 @@ def draw_faces(context, myobj, region, rv3d):
draw_text(myobj, point2[0], point2[1], txt, rgb2, fsize)
except:
- print("Unexpected error:" + str(sys.exc_info()))
+ print("Unexpected error:" + str(exc_info()))
pass
return
@@ -1113,7 +1109,7 @@ def draw_faces(context, myobj, region, rv3d):
# return: distance
# --------------------------------------------------------------------
def distance(v1, v2, locx=True, locy=True, locz=True):
- x = math.sqrt((v2[0] - v1[0]) ** 2 + (v2[1] - v1[1]) ** 2 + (v2[2] - v1[2]) ** 2)
+ x = sqrt((v2[0] - v1[0]) ** 2 + (v2[1] - v1[1]) ** 2 + (v2[2] - v1[2]) ** 2)
# If axis is not used, make equal both (no distance)
v1b = [v1[0], v1[1], v1[2]]
@@ -1125,7 +1121,7 @@ def distance(v1, v2, locx=True, locy=True, locz=True):
if locz is False:
v2b[2] = v1b[2]
- xloc = math.sqrt((v2b[0] - v1b[0]) ** 2 + (v2b[1] - v1b[1]) ** 2 + (v2b[2] - v1b[2]) ** 2)
+ xloc = sqrt((v2b[0] - v1b[0]) ** 2 + (v2b[1] - v1b[1]) ** 2 + (v2b[2] - v1b[2]) ** 2)
return x, xloc
@@ -1161,7 +1157,7 @@ def interpolate3d(v1, v2, d1):
# --------------------------------------------------------------------
def get_point(v1, mainobject):
# Using World Matrix
- vt = mathutils.Vector((v1[0], v1[1], v1[2], 1))
+ vt = Vector((v1[0], v1[1], v1[2], 1))
m4 = mainobject.matrix_world
vt2 = m4 * vt
v2 = [vt2[0], vt2[1], vt2[2]]
@@ -1188,7 +1184,7 @@ def get_location(mainobject):
def get_mesh_vertices(myobj):
try:
if myobj.mode == 'EDIT':
- bm = bmesh.from_edit_mesh(myobj.data)
+ bm = from_edit_mesh(myobj.data)
obverts = bm.verts
else:
obverts = myobj.data.vertices
@@ -1217,7 +1213,7 @@ def get_scale_txt_location(context):
# --------------------------------------------------------------------
def get_render_location(mypoint):
- v1 = mathutils.Vector(mypoint)
+ v1 = Vector(mypoint)
scene = bpy.context.scene
co_2d = object_utils.world_to_camera_view(scene, scene.camera, v1)
# Get pixel coords
@@ -1241,13 +1237,13 @@ def get_render_location(mypoint):
#
# ---------------------------------------------------------
def get_arc_data(pointa, pointb, pointc, pointd):
- v1 = mathutils.Vector((pointa[0] - pointb[0], pointa[1] - pointb[1], pointa[2] - pointb[2]))
- v2 = mathutils.Vector((pointc[0] - pointb[0], pointc[1] - pointb[1], pointc[2] - pointb[2]))
- v3 = mathutils.Vector((pointd[0] - pointb[0], pointd[1] - pointb[1], pointd[2] - pointb[2]))
+ v1 = Vector((pointa[0] - pointb[0], pointa[1] - pointb[1], pointa[2] - pointb[2]))
+ v2 = Vector((pointc[0] - pointb[0], pointc[1] - pointb[1], pointc[2] - pointb[2]))
+ v3 = Vector((pointd[0] - pointb[0], pointd[1] - pointb[1], pointd[2] - pointb[2]))
angle = v1.angle(v2) + v2.angle(v3)
- rclength = math.pi * 2 * v2.length * (angle / (math.pi * 2))
+ rclength = pi * 2 * v2.length * (angle / (pi * 2))
return angle, rclength
diff --git a/measureit/measureit_main.py b/measureit/measureit_main.py
index 6e01f903..96a0ece4 100644
--- a/measureit/measureit_main.py
+++ b/measureit/measureit_main.py
@@ -26,11 +26,12 @@
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
-# noinspection PyUnresolvedReferences
-import bmesh
+from bmesh import from_edit_mesh
# noinspection PyUnresolvedReferences
import bgl
-# noinspection PyUnresolvedReferences
+from bpy.types import PropertyGroup, Panel, Object, Operator, SpaceView3D
+from bpy.props import IntProperty, CollectionProperty, FloatVectorProperty, BoolProperty, StringProperty, FloatProperty, \
+ EnumProperty
from bpy.app.handlers import persistent
# noinspection PyUnresolvedReferences
from .measureit_geometry import *
@@ -84,8 +85,8 @@ bpy.app.handlers.save_pre.append(save_handler)
# ------------------------------------------------------------------
# Define property group class for measureit faces index
# ------------------------------------------------------------------
-class MeasureitIndex(bpy.types.PropertyGroup):
- glidx = bpy.props.IntProperty(name="index",
+class MeasureitIndex(PropertyGroup):
+ glidx = IntProperty(name="index",
description="vertex index")
# Register
@@ -95,11 +96,11 @@ bpy.utils.register_class(MeasureitIndex)
# ------------------------------------------------------------------
# Define property group class for measureit faces
# ------------------------------------------------------------------
-class MeasureitFaces(bpy.types.PropertyGroup):
- glface = bpy.props.IntProperty(name="glface",
+class MeasureitFaces(PropertyGroup):
+ glface = IntProperty(name="glface",
description="Face number")
# Array of index
- measureit_index = bpy.props.CollectionProperty(type=MeasureitIndex)
+ measureit_index = CollectionProperty(type=MeasureitIndex)
# Register
bpy.utils.register_class(MeasureitFaces)
@@ -108,80 +109,80 @@ bpy.utils.register_class(MeasureitFaces)
# ------------------------------------------------------------------
# Define property group class for measureit data
# ------------------------------------------------------------------
-class MeasureitProperties(bpy.types.PropertyGroup):
- gltype = bpy.props.IntProperty(name="gltype",
+class MeasureitProperties(PropertyGroup):
+ gltype = IntProperty(name="gltype",
description="Measure type (1-Segment, 2-Label, etc..)", default=1)
- glpointa = bpy.props.IntProperty(name="glpointa",
+ glpointa = IntProperty(name="glpointa",
description="Hidden property for opengl")
- glpointb = bpy.props.IntProperty(name="glpointb",
+ glpointb = IntProperty(name="glpointb",
description="Hidden property for opengl")
- glpointc = bpy.props.IntProperty(name="glpointc",
+ glpointc = IntProperty(name="glpointc",
description="Hidden property for opengl")
- glcolor = bpy.props.FloatVectorProperty(name="glcolor",
+ glcolor = FloatVectorProperty(name="glcolor",
description="Color for the measure",
default=(0.173, 0.545, 1.0, 1.0),
min=0.1,
max=1,
subtype='COLOR',
size=4)
- glview = bpy.props.BoolProperty(name="glview",
+ glview = BoolProperty(name="glview",
description="Measure visible/hide",
default=True)
- glspace = bpy.props.FloatProperty(name='glspace', min=-100, max=100, default=0.1,
+ glspace = FloatProperty(name='glspace', min=-100, max=100, default=0.1,
precision=3,
description='Distance to display measure')
- glwidth = bpy.props.IntProperty(name='glwidth', min=1, max=10, default=1,
+ glwidth = IntProperty(name='glwidth', min=1, max=10, default=1,
description='line width')
- glfree = bpy.props.BoolProperty(name="glfree",
+ glfree = BoolProperty(name="glfree",
description="This measure is free and can be deleted",
default=False)
- gltxt = bpy.props.StringProperty(name="gltxt", maxlen=256,
+ gltxt = StringProperty(name="gltxt", maxlen=256,
description="Short description (use | for line break)")
- gladvance = bpy.props.BoolProperty(name="gladvance",
+ gladvance = BoolProperty(name="gladvance",
description="Advanced options as line width or position",
default=False)
- gldefault = bpy.props.BoolProperty(name="gldefault",
+ gldefault = BoolProperty(name="gldefault",
description="Display measure in position calculated by default",
default=True)
- glnormalx = bpy.props.FloatProperty(name="glnormalx",
+ glnormalx = FloatProperty(name="glnormalx",
description="Change orientation in X axis",
default=1, min=-1, max=1, precision=2)
- glnormaly = bpy.props.FloatProperty(name="glnormaly",
+ glnormaly = FloatProperty(name="glnormaly",
description="Change orientation in Y axis",
default=0, min=-1, max=1, precision=2)
- glnormalz = bpy.props.FloatProperty(name="glnormalz",
+ glnormalz = FloatProperty(name="glnormalz",
description="Change orientation in Z axis",
default=0, min=-1, max=1, precision=2)
- glfont_size = bpy.props.IntProperty(name="Text Size",
+ glfont_size = IntProperty(name="Text Size",
description="Text size",
default=14, min=6, max=150)
- gllink = bpy.props.StringProperty(name="gllink",
+ gllink = StringProperty(name="gllink",
description="linked object for linked measures")
- glocwarning = bpy.props.BoolProperty(name="glocwarning",
+ glocwarning = BoolProperty(name="glocwarning",
description="Display a warning if some axis is not used in distance",
default=True)
- glocx = bpy.props.BoolProperty(name="glocx",
+ glocx = BoolProperty(name="glocx",
description="Include changes in X axis for calculating the distance",
default=True)
- glocy = bpy.props.BoolProperty(name="glocy",
+ glocy = BoolProperty(name="glocy",
description="Include changes in Y axis for calculating the distance",
default=True)
- glocz = bpy.props.BoolProperty(name="glocz",
+ glocz = BoolProperty(name="glocz",
description="Include changes in Z axis for calculating the distance",
default=True)
- glfontx = bpy.props.IntProperty(name="glfontx",
+ glfontx = IntProperty(name="glfontx",
description="Change font position in X axis",
default=0, min=-3000, max=3000)
- glfonty = bpy.props.IntProperty(name="glfonty",
+ glfonty = IntProperty(name="glfonty",
description="Change font position in Y axis",
default=0, min=-3000, max=3000)
- gldist = bpy.props.BoolProperty(name="gldist",
+ gldist = BoolProperty(name="gldist",
description="Display distance for this measure",
default=True)
- glnames = bpy.props.BoolProperty(name="glnames",
+ glnames = BoolProperty(name="glnames",
description="Display text for this measure",
default=True)
- gltot = bpy.props.EnumProperty(items=(('99', "-", "Select a group for sum"),
+ gltot = EnumProperty(items=(('99', "-", "Select a group for sum"),
('0', "A", ""),
('1', "B", ""),
('2', "C", ""),
@@ -210,74 +211,74 @@ class MeasureitProperties(bpy.types.PropertyGroup):
('25', "Z", "")),
name="Sum in Group",
description="Add segment length in selected group")
- glorto = bpy.props.EnumProperty(items=(('99', "None", ""),
+ glorto = EnumProperty(items=(('99', "None", ""),
('0', "A", "Point A must use selected point B location"),
('1', "B", "Point B must use selected point A location")),
name="Orthogonal",
description="Display point selected as orthogonal (select axis to copy)")
- glorto_x = bpy.props.BoolProperty(name="ox",
+ glorto_x = BoolProperty(name="ox",
description="Copy X location",
default=False)
- glorto_y = bpy.props.BoolProperty(name="oy",
+ glorto_y = BoolProperty(name="oy",
description="Copy Y location",
default=False)
- glorto_z = bpy.props.BoolProperty(name="oz",
+ glorto_z = BoolProperty(name="oz",
description="Copy Z location",
default=False)
- glarrow_a = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ glarrow_a = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line", "The point of the arrow are lines"),
('2', "Triangle", "The point of the arrow is triangle"),
('3', "TShape", "The point of the arrow is a T")),
name="A end",
description="Add arrows to point A")
- glarrow_b = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ glarrow_b = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line", "The point of the arrow are lines"),
('2', "Triangle", "The point of the arrow is triangle"),
('3', "TShape", "The point of the arrow is a T")),
name="B end",
description="Add arrows to point B")
- glarrow_s = bpy.props.IntProperty(name="Size",
+ glarrow_s = IntProperty(name="Size",
description="Arrow size",
default=15, min=6, max=500)
- glarc_full = bpy.props.BoolProperty(name="arcfull",
+ glarc_full = BoolProperty(name="arcfull",
description="Create full circunference",
default=False)
- glarc_extrad = bpy.props.BoolProperty(name="arcextrad",
+ glarc_extrad = BoolProperty(name="arcextrad",
description="Adapt radio lengh to arc line",
default=True)
- glarc_rad = bpy.props.BoolProperty(name="arc rad",
+ glarc_rad = BoolProperty(name="arc rad",
description="Show arc radius",
default=True)
- glarc_len = bpy.props.BoolProperty(name="arc len",
+ glarc_len = BoolProperty(name="arc len",
description="Show arc length",
default=True)
- glarc_ang = bpy.props.BoolProperty(name="arc ang",
+ glarc_ang = BoolProperty(name="arc ang",
description="Show arc angle",
default=True)
- glarc_a = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ glarc_a = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line", "The point of the arrow are lines"),
('2', "Triangle", "The point of the arrow is triangle"),
('3', "TShape", "The point of the arrow is a T")),
name="Ar end",
description="Add arrows to point A")
- glarc_b = bpy.props.EnumProperty(items=(('99', "--", "No arrow"),
+ glarc_b = EnumProperty(items=(('99', "--", "No arrow"),
('1', "Line", "The point of the arrow are lines"),
('2', "Triangle", "The point of the arrow is triangle"),
('3', "TShape", "The point of the arrow is a T")),
name="Br end",
description="Add arrows to point B")
- glarc_s = bpy.props.IntProperty(name="Size",
+ glarc_s = IntProperty(name="Size",
description="Arrow size",
default=15, min=6, max=500)
- glarc_txradio = bpy.props.StringProperty(name="txradio",
+ glarc_txradio = StringProperty(name="txradio",
description="Text for radius", default="r=")
- glarc_txlen = bpy.props.StringProperty(name="txlen",
+ glarc_txlen = StringProperty(name="txlen",
description="Text for length", default="L=")
- glarc_txang = bpy.props.StringProperty(name="txang",
+ glarc_txang = StringProperty(name="txang",
description="Text for angle", default="A=")
- glcolorarea = bpy.props.FloatVectorProperty(name="glcolorarea",
+ glcolorarea = FloatVectorProperty(name="glcolorarea",
description="Color for the measure of area",
default=(0.1, 0.1, 0.1, 1.0),
min=0.1,
@@ -286,7 +287,7 @@ class MeasureitProperties(bpy.types.PropertyGroup):
size=4)
# Array of faces
- measureit_faces = bpy.props.CollectionProperty(type=MeasureitFaces)
+ measureit_faces = CollectionProperty(type=MeasureitFaces)
# Register
bpy.utils.register_class(MeasureitProperties)
@@ -296,22 +297,22 @@ bpy.utils.register_class(MeasureitProperties)
# Define object class (container of segments)
# Measureit
# ------------------------------------------------------------------
-class MeasureContainer(bpy.types.PropertyGroup):
- measureit_num = bpy.props.IntProperty(name='Number of measures', min=0, max=1000, default=0,
+class MeasureContainer(PropertyGroup):
+ measureit_num = IntProperty(name='Number of measures', min=0, max=1000, default=0,
description='Number total of measureit elements')
# Array of segments
- measureit_segments = bpy.props.CollectionProperty(type=MeasureitProperties)
+ measureit_segments = CollectionProperty(type=MeasureitProperties)
bpy.utils.register_class(MeasureContainer)
-bpy.types.Object.MeasureGenerator = bpy.props.CollectionProperty(type=MeasureContainer)
+Object.MeasureGenerator = CollectionProperty(type=MeasureContainer)
# ------------------------------------------------------------------
# Define UI class
# Measureit
# ------------------------------------------------------------------
-class MeasureitEditPanel(bpy.types.Panel):
+class MeasureitEditPanel(Panel):
bl_idname = "measureit.editpanel"
bl_label = "Measureit"
bl_space_type = 'VIEW_3D'
@@ -567,7 +568,7 @@ def add_item(box, idx, segment):
# ------------------------------------------------------------------
# Define panel class for main functions.
# ------------------------------------------------------------------
-class MeasureitMainPanel(bpy.types.Panel):
+class MeasureitMainPanel(Panel):
bl_idname = "measureit_main_panel"
bl_label = "Tools"
bl_space_type = 'VIEW_3D'
@@ -664,7 +665,7 @@ class MeasureitMainPanel(bpy.types.Panel):
# ------------------------------------------------------------------
# Define panel class for conf functions.
# ------------------------------------------------------------------
-class MeasureitConfPanel(bpy.types.Panel):
+class MeasureitConfPanel(Panel):
bl_idname = "measureit_conf_panel"
bl_label = "Configuration"
bl_space_type = 'VIEW_3D'
@@ -698,7 +699,7 @@ class MeasureitConfPanel(bpy.types.Panel):
# ------------------------------------------------------------------
# Define panel class for render functions.
# ------------------------------------------------------------------
-class MeasureitRenderPanel(bpy.types.Panel):
+class MeasureitRenderPanel(Panel):
bl_idname = "measureit_render_panel"
bl_label = "Render"
bl_space_type = 'VIEW_3D'
@@ -733,7 +734,7 @@ class MeasureitRenderPanel(bpy.types.Panel):
# Defines button for add a measure segment
#
# -------------------------------------------------------------
-class AddSegmentButton(bpy.types.Operator):
+class AddSegmentButton(Operator):
bl_idname = "measureit.addsegmentbutton"
bl_label = "Add"
bl_description = "(EDITMODE only) Add a new measure segment between 2 vertices (select 2 vertices or more)"
@@ -820,7 +821,7 @@ class AddSegmentButton(bpy.types.Operator):
# Defines button for add area measure
#
# -------------------------------------------------------------
-class AddAreaButton(bpy.types.Operator):
+class AddAreaButton(Operator):
bl_idname = "measureit.addareabutton"
bl_label = "Area"
bl_description = "(EDITMODE only) Add a new measure for area (select 1 o more faces)"
@@ -906,13 +907,13 @@ class AddAreaButton(bpy.types.Operator):
# Defines button for add a measure segment to x/y/z origin
#
# -------------------------------------------------------------
-class AddSegmentOrtoButton(bpy.types.Operator):
+class AddSegmentOrtoButton(Operator):
bl_idname = "measureit.addsegmentortobutton"
bl_label = "Add"
bl_description = "(EDITMODE only) Add a new measure segment from vertex to object origin for one " \
"axis (select 1 vertex)"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Poll
@@ -995,7 +996,7 @@ class AddSegmentOrtoButton(bpy.types.Operator):
# Defines button for add a angle
#
# -------------------------------------------------------------
-class AddAngleButton(bpy.types.Operator):
+class AddAngleButton(Operator):
bl_idname = "measureit.addanglebutton"
bl_label = "Angle"
bl_description = "(EDITMODE only) Add a new angle measure (select 3 vertices, 2nd is angle vertex)"
@@ -1074,7 +1075,7 @@ class AddAngleButton(bpy.types.Operator):
# Defines button for add a arc
#
# -------------------------------------------------------------
-class AddArcButton(bpy.types.Operator):
+class AddArcButton(Operator):
bl_idname = "measureit.addarcbutton"
bl_label = "Angle"
bl_description = "(EDITMODE only) Add a new arc measure (select 3 vertices of the arc," \
@@ -1157,7 +1158,7 @@ class AddArcButton(bpy.types.Operator):
# Defines button for add a label segment
#
# -------------------------------------------------------------
-class AddLabelButton(bpy.types.Operator):
+class AddLabelButton(Operator):
bl_idname = "measureit.addlabelbutton"
bl_label = "Add"
bl_description = "(EDITMODE only) Add a new measure label (select 1 vertex)"
@@ -1238,7 +1239,7 @@ class AddLabelButton(bpy.types.Operator):
# Defines button for add a link
#
# -------------------------------------------------------------
-class AddLinkButton(bpy.types.Operator):
+class AddLinkButton(Operator):
bl_idname = "measureit.addlinkbutton"
bl_label = "Add"
bl_description = "(OBJECT mode only) Add a new measure between objects (select 2 " \
@@ -1383,7 +1384,7 @@ class AddLinkButton(bpy.types.Operator):
# Defines button for add a origin segment
#
# -------------------------------------------------------------
-class AddOriginButton(bpy.types.Operator):
+class AddOriginButton(Operator):
bl_idname = "measureit.addoriginbutton"
bl_label = "Add"
bl_description = "(OBJECT mode only) Add a new measure to origin (select object and optionally 1 vertex)"
@@ -1480,12 +1481,12 @@ class AddOriginButton(bpy.types.Operator):
# Defines button for delete a measure segment
#
# -------------------------------------------------------------
-class DeleteSegmentButton(bpy.types.Operator):
+class DeleteSegmentButton(Operator):
bl_idname = "measureit.deletesegmentbutton"
bl_label = "Delete"
bl_description = "Delete a measure"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Execute button action
@@ -1514,12 +1515,12 @@ class DeleteSegmentButton(bpy.types.Operator):
# Defines button for delete all measure segment
#
# -------------------------------------------------------------
-class DeleteAllSegmentButton(bpy.types.Operator):
+class DeleteAllSegmentButton(Operator):
bl_idname = "measureit.deleteallsegmentbutton"
bl_label = "Delete"
bl_description = "Delete all measures (it cannot be undone)"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Execute button action
@@ -1549,12 +1550,12 @@ class DeleteAllSegmentButton(bpy.types.Operator):
# Defines button for delete all measure segment
#
# -------------------------------------------------------------
-class DeleteAllSumButton(bpy.types.Operator):
+class DeleteAllSumButton(Operator):
bl_idname = "measureit.deleteallsumbutton"
bl_label = "Delete"
bl_description = "Delete all sum groups"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Execute button action
@@ -1575,12 +1576,12 @@ class DeleteAllSumButton(bpy.types.Operator):
# Defines button for render
#
# -------------------------------------------------------------
-class RenderSegmentButton(bpy.types.Operator):
+class RenderSegmentButton(Operator):
bl_idname = "measureit.rendersegmentbutton"
bl_label = "Render"
bl_description = "Create a render image with measures. Use UV/Image editor to view image generated"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Execute button action
@@ -1711,12 +1712,12 @@ class RenderSegmentButton(bpy.types.Operator):
# Defines a new note
#
# -------------------------------------------------------------
-class AddNoteButton(bpy.types.Operator):
+class AddNoteButton(Operator):
bl_idname = "measureit.addnotebutton"
bl_label = "Note"
bl_description = "(OBJECT mode only) Add a new annotation"
bl_category = 'Measureit'
- tag = bpy.props.IntProperty()
+ tag = IntProperty()
# ------------------------------
# Poll
@@ -1779,7 +1780,7 @@ class AddNoteButton(bpy.types.Operator):
# Defines button for enable/disable the tip display
#
# -------------------------------------------------------------
-class RunHintDisplayButton(bpy.types.Operator):
+class RunHintDisplayButton(Operator):
bl_idname = "measureit.runopenglbutton"
bl_label = "Display hint data manager"
bl_description = "Main control for enabling or disabling the display of measurements in the viewport"
@@ -1793,7 +1794,7 @@ class RunHintDisplayButton(bpy.types.Operator):
@staticmethod
def handle_add(self, context):
if RunHintDisplayButton._handle is None:
- RunHintDisplayButton._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, (self, context),
+ RunHintDisplayButton._handle = SpaceView3D.draw_handler_add(draw_callback_px, (self, context),
'WINDOW',
'POST_PIXEL')
context.window_manager.measureit_run_opengl = True
@@ -1805,7 +1806,7 @@ class RunHintDisplayButton(bpy.types.Operator):
@staticmethod
def handle_remove(self, context):
if RunHintDisplayButton._handle is not None:
- bpy.types.SpaceView3D.draw_handler_remove(RunHintDisplayButton._handle, 'WINDOW')
+ SpaceView3D.draw_handler_remove(RunHintDisplayButton._handle, 'WINDOW')
RunHintDisplayButton._handle = None
context.window_manager.measureit_run_opengl = False
@@ -1946,7 +1947,7 @@ def get_selected_vertex(myobject):
bpy.ops.object.mode_set(mode='EDIT')
flag = True
- bm = bmesh.from_edit_mesh(myobject.data)
+ bm = from_edit_mesh(myobject.data)
tv = len(bm.verts)
for v in bm.verts:
if v.select:
@@ -1982,7 +1983,7 @@ def get_selected_vertex_history(myobject):
bpy.ops.object.mode_set(mode='EDIT')
flag = True
- bm = bmesh.from_edit_mesh(myobject.data)
+ bm = from_edit_mesh(myobject.data)
for v in bm.select_history:
mylist.extend([v.index])
@@ -2012,7 +2013,7 @@ def get_smart_selected(myobject):
bpy.ops.object.mode_set(mode='EDIT')
flag = True
- bm = bmesh.from_edit_mesh(myobject.data)
+ bm = from_edit_mesh(myobject.data)
for e in bm.edges:
if e.select is True:
mylist.extend([e.verts[0].index])
@@ -2044,7 +2045,7 @@ def get_selected_faces(myobject):
bpy.ops.object.mode_set(mode='EDIT')
flag = True
- bm = bmesh.from_edit_mesh(myobject.data)
+ bm = from_edit_mesh(myobject.data)
for e in bm.faces:
myface = []
if e.select is True:
diff --git a/measureit/measureit_render.py b/measureit/measureit_render.py
index cac0a5a2..88479310 100644
--- a/measureit/measureit_render.py
+++ b/measureit/measureit_render.py
@@ -29,12 +29,8 @@ import bpy
import bgl
# noinspection PyUnresolvedReferences
import blf
-# noinspection PyUnresolvedReferences
-import mathutils
-# noinspection PyUnresolvedReferences
-import bmesh
-import os
-import sys
+from os import path, remove
+from sys import exc_info
# noinspection PyUnresolvedReferences
import bpy_extras.image_utils as img_utils
# noinspection PyUnresolvedReferences
@@ -79,11 +75,11 @@ def render_main(self, context, animation=False):
# ---------------------------------------
ren_path = bpy.context.scene.render.filepath
if len(ren_path) > 0:
- if ren_path.endswith(os.path.sep):
- initpath = os.path.realpath(ren_path) + os.path.sep
+ if ren_path.endswith(path.sep):
+ initpath = path.realpath(ren_path) + path.sep
else:
- (initpath, filename) = os.path.split(ren_path)
- outpath = os.path.join(initpath, "measureit_tmp_render.png")
+ (initpath, filename) = path.split(ren_path)
+ outpath = path.join(initpath, "measureit_tmp_render.png")
else:
self.report({'ERROR'},
"MeasureIt: Unable to save temporary render image. Define a valid render path")
@@ -213,7 +209,7 @@ def render_main(self, context, animation=False):
x1 = rfborder
x2 = width - rfborder
- y1 = int(math.ceil(rfborder / (width / height)))
+ y1 = int(ceil(rfborder / (width / height)))
y2 = height - y1
draw_rectangle((x1, y1), (x2, y2))
@@ -247,7 +243,7 @@ def render_main(self, context, animation=False):
img.user_clear()
bpy.data.images.remove(img)
# remove temp file
- os.remove(outpath)
+ remove(outpath)
# reset
bgl.glEnable(bgl.GL_SCISSOR_TEST)
# -----------------------
@@ -261,13 +257,13 @@ def render_main(self, context, animation=False):
ren_path = bpy.context.scene.render.filepath
filename = "mit_frame"
if len(ren_path) > 0:
- if ren_path.endswith(os.path.sep):
- initpath = os.path.realpath(ren_path) + os.path.sep
+ if ren_path.endswith(path.sep):
+ initpath = path.realpath(ren_path) + path.sep
else:
- (initpath, filename) = os.path.split(ren_path)
+ (initpath, filename) = path.split(ren_path)
ftxt = "%04d" % scene.frame_current
- outpath = os.path.join(initpath, filename + ftxt + ".png")
+ outpath = path.join(initpath, filename + ftxt + ".png")
save_image(self, outpath, out)
@@ -276,7 +272,7 @@ def render_main(self, context, animation=False):
except:
settings.color_depth = depth
- print("Unexpected error:" + str(sys.exc_info()))
+ print("Unexpected error:" + str(exc_info()))
self.report({'ERROR'}, "MeasureIt: Unable to create render image")
return False
@@ -338,6 +334,6 @@ def save_image(self, filepath, myimage):
settings.color_mode = mode
settings.color_depth = depth
except:
- print("Unexpected error:" + str(sys.exc_info()))
+ print("Unexpected error:" + str(exc_info()))
self.report({'ERROR'}, "MeasureIt: Unable to save render image")
return