Browse Source

Use PEP8. Fix NameError&note use. Switch to 2.79-2.80 code.

master
poikilos 5 years ago
committed by Jacob Gustafson
parent
commit
42c077034d
  1. 38
      utilities/blender/generate_Empty_at_each_vertex.py

38
utilities/blender/generate_Empty_at_each_vertex.py

@ -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" print("How to use: paste into a Blender Text Editor panel, select"
" object, Run Script") " object, Run Script")
y_up = True y_up = True
enable_minetest = True enable_minetest = True
import bpy
# from mathutils import Matrix
from mathutils import Vector
# from mathutils import Euler
class MessageBox(bpy.types.Operator): class MessageBox(bpy.types.Operator):
bl_idname = "message.messagebox" bl_idname = "message.messagebox"
@ -34,18 +36,23 @@ class MessageBox(bpy.types.Operator):
# col.prop(context.scene, "my_string_prop") # col.prop(context.scene, "my_string_prop")
ob1 = None ob1 = bpy.context.active_object # works with 2.7 or 2.8
try: # try:
ob1 = obj.select_get() # # See <https://blender.stackexchange.com/questions/141330/
except: # # problem-with-bpy-context-selected-objects>
# < 2.8 # # for o in context.scene.objects:
ob1 = bpy.context.scene.objects.active # # 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) bpy.utils.register_class(MessageBox)
if ob1 is None: if ob1 is None:
msg = "Nothing is selected." 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) # self.report({'ERROR'}, msg)
bpy.ops.message.messagebox('INVOKE_DEFAULT', message=msg) bpy.ops.message.messagebox('INVOKE_DEFAULT', message=msg)
else: else:
@ -53,7 +60,9 @@ else:
loc1 = ob1.location loc1 = ob1.location
# loc1 = ob1.matrix_world.translation # 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 mesh = ob1.data
# print("mesh:" + str(mesh)) # print("mesh:" + str(mesh))
# print("hasattr(mesh, 'vertices'):" + str(hasattr(mesh, # print("hasattr(mesh, 'vertices'):" + str(hasattr(mesh,
@ -68,7 +77,8 @@ else:
xMax = None xMax = None
yMax = None yMax = None
zMax = 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 wm = ob1.matrix_world
newNamePrefix = "Empty.from." + ob1.name newNamePrefix = "Empty.from." + ob1.name
i = 0 i = 0
@ -80,7 +90,7 @@ else:
except TypeError: except TypeError:
loc = wm * vert.co # Blender <2.8 loc = wm * vert.co # Blender <2.8
# See also vert.co.x (and y and z) # 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 bpy.context.active_object.name = name
# Also consider sambler's answer at # Also consider sambler's answer at

Loading…
Cancel
Save