feat: attribute dump function
refactor: cleanup utils
This commit is contained in:
@ -19,8 +19,6 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
import time
|
||||
from uuid import uuid4
|
||||
@ -35,17 +33,6 @@ from .libs import dump_anything
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.WARNING)
|
||||
|
||||
def has_action(target):
|
||||
return (hasattr(target, 'animation_data')
|
||||
and target.animation_data
|
||||
and target.animation_data.action)
|
||||
|
||||
|
||||
def has_driver(target):
|
||||
return (hasattr(target, 'animation_data')
|
||||
and target.animation_data
|
||||
and target.animation_data.drivers)
|
||||
|
||||
|
||||
def find_from_attr(attr_name, attr_value, list):
|
||||
for item in list:
|
||||
@ -73,19 +60,6 @@ def get_datablock_users(datablock):
|
||||
return users
|
||||
|
||||
|
||||
def random_string_digits(stringLength=6):
|
||||
"""Generate a random string of letters and digits """
|
||||
lettersAndDigits = string.ascii_letters + string.digits
|
||||
return ''.join(random.choices(lettersAndDigits, k=stringLength))
|
||||
|
||||
|
||||
def randomColor():
|
||||
r = random.random()
|
||||
v = random.random()
|
||||
b = random.random()
|
||||
return [r, v, b]
|
||||
|
||||
|
||||
def clean_scene():
|
||||
for type_name in dir(bpy.data):
|
||||
try:
|
||||
@ -96,76 +70,10 @@ def clean_scene():
|
||||
continue
|
||||
|
||||
|
||||
def revers(d):
|
||||
l = []
|
||||
for i in d:
|
||||
l.append(i)
|
||||
|
||||
return l[::-1]
|
||||
|
||||
|
||||
def get_armature_edition_context(armature):
|
||||
|
||||
override = {}
|
||||
# Set correct area
|
||||
for area in bpy.data.window_managers[0].windows[0].screen.areas:
|
||||
if area.type == 'VIEW_3D':
|
||||
override = bpy.context.copy()
|
||||
override['area'] = area
|
||||
break
|
||||
|
||||
# Set correct armature settings
|
||||
override['window'] = bpy.data.window_managers[0].windows[0]
|
||||
override['screen'] = bpy.data.window_managers[0].windows[0].screen
|
||||
override['mode'] = 'EDIT_ARMATURE'
|
||||
override['active_object'] = armature
|
||||
override['selected_objects'] = [armature]
|
||||
|
||||
for o in bpy.data.objects:
|
||||
if o.data == armature:
|
||||
override['edit_object'] = o
|
||||
|
||||
break
|
||||
|
||||
return override
|
||||
|
||||
|
||||
def get_selected_objects(scene, active_view_layer):
|
||||
return [obj.uuid for obj in scene.objects if obj.select_get(view_layer=active_view_layer)]
|
||||
|
||||
|
||||
def load_dict(src_dict, target):
|
||||
try:
|
||||
for item in src_dict:
|
||||
# attr =
|
||||
setattr(target, item, src_dict[item])
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
pass
|
||||
|
||||
|
||||
def dump_datablock_attibutes(datablock=None, attributes=[], depth=1, dickt=None):
|
||||
if datablock:
|
||||
dumper = dump_anything.Dumper()
|
||||
dumper.type_subset = dumper.match_subset_all
|
||||
dumper.depth = depth
|
||||
|
||||
datablock_type = datablock.bl_rna.name
|
||||
|
||||
data = {}
|
||||
|
||||
if dickt:
|
||||
data = dickt
|
||||
for attr in attributes:
|
||||
try:
|
||||
data[attr] = dumper.dump(getattr(datablock, attr))
|
||||
except:
|
||||
pass
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def resolve_from_id(id, optionnal_type=None):
|
||||
for category in dir(bpy.data):
|
||||
root = getattr(bpy.data, category)
|
||||
|
Reference in New Issue
Block a user