Jump to: navigation, search

Difference between revisions of "Pyhton Scripts"

(Created page with "Python scripts vault used during the project. == BoneMatrixCopy == import bpy, math from mathutils import Vector, Matrix # configuration ############ ARMATURE_NAME = 'ma...")
 
Line 22: Line 22:
 
  target.rotation_mode = 'XYZ'
 
  target.rotation_mode = 'XYZ'
 
  print( 'done, matrix of bone', armature.name, ':', bone.name, 'copied on',  target.name )
 
  print( 'done, matrix of bone', armature.name, ':', bone.name, 'copied on',  target.name )
 +
 +
== BonesAndVertexgroupsBulkRenaming ==
 +
 +
import bpy
 +
 +
# right and left markers
 +
NEEDLE = "R_"
 +
REPLACE = "L_"
 +
 +
# name of the armature and the related mesh
 +
ARMATURE_NAME = 'armature_skeleton'
 +
MESH_NAME = 'skeleton'
 +
 +
scn = bpy.context.scene
 +
armature = scn.objects[ ARMATURE_NAME ].data
 +
mesh = scn.objects[ MESH_NAME ]
 +
 +
# renaming all bones
 +
print( "armature:", ARMATURE_NAME, armature )
 +
for b in armature.bones:
 +
    b.name = b.name.replace( NEEDLE, REPLACE )
 +
    print( b.name )
 +
   
 +
# renaming all vertex groups
 +
print( "mesh:", MESH_NAME, mesh )
 +
for vg in mesh.vertex_groups:
 +
    vg.name = vg.name.replace( NEEDLE, REPLACE )
 +
    print( vg.name )
 +
 +
[https://github.com/Blender-Brussels/bpy-bge-library/blob/master/users/frankiezafe/bone_renaming.py script on github]

Revision as of 17:39, 28 March 2016

Python scripts vault used during the project.

BoneMatrixCopy

import bpy, math
from mathutils import Vector, Matrix
# configuration ############
ARMATURE_NAME = 'makehuman'
BONE_NAME = 'RightArm'
# getting the right bone, no safety net...
scn = bpy.context.scene
armature = scn.objects[ ARMATURE_NAME ].data
bone = armature.bones[ BONE_NAME ]
# orientation of the bone is represented as a 4x4 matrix
# see https://www.blender.org/api/blender_python_api_2_59_0/bpy.types.Bone.html#bpy.types.Bone.matrix_local
bone_mat = bone.matrix_local
# getting the active object
target = scn.objects.active
# copy of the matrix ############
target.matrix_local = bone_mat
target.rotation_mode = 'QUATERNION'
target.rotation_mode = 'XYZ'
print( 'done, matrix of bone', armature.name, ':', bone.name, 'copied on',  target.name )

BonesAndVertexgroupsBulkRenaming

import bpy

# right and left markers
NEEDLE = "R_"
REPLACE = "L_"

# name of the armature and the related mesh
ARMATURE_NAME = 'armature_skeleton'
MESH_NAME = 'skeleton'

scn = bpy.context.scene
armature = scn.objects[ ARMATURE_NAME ].data
mesh = scn.objects[ MESH_NAME ]

# renaming all bones
print( "armature:", ARMATURE_NAME, armature )
for b in armature.bones:
   b.name = b.name.replace( NEEDLE, REPLACE )
   print( b.name )
   
# renaming all vertex groups
print( "mesh:", MESH_NAME, mesh )
for vg in mesh.vertex_groups:
   vg.name = vg.name.replace( NEEDLE, REPLACE )
   print( vg.name )

script on github