-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: Sanitize Object and Mesh Names for Filesystem Compatibility #11
Description
Summary
Currently, the addon names generated mesh objects and their data blocks directly using the character they represent (e.g., MyFont_?, MyFont_:). While this works inside Blender, many of these characters (?, :, *, /, etc.) are illegal in filenames on most operating systems.
This becomes a critical bug when a user attempts to batch export the generated meshes, as the export operation will fail. We need to implement a robust sanitization system to replace these "unsafe" characters with filesystem-friendly text.
Current Behavior
Object and mesh names can contain characters that are incompatible with filesystems. For example, mesh_obj.name = f"{sanitized_name}_{character}".
Expected Behavior
All generated object and mesh names are sanitized, replacing special characters with a safe, descriptive string. For example:
MyFont_?becomesMyFont__QuestionMarkMyFont_:becomesMyFont__Colon
Implementation Plan
-
Create a Replacement Map: A comprehensive Python dictionary is needed to map unsafe characters to safe string representations. This map should be as extensive as possible to cover common symbols and non-ASCII characters.
# Example snippet of the replacement map REPLACEMENT_MAP = { '"': "_DoubleQuote", '*': "_Asterisk", ':': "_Colon", '<': "_LessThan", '>': "_GreaterThan", '|': "_Pipe", '?': "_QuestionMark", '\\': "_Backslash", '/': "_ForwardSlash", # and so forth }
-
Create a Sanitization Function: A helper function should be created that takes a string and the replacement map, and returns a sanitized version of the string.
-
Integrate into Naming Logic: In the
executemethod of theBF2M_OT_Generateoperator, pass the generatedcharacterthrough the new sanitization function before assigning it to the object and mesh data names.# __init__.py -> class BF2M_OT_Generate -> execute() # ... inside the loop ... character = chr(char_code) safe_character_name = sanitize_character(character, REPLACEMENT_MAP) # New function call? mesh_obj_name = f"{sanitized_name}_{safe_character_name}" mesh_obj = bpy.data.objects.new(name=mesh_obj_name, object_data=final_mesh_data) # Also sanitize the mesh data name mesh_obj.data.name = f"{char_code}_{sanitized_name}_{safe_character_name}"