Skip to content

Feature: Sanitize Object and Mesh Names for Filesystem Compatibility #11

@Rakadeja

Description

@Rakadeja
Image

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_? becomes MyFont__QuestionMark
  • MyFont_: becomes MyFont__Colon

Implementation Plan

  1. 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
    }
  2. 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.

  3. Integrate into Naming Logic: In the execute method of the BF2M_OT_Generate operator, pass the generated character through 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}"

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestfeature

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions