summaryrefslogtreecommitdiff
path: root/blender_funcs.py
diff options
context:
space:
mode:
Diffstat (limited to 'blender_funcs.py')
-rw-r--r--blender_funcs.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/blender_funcs.py b/blender_funcs.py
index d9eb7a4..e18431e 100644
--- a/blender_funcs.py
+++ b/blender_funcs.py
@@ -1,4 +1,5 @@
import bpy, numpy
+import time
# file that contains useful blender some functions that I don't
# want to re-write on each individual .py file
@@ -31,19 +32,39 @@ def disp_msg(string):
print(string)
bpy.ops.message.messagebox('INVOKE_DEFAULT', message = string)
-# select object and its children
-def select_obj(scene, obj, recursive):
+# select object and its children in the interaction mode specified
+def select_obj(obj, recursive, interact_mode):
- # select an area
- bpy.ops.object.select_all(action='DESELECT')
- scene.objects.active = None
- obj.select = True
+ # get the object scene
+ scene = obj.users_scene[0]
+
+ # make it the only object selected and active
+ # multiple objects can be "selected" but only one can be "active"
+ # so deselect all objects
+ for o in scene.objects:
+ o.select = False
+
+ # select the new object and set it to the selected mode 2 times lol
scene.objects.active = obj
+ obj.select = True
+ bpy.ops.object.mode_set(mode = interact_mode)
+ bpy.ops.object.mode_set(mode = interact_mode)
- # select object and its children
+ # select the children objects as well, if on object mode
if (recursive == True):
- bpy.ops.object.select_grouped(type = 'CHILDREN_RECURSIVE')
- obj.select = True
+ for child in obj.children:
+ child.select = True
+
+
+# duplicate a selected object with its children objects
+def duplicate_obj(scene, obj):
+
+ # select the object in object mode
+ select_obj(obj, True, "OBJECT")
+ # do the following lmao
+ bpy.ops.object.duplicate(linked = True)
+ bpy.ops.object.make_single_user(type = 'SELECTED_OBJECTS', object = True, obdata = True)
+ select_obj(scene.objects.active, False, "OBJECT")
# transf_apply_recurse function
# transform_apply the parent and its child meshes
@@ -51,18 +72,18 @@ def select_obj(scene, obj, recursive):
def transf_apply_recurse(scene, obj, loc, rot, sca):
# select obj
- select_obj(scene, obj, False)
+ select_obj(obj, False, "OBJECT")
bpy.ops.object.transform_apply(location = loc, rotation = rot, scale = sca)
# armature child mesh scaling
if (len(obj.children) != 0):
for child in obj.children:
# select child and apply transform
- select_obj(scene, child, False)
+ select_obj(child, False, "OBJECT")
bpy.ops.object.transform_apply(location = loc, rotation = rot, scale = sca)
# select parent object at the end
- select_obj(scene, obj, False)
+ select_obj(obj, False, "OBJECT")
# set a bone bind matrix
def set_bone_bind_mat(bone, mat):