Python
- Ctrl+Spacebar to Autocomplete in the console
- bpy.context = C
- bpy.data = D
- For rigging. need to be in the edit mode to add a bone
valueIfTrue if isConditionTrue else valueIfFalse
# Switching Modes
import bpy
from bpy import context
to_mode = 'XYZ'
for pb in context.selected_pose_bones:
pb.rotation_mode = to_mode
bpy.context.scene_Frame.current
bpy.ops.render.render(use_viewport=True)
bpy.data.scenes["Scene"].render.filepath
for f in mesh.polygons:
for i in f.loop_indices:
l = mesh.loops[i]
v = mesh.vertices[ l.vertex_index ] #the right vertex
map = mesh.uv_layers['UVMap'].data[i] #the right uv mapping
bpy.ops.object.mode_set(mode='POSE')
import bpy
bpy.ops.import_scene.gltf(filepath="C:/Users/Luke/Desktop/Blender_Dota/props_debris/battle_debris1.gltf", filter_glob="*.glb;*.gltf", loglevel=0, import_pack_images=False, import_shading='NORMALS')
import bpy
bpy.ops.wm.save_as_mainfile(filepath="C:/Users/Luke/Desktop/save_test.blend")
import bpy
bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
bpy.ops.wm.open_mainfile(filepath=bpy.data.filepath)
import bpy
old_armature = bpy.data.objects['metarig_old']
new_armature = bpy.data.objects['metarig_new']
old_bone_list = old_armature.pose.bones
for old_bone in old_bone_list:
if old_bone.constraints:
for old_constraint in old_bone.constraints:
if old_constraint.target.type == 'ARMATURE':
new_bone = new_armature.pose.bones[old_bone.name]
new_constraint = new_bone.constraints.new(old_constraint.type)
new_constraint.target = old_constraint.target
new_constraint.subtarget = old_constraint.subtarget
new_constraint.target_space = old_constraint.target_space
new_constraint.owner_space = old_constraint.owner_space
new_constraint.invert_x = old_constraint.invert_x
new_constraint.invert_x = old_constraint.invert_y
new_constraint.invert_x = old_constraint.invert_z
else:
pass
else:
pass
import bpy
armature = bpy.data.objects['Armature_proxy']
bone_list = armature.pose.bones
for bone in bone_list:
print (bone.name)
if bone.constraints:
for constraint in bone.constraints:
print (constraint.target)
print (constraint.target.__dir__())
if constraint.target.type == 'ARMATURE':
print ("yahoo")
break
constraints.subtarget
import bpy
modify parameters
bpy.data.objects['Cube'].location = (1,2,3)
retrieve selected object
bpy.context.active_object
or
bpy.data.objects
C.selected_objects (Selected objects)
bpy.data.objects (All objects)
for ob in bpy.data.objects: print (ob.name)
for ob in bpy.context.selected_objects: ob.scale = [2,2,2]
bpy.data.objects = list all objects of all scenes
bpy.context.scene.objects = list object in the selected scene.
#modal
def modal(self,context,event):
# Free navigation
if event.type == 'MIDDLEMOUSE' and event.value == 'RELEASE':
print('release',self.mouse_pos)
return{'RUNNING_MODAL'}
elif event.type == 'MIDDLEMOUSE' and event.value == 'PRESS':
self.mouse_pos = (event.mouse_region_x, event.mouse_region_y)
print('mouse down', self.mouse_pos)
return {'PASS_THROUGH'}
# Confirm
elif event.type == 'LEFTMOUSE' and event.value == 'PRESS':
return {'FINISHED'}
# Cancel
elif event.type == 'RIGHTMOUSE' and event.value == 'PRESS':
self.modifier.thickness = self.original_thickness
if self.created_modifier == True:
self.obj.modifiers.remove(self.modifier)
return {'CANCELLED'}
# Adjust
elif event.type == 'MOUSEMOVE':
delta = event.mouse_x - event.mouse_prev_x
delta = delta / self.divisor
if event.shift:
delta /= 5
self.modifier.thickness += delta
return {"RUNNING_MODAL"}