pense-bête de bruno sanchiz

Accueil > Blender > blender365 python

blender365 python

Publié le 12 février 2024, dernière mise-à-jour le 20 mai 2024, 7 visites, visites totales.

import bpy

RÉSUMÉ

   
def Reesumee():
    for nom in ["actions" , "armatures" , "brushes" , "cache_files" , "cameras" , "collections" , "curves"  , "fonts" , "grease_pencils" , "hair_curves" , "images" , "lattices" , "libraries" , "lightprobes" , "lights" , "linestyles" , "masks" , "materials" , "meshes" , "metaballs" , "movieclips" , "node_groups" , "objects" , "paint_curves" , "palettes" , "particles" , "pointclouds" , "scenes" , "screens" , "shape_keys" , "sounds" , "speakers" , "texts" , "textures" , "volumes" , "window_managers" , "workspaces" , "worlds"    ]:
        _collection=eval("bpy.data."+nom)
        if len(_collection) != 0 :
            print(nom,len(_collection),"élément"+"s"*(len(_collection)>1) )

SCENES

_scene=bpy.data.scenes["Scene"]

COLLECTIONS

_collection=_scene.collection
def SousCollections(collection):
    return collection.children
def SelectionneObjetsDUneCollection(collection):
    return collection.select_all()

OBJETS

<class 'bpy_types.Object'>
_objets=bpy.data.objects
_NomsDesObjets=[obj.name  for obj in _objets]

def ReesumeeDesObjets(_NomsDesObjets=None):

    _objets=bpy.data.objects
    if _NomsDesObjets==None:        
        _NomsDesObjets=[obj.name  for obj in _objets]
    elif isinstance(_NomsDesObjets,str):
        _NomsDesObjets=[_NomsDesObjets]
    for _nom in _NomsDesObjets:
        obj=bpy.data.objects[_nom]
        print("= "*20+_nom)
        
        print(len(obj.users_collection)," obj.users_collection ",str([a.name for a in obj.users_collection]))
        
        _material_slots=obj.material_slots
        print(len(_material_slots), " material_slots", str([a.name for a in _material_slots]))

        _children=obj.children
        print(len(_children), " children", str([a.name for a in _children]))
        
        _parent=obj.parent
        if _parent==None:print("0 parent") 
        else: print("parent : ",_parent.name)

        _particle_systems=obj.particle_systems
        print(len(_particle_systems), " particle_systems", str([ms.name for ms in _particle_systems]))
        
        _modifiers=obj.modifiers
        print(len(_modifiers), " modifiers", str([ms.name for ms in _modifiers]))     

        _constraints=obj.constraints
        print(len(_constraints), " constraints", str([ms.name for ms in _constraints]))
        
                
                
        for truc in ['name',  'location',   'rotation_euler', 'rotation_mode','rotation_quaternion', 'scale', 'dimensions',   'active_material','active_material_index'   ]:
            print(truc+":",eval("obj."+truc))
        
        for truc in [ 'rigid_body', 'rigid_body_constraint', 'soft_body','animation_data']:
            _contenu=eval("obj."+truc)
            if _contenu!=None:print(truc+":",_contenu)
            else : print("pas de ",truc)
                
        #  'rotation_axis_angle', , 
        for truc in [ 'data', 'hide_render', 'lightgroup',  'parent_bone',  'pose']:
            _contenu=eval("obj."+truc)
            try:
                print(truc+":",_contenu)
            except:
                pass    
    

def SelectionneUnObjet(obj):
    obj.select_set(True)
def DeselectionneUnObjet(obj):
    obj.select_set(False)

def SelectionneUnSeulObjet(obj):
    for o in bpy.data.objects:
        DeselectionneUnObjet(o)
    SelectionneUnObjet(obj)

def ObjetsContenantMot(mot):
    return [o for o in Objets() if mot in o.name]

BONES / POSE

copie de Armature vers Armature.001

for b in bpy.data.objects['Armature'].pose.bones:
    b2=bpy.data.objects['Armature.001'].pose.bones[b.name]

    for frame in range(11):
        print(frame)
        bpy.data.scenes['Scene'].frame_current=frame
        bpy.data.scenes['Scene'].frame_set(frame)
    
        b2.location=b.location # OU  b2.location=[0,0,0]
        b2.keyframe_insert("location",frame=frame)

        b2.rotation_mode="QUATERNION"
        b2.rotation_quaternion=b.rotation_quaternion    
        b2.keyframe_insert("rotation_quaternion",frame=frame)
        b2.scale=b.scale
        b2.keyframe_insert("scale",frame=frame)
   

MATÉRIAUX


def Materiaux():
    _Materiaux=bpy.data.materials
    return  _Materiaux
def Materiaux_Noms():
    _Materiaux_Noms=[m.name for m in Materiaux()]
    return _Materiaux_Noms

def Materiau_detruire(nom):
    if nom in Materiaux_Noms():
        bpy.data.materials.remove( bpy.data.materials[nom])

bpy.data.materials['texte'].copy()
#bpy.data.materials.new(texte.name)

obj.data.materials["name"].use_nodes=True
obj.data.materials.clear()
texte.active_material=bpy.data.materials[texte.name]  OU obj.data.materials.append(bpy.data.materials["name"])

DIFFUSE BSDF
bpy.data.materials['texte.001'].node_tree.nodes['Diffuse BSDF'].inputs[0]
    .identifier === Color
    .default_value=Vector((1.,0.,0.,1))
bpy.data.materials['texte.001'].node_tree.nodes['Diffuse BSDF'].inputs[1]
    .identifier === "Roughness"
    .default_value=0.5


graph editor

 _texte.animation_data.action === bpy.data.actions['texteAction']
_texte.animation_data.action.fcurves
 _texte.animation_data.action.fcurves[1].data_path === 'location'
texte.animation_data.action.fcurves[0].keyframe_points[0].co === Vector(())
_texte.animation_data.action.fcurves[0].keyframe_points[0].handle_left === Vector(())
 _texte.animation_data.action.fcurves[0].keyframe_points[0].handle_right === Vector(())
_texte.animation_data.action.fcurves[0].keyframe_points[0].interpolation === "LINEAR"|"BEZIER"

def CourbeLineaire(courbe):
    for point in courbe.keyframe_points:
        point.interpolation="LINEAR"
        
for o in ObjetsContenantMot("texte"):
    for courbe in o.animation_data.action.fcurves:
        CourbeLineaire(courbe)

courbe de bézier

PosLocal=CourbeDeBezier.data.splines[0].bezier_points[0].co
GaucheLocal=CourbeDeBezier.data.splines[0].bezier_points[0].handle_left
DroiteLocal=CourbeDeBezier.data.splines[0].bezier_points[0].handle_right

Global=Local+CourbeDeBezier.location



courbe=bpy.data.curves[0]=CourbeDeBezier.data
def transforme_point(courbe):
    spline=courbe.splines[0]
    for i in range(4):
        point=spline.bezier_points[i]
        pos=point.co
        point.co+=vector(( (-1)*pos[0]*depl() , (-1)*pos[1]*depl(),rand()/10))
        point.handle_left+=vector((rand()/5,rand()/5,rand()/10 )) 
        point.handle_right+=vector((rand()/5,rand()/5,rand()/10 ))

bpy.ops.script.python_file_run(filepath="")

[bruno sanchiz]