use prefix for custom properties

This commit is contained in:
themancalledjakob 2024-08-14 14:57:34 +02:00
parent d1d71f03ad
commit 409e06bd44
3 changed files with 58 additions and 9 deletions

View file

@ -372,7 +372,7 @@ class ABC3D_PT_TextManagement(bpy.types.Panel):
continue continue
remove_me = True remove_me = True
for c in t.text_object.children: for c in t.text_object.children:
if len(c.users_collection) > 0 and (c.get('linked_textobject')) != type(None) and c.get('linked_textobject') == t.text_id: if len(c.users_collection) > 0 and (c.get(f"{utils.prefix()}_linked_textobject")) != type(None) and c.get(f"{utils.prefix()}_linked_textobject") == t.text_id:
remove_me = False remove_me = False
# not sure how to solve this reliably atm, # not sure how to solve this reliably atm,
# we need to reassign the glyph, but also get the proper properties from glyph_properties # we need to reassign the glyph, but also get the proper properties from glyph_properties
@ -394,6 +394,14 @@ class ABC3D_PT_TextManagement(bpy.types.Panel):
remove_list.append(i) remove_list.append(i)
for i in remove_list: for i in remove_list:
if type(abc3d_data.available_texts[i].text_object) != type(None):
del mom[f"{utils.prefix()}_linked_textobject"]
del mom[f"{utils.prefix()}_font_name"]
del mom[f"{utils.prefix()}_face_name"]
del mom[f"{utils.prefix()}_font_size"]
del mom[f"{utils.prefix()}_letter_spacing"]
del mom[f"{utils.prefix()}_orientation"]
del mom[f"{utils.prefix()}_translation"]
abc3d_data.available_texts.remove(i) abc3d_data.available_texts.remove(i)
for i, t in enumerate(abc3d_data.available_texts): for i, t in enumerate(abc3d_data.available_texts):
@ -531,7 +539,13 @@ class ABC3D_OT_LoadInstalledFonts(bpy.types.Operator):
scene = bpy.context.scene scene = bpy.context.scene
butils.load_installed_fonts() butils.load_installed_fonts()
butils.ShowMessageBox("Loading Fonts",
'INFO',
"Updating Data Structures.")
butils.update_available_fonts() butils.update_available_fonts()
butils.ShowMessageBox("Loading Fonts",
'INFO',
"Done loading installed fonts.")
return {'FINISHED'} return {'FINISHED'}
@ -612,6 +626,20 @@ class ABC3D_OT_PlaceText(bpy.types.Operator):
bl_label = "Place Text" bl_label = "Place Text"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
# t.font_name = font_name
# t.face_name = face_name
# t.text_object = selected
# t.text = scene.abc3d.text
# t.letter_spacing = scene.abc3d.letter_spacing
# t.font_size = scene.abc3d.font_size
# t.translation = scene.abc3d.translation
# t.orientation = scene.abc3d.orientation
# t.distribution_type = distribution_type
# def invoke(self, context, event):
# wm = context.window_manager
# return wm.invoke_props_dialog(self)
def execute(self, context): def execute(self, context):
global shared global shared
scene = bpy.context.scene scene = bpy.context.scene

View file

@ -407,7 +407,6 @@ def load_font_from_filepath(filepath):
o_exists = True o_exists = True
try: try:
o, o.name o, o.name
except ReferenceError as e: except ReferenceError as e:
o_exists = False o_exists = False
if o_exists and o.name not in allObjectsBefore: if o_exists and o.name not in allObjectsBefore:
@ -449,10 +448,13 @@ def load_font_from_filepath(filepath):
# f.font_name = font_name # f.font_name = font_name
# f.face_name = face_name # f.face_name = face_name
# print(f"{__name__} added {font_name} {face_name}") # print(f"{__name__} added {font_name} {face_name}")
else: elif o_exists:
remove_list.append(o) remove_list.append(o)
for o in remove_list: for o in remove_list:
try:
bpy.data.objects.remove(o, do_unlink=True) bpy.data.objects.remove(o, do_unlink=True)
except ReferenceError as e:
print(f"{__name__} could not remove object, because it doesn't exist")
print(f"{__name__}: loaded font from {filepath}") print(f"{__name__}: loaded font from {filepath}")
update_available_fonts() update_available_fonts()
@ -600,8 +602,8 @@ def set_text_on_curve(text_properties):
regenerate = True regenerate = True
elif len(text_properties.text) > i and g.glyph_id != text_properties.text[i]: elif len(text_properties.text) > i and g.glyph_id != text_properties.text[i]:
regenerate = True regenerate = True
elif len(text_properties.text) > i and (g.glyph_object['font_name'] != text_properties.font_name elif len(text_properties.text) > i and (g.glyph_object[f"{utils.prefix()}_font_name"] != text_properties.font_name
or g.glyph_object['face_name'] != text_properties.face_name): or g.glyph_object[f"{utils.prefix()}_face_name"] != text_properties.face_name):
regenerate = True regenerate = True
if len(text_properties.text) != len(text_properties.glyphs): if len(text_properties.text) != len(text_properties.glyphs):
@ -660,9 +662,9 @@ def set_text_on_curve(text_properties):
ob = None ob = None
if regenerate: if regenerate:
ob = bpy.data.objects.new(f"{glyph_id}", glyph.data) ob = bpy.data.objects.new(f"{glyph_id}", glyph.data)
ob['linked_textobject'] = text_properties.text_id ob[f"{utils.prefix()}_linked_textobject"] = text_properties.text_id
ob['font_name'] = text_properties.font_name ob[f"{utils.prefix()}_font_name"] = text_properties.font_name
ob['face_name'] = text_properties.face_name ob[f"{utils.prefix()}_face_name"] = text_properties.face_name
else: else:
ob = text_properties.glyphs[i].glyph_object ob = text_properties.glyphs[i].glyph_object
@ -732,6 +734,13 @@ def set_text_on_curve(text_properties):
if regenerate: if regenerate:
mom.select_set(True) mom.select_set(True)
mom[f"{utils.prefix()}_linked_textobject"] = text_properties.text_id
mom[f"{utils.prefix()}_font_name"] = text_properties.font_name
mom[f"{utils.prefix()}_face_name"] = text_properties.face_name
mom[f"{utils.prefix()}_font_size"] = text_properties.font_size
mom[f"{utils.prefix()}_letter_spacing"] = text_properties.letter_spacing
mom[f"{utils.prefix()}_orientation"] = text_properties.orientation
mom[f"{utils.prefix()}_translation"] = text_properties.translation
bpy.context.view_layer.objects.active = mom bpy.context.view_layer.objects.active = mom
bpy.ops.object.parent_set(type='OBJECT') bpy.ops.object.parent_set(type='OBJECT')

View file

@ -1,3 +1,15 @@
def get_version_major():
return 0
def get_version_minor():
return 0
def get_version_patch():
return 1
def get_version_string():
return f"{get_version_major()}.{get_version_minor()}.{get_version_patch}"
def prefix():
return "ABC3D"
import time import time
import datetime import datetime
from mathutils import ( from mathutils import (