|
|
@ -1,13 +1,15 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
import bpy |
|
|
|
# from mathutils import Matrix |
|
|
|
from mathutils import Vector |
|
|
|
# from mathutils import Euler |
|
|
|
|
|
|
|
print("How to use: paste into a Blender Text Editor panel, select" |
|
|
|
" object, Run Script") |
|
|
|
|
|
|
|
y_up = True |
|
|
|
enable_minetest = True |
|
|
|
|
|
|
|
import bpy |
|
|
|
# from mathutils import Matrix |
|
|
|
from mathutils import Vector |
|
|
|
# from mathutils import Euler |
|
|
|
|
|
|
|
class MessageBox(bpy.types.Operator): |
|
|
|
bl_idname = "message.messagebox" |
|
|
@ -34,18 +36,23 @@ class MessageBox(bpy.types.Operator): |
|
|
|
# col.prop(context.scene, "my_string_prop") |
|
|
|
|
|
|
|
|
|
|
|
ob1 = None |
|
|
|
try: |
|
|
|
ob1 = obj.select_get() |
|
|
|
except: |
|
|
|
# < 2.8 |
|
|
|
ob1 = bpy.context.scene.objects.active |
|
|
|
ob1 = bpy.context.active_object # works with 2.7 or 2.8 |
|
|
|
# try: |
|
|
|
# # See <https://blender.stackexchange.com/questions/141330/ |
|
|
|
# # problem-with-bpy-context-selected-objects> |
|
|
|
# # for o in context.scene.objects: |
|
|
|
# # o.select_get() returns bool! |
|
|
|
# # To select it automatically: o.select_set(bool) |
|
|
|
# except: |
|
|
|
# # Blender version <= 2.79 |
|
|
|
# ob1 = bpy.context.scene.objects.active |
|
|
|
|
|
|
|
bpy.utils.register_class(MessageBox) |
|
|
|
|
|
|
|
if ob1 is None: |
|
|
|
msg = "Nothing is selected." |
|
|
|
# WRONG: https://stackoverflow.com/questions/7697532/how-to-show-a-message-from-a-blender-script |
|
|
|
# WRONG: <https://stackoverflow.com/questions/7697532/how-to-show-a- |
|
|
|
# message-from-a-blender-script> |
|
|
|
# self.report({'ERROR'}, msg) |
|
|
|
bpy.ops.message.messagebox('INVOKE_DEFAULT', message=msg) |
|
|
|
else: |
|
|
@ -53,7 +60,9 @@ else: |
|
|
|
loc1 = ob1.location |
|
|
|
# loc1 = ob1.matrix_world.translation |
|
|
|
|
|
|
|
# See https://blender.stackexchange.com/questions/6139/how-to-iterate-through-all-vertices-of-an-object-that-contains-multiple-meshes |
|
|
|
# See <https://blender.stackexchange.com/questions/6139/how-to- |
|
|
|
# iterate-through-all-vertices-of-an-object-that-contains- |
|
|
|
# multiple-meshes> |
|
|
|
mesh = ob1.data |
|
|
|
# print("mesh:" + str(mesh)) |
|
|
|
# print("hasattr(mesh, 'vertices'):" + str(hasattr(mesh, |
|
|
@ -68,7 +77,8 @@ else: |
|
|
|
xMax = None |
|
|
|
yMax = None |
|
|
|
zMax = None |
|
|
|
# See https://blender.stackexchange.com/questions/6155/how-to-convert-coordinates-from-vertex-to-world-space |
|
|
|
# See <https://blender.stackexchange.com/questions/6155/how-to- |
|
|
|
# convert-coordinates-from-vertex-to-world-space> |
|
|
|
wm = ob1.matrix_world |
|
|
|
newNamePrefix = "Empty.from." + ob1.name |
|
|
|
i = 0 |
|
|
@ -80,7 +90,7 @@ else: |
|
|
|
except TypeError: |
|
|
|
loc = wm * vert.co # Blender <2.8 |
|
|
|
# See also vert.co.x (and y and z) |
|
|
|
bpy.ops.object.add(type='EMPTY', radius=.25, location=loc); |
|
|
|
bpy.ops.object.add(type='EMPTY', radius=.25, location=loc) |
|
|
|
bpy.context.active_object.name = name |
|
|
|
|
|
|
|
# Also consider sambler's answer at |
|
|
|