diff --git a/__init__.py b/__init__.py index 9ed5a48..748d638 100644 --- a/__init__.py +++ b/__init__.py @@ -660,42 +660,34 @@ class ABC3D_PT_TextPropertiesPanel(bpy.types.Panel): # and bpy.context.object.select_get(): a_o = bpy.context.active_object if a_o is not None: - if f"{utils.prefix()}_text_id" in a_o: - text_index = a_o[f"{utils.prefix()}_text_id"] - return bpy.context.scene.abc3d_data.available_texts[text_index] - elif a_o.parent is not None and f"{utils.prefix()}_text_id" in a_o.parent: - text_index = a_o.parent[f"{utils.prefix()}_text_id"] - return bpy.context.scene.abc3d_data.available_texts[text_index] - else: - for t in bpy.context.scene.abc3d_data.available_texts: - if butils.is_or_has_parent( - bpy.context.active_object, t.text_object, max_depth=4 - ): - return t + # if f"{utils.prefix()}_text_id" in a_o: + # text_id = a_o[f"{utils.prefix()}_text_id"] + # return butils.get_text_properties(text_id) + # # elif a_o.parent is not None and f"{utils.prefix()}_text_id" in a_o.parent: + # # text_id = a_o.parent[f"{utils.prefix()}_text_id"] + # # return butils.get_text_properties(text_id) + # else: + for t in bpy.context.scene.abc3d_data.available_texts: + if butils.is_or_has_parent( + bpy.context.active_object, t.text_object, max_depth=4 + ): + return t return None - def get_active_glyph_properties(self): + def get_active_glyph_properties(self, text_properties): + if text_properties is None: + return None a_o = bpy.context.active_object if a_o is not None: - if ( - f"{utils.prefix()}_text_id" in a_o - and f"{utils.prefix()}_glyph_index" in a_o - ): - text_index = a_o[f"{utils.prefix()}_text_id"] + if f"{utils.prefix()}_glyph_index" in a_o: glyph_index = a_o[f"{utils.prefix()}_glyph_index"] - return bpy.context.scene.abc3d_data.available_texts[text_index].glyphs[ - glyph_index - ] + if len(text_properties.glyphs) <= glyph_index: + return None + return text_properties.glyphs[glyph_index] else: - for t in bpy.context.scene.abc3d_data.available_texts: - if butils.is_or_has_parent( - a_o, t.text_object, if_is_parent=False, max_depth=4 - ): - for g in t.glyphs: - if butils.is_or_has_parent( - a_o, g.glyph_object, max_depth=4 - ): - return g + for g in text_properties.glyphs: + if butils.is_or_has_parent(a_o, g.glyph_object, max_depth=4): + return g return None @classmethod @@ -709,7 +701,7 @@ class ABC3D_PT_TextPropertiesPanel(bpy.types.Panel): layout = self.layout props = self.get_active_text_properties() - glyph_props = self.get_active_glyph_properties() + glyph_props = self.get_active_glyph_properties(props) if props is None or props.text_object is None: # this should not happen diff --git a/butils.py b/butils.py index 28dbd0f..fba0ef4 100644 --- a/butils.py +++ b/butils.py @@ -1301,6 +1301,8 @@ def transfer_text_object_to_text_properties( transfer_glyph_object_to_glyph_properties(glyph_object, glyph_properties) glyph_properties["glyph_object"] = glyph_object glyph_properties["glyph_index"] = glyph_index + glyph_properties["text_id"] = text_properties.text_id + glyph_object["text_id"] = text_properties.text_id inner_node = None for c in glyph_object.children: if c.name.startswith(f"{glyph_id}_mesh"):