font3d_blender_addon/butils.py
themancalledjakob d06bf038b0 instantiate an A
2024-05-21 18:00:49 +02:00

32 lines
1.2 KiB
Python

import bpy
def get_parent_collection_names(collection, parent_names):
for parent_collection in bpy.data.collections:
if collection.name in parent_collection.children.keys():
parent_names.append(parent_collection.name)
get_parent_collection_names(parent_collection, parent_names)
return
def turn_collection_hierarchy_into_path(obj):
parent_collection = obj.users_collection[0]
parent_names = []
parent_names.append(parent_collection.name)
get_parent_collection_names(parent_collection, parent_names)
parent_names.reverse()
return '\\'.join(parent_names)
def move_in_fontcollection(obj, fontcollection, scene):
# print(turn_collection_hierarchy_into_path(obj))
if scene.collection.objects.find(obj.name) >= 0:
scene.collection.objects.unlink(obj)
if fontcollection.objects.find(obj.name) < 0:
fontcollection.objects.link(obj)
if fontcollection.objects.find("glyphs") < 0:
empty = bpy.data.objects.new("glyphs", None)
empty.empty_display_type = 'PLAIN_AXES'
fontcollection.objects.link(empty)
glyphs = fontcollection.objects.get("glyphs")
if obj.parent != glyphs:
obj.parent = glyphs