22
$\begingroup$

How can I remove personal data from a .blend file?

I was asked to upload a .blend file in order to reproduce the issue. I removed all objects from the scene as far as possible and also removed all Python code as far as possible. This is good: it makes the file small, the sources for potential problems are eliminated and you can focus on the real problem.

However, when I look at the .blend file with Notepad or a Hex editor, it shows many paths on my system, which include my user name and other information. Note that I don't have any external references to files (like textures).


For this time, I can replace the personal data in a Hex editor, however, this is not a good approach in general, because

  • it only works as long as the file format does not use a checksum to verify the integrity of the file. (So I'm lucky it works for .blend files)
  • it only works as long as the file is not compressed, because changing a compressed file breaks the compression. (Strange enough that the .blend file is still the same even if I use compression)
  • if you accidentally delete a character (so that the file becomes smaller), the file becomes invalid
  • you need to know in advance what you're looking for (you need to know the search term) - and there might be many
  • it's a lot of work to do for something which doesn't bring additional benefit
$\endgroup$
6
  • $\begingroup$ What happens if you delete the references to the paths. $\endgroup$
    – Vader
    Apr 8, 2014 at 11:39
  • $\begingroup$ @Vader: It is possible to replace it, not to delete it. I can do it that way this time, but see my updated question for the reasons I'd not like doing that in the future. $\endgroup$ Apr 8, 2014 at 12:20
  • $\begingroup$ What about re-opening the file after restarting blender, and saving it out again? Not sure if this will do anything, but I'm guessing it may clear any data it doesn't need. $\endgroup$
    – Greg Zaal
    Apr 8, 2014 at 12:31
  • $\begingroup$ When you say many paths, what do you mean? I checked a file and only found 3 occurrences of my username, having saved the file on my Desktop. $\endgroup$
    – iKlsR
    Apr 8, 2014 at 13:56
  • $\begingroup$ @iKlsR: I have received the file of a colleague. The file contains paths from my PC as well as his PC. One of them refers to my Desktop, although I didn't save the file on the Desktop. In total I have 7 paths (not necessarily different) in the file which I could immediately identify as personal data. I have 10 occurrences of `C:`, which at least identifies me as a Windows user. $\endgroup$ Apr 8, 2014 at 14:07

3 Answers 3

10
$\begingroup$

As far as I know, there is no way to strip this information from a .blend file without editing the file itself as you have done and that has its own set of cons.

Option 1

Work at the root directory of your system. ie. C:/personal_folder/ or on a portable medium. You say you don't have any images or such attached so this shouldn't log anything private such as your username or any other personal paths provided you don't import anything and all you have is a model.

Option 2

Export to another format and reimport back into Blender. Exporting to a simple format such as .obj will only export mesh data (if all you have is a mesh) and same goes for importing it back. I did this with a file saved on my desktop and the only instance I could find with personal info was the location to the file. Use this with method 1 for optimal results.

As it addresses your other privacy concerns, being identified as to what OS you're on is fairly useless information and if you're sharing a file here, you might even be asked what os you are running so provided that no personal paths are included you should be fine.

$\endgroup$
3
$\begingroup$

Quick Answer:

You can use the python scripting tools to remove filepaths with a single button press. The script below will add a button to the topbar in File > Clean Up > Clear Filepaths to replace all filepaths in the file with the letter b.

import bpy
from bpy.utils import register_class, unregister_class

bl_info = {
    "name" : "Clear Blender Filepaths",
    "location" : "Top toolbar > File > Clean Up > Clear Blender Filepaths",
    "description" : 'Removes personal filepaths from your blender file',
    "blender" : (3, 6, 2),
    "category" : "System",
}

class cbf(bpy.types.Operator):
    bl_label = "Clear Filepaths"
    bl_idname = "cbf.cleanblenderfilepaths"
    bl_description = '''Save an uncompressed copy of your .blend file with personal filepaths cleared like
"C:\\Users\\my username\\Embarassing folder name\\", and
"D:\\Personal stuff\\Oh shoot I can\'t believe this was saved to that blend file I put on Gumroad\\"'''
    def execute(self, context):

        #don't run if the file has not been saved yet
        if not bpy.data.filepath:
            return {'FINISHED'}
        
        #save the file as an uncompressed file next to the original
        bpy.ops.wm.save_as_mainfile(filepath = bpy.data.filepath.replace('.blend', '_cleaned.blend'), compress = False, relative_remap = False)

        #collect all filepaths
        filepath_list = []
        def add(this):
            if this and (this not in filepath_list):
                filepath_list.append(this)
        
        for cat in [bpy.data.images,
                    bpy.data.objects,
                    bpy.data.linestyles,
                    bpy.data.materials,
                    bpy.data.node_groups,
                    bpy.data.texts,
                    bpy.data.cameras,
                    bpy.data.lights,
                    bpy.data.meshes]:
            for item in cat:
                for check in ['filepath', 'filepath_raw']:
                    if getattr(item, check, None):
                        add(getattr(item, check, None))
                    if getattr(item, 'original', None):
                        if getattr(item.original, 'filepath', None):
                            add(item.original.filepath)
                    if getattr(item, 'library_weak_reference', None):
                        if getattr(item.library_weak_reference, 'filepath', None):
                            add(item.library_weak_reference.filepath)
                    if getattr(item, 'packed_files', None):
                        for packed_file in getattr(item, 'packed_files', []):
                            if getattr(packed_file, 'filepath', None):
                                add(packed_file.filepath)     
                                    
        add(bpy.data.filepath)
        add(bpy.context.scene.render.filepath if bpy.context.scene.render.filepath != '/tmp\\' else None)

        #read the whole file in and check for any filepath instances
        original_filepath = bpy.data.filepath
        file = open(original_filepath, 'rb')
        raw_data = file.read()
        for path in filepath_list:
            raw_data = raw_data.replace(path.encode(), b'b'*len(path))
        
        file.close()
        #overwrite the file with filepaths replaced as 'bbbbbbb'
        file = open(original_filepath, 'wb')
        file.write(raw_data)
        file.close()

        #close blender so the cleaned file is not accidentally overwritten
        bpy.ops.wm.quit_blender()
        return {'FINISHED'}

def menu_draw(self, context):
        self.layout.operator("cbf.cleanblenderfilepaths")

def wrap(register_bool):
    register_class(cbf) if register_bool else unregister_class(cbf)
    bpy.types.TOPBAR_MT_file_cleanup.append(menu_draw) if register_bool else bpy.types.TOPBAR_MT_file_cleanup.remove(menu_draw)

def register():
    wrap(True)

def unregister():
    wrap(False)

if __name__ == "__main__":
    register()

Longer answer:

Despite being an open source program, there seems to be little information on this topic, and this page has the most info I’ve found on PII in a .blend file so let’s sum up all the info and add some more.

  • Editing an uncompressed save file for filepaths is possible if the resources are packed into the blend file, but you need to know exactly what you’re looking for.
  • Editing a compressed save file seems to be possible as long as the amount of characters in the filepath remains the same. However, editing a compressed file will lead to the hex editor missing a path due to compression obfuscating some filepath strings. I have manually edited a compressed save file and removed all instances of any relative or absolute filepaths, but I reopened the compressed file in blender and was still able to access the library_weak_reference.filepath attribute that contained one of the directories I just removed in the hex editor.
  • Working in a higher up directory will still save those directory names to the blend file, and the blend file can still be “contaminated” if you import or append something from a .blend file located in a personal directory containing your username. Exporting everything to a different format then reimporting works but is not feasible for large projects with many objects that would have to be reimported. All materials would also have to be recreated from scratch (see library_weak_reference issue below, this would apply to appended materials)
  • It may have worked in previous versions, but for me, attempting to delete a DATA block containing a personal filepath in a Blender 3.6 save file resulted in blender just loading the default scene. I’m guessing Blender thought the file was corrupt and didn’t attempt to load it.

So in a typical usage scenario it looks like it is unavoidable to have filepaths in the .blend file. How can you know what filepaths are being used in the file? And can you edit them in Blender itself? From what I’ve gathered, there are a few places to look in blender for filepaths using the python api:

  • The current file’s directory accessed with bpy.data.filepath (not completely sure if this is saved to the .blend)
  • The render output filepath accessed with bpy.context.scene.render.filepath
  • Absolute and Relative directories where images were imported from (accessed with bpy.data.images[0].filepath, and bpy.data.images[0].original.filepath)
  • Absolute and Relative directories from packed images accessed with bpy.data.images[0].packed_files[0].filepath
  • Filepaths to other .blend files from which objects, meshes, node_groups, materials, etc were appended from (check bpy.data.objects[-1].library_weak_reference.filepath after appending an object and it will show you the filepath to the blend file you imported it from)

Filepath variables can be set using Blender’s python api, but library_weak_reference filepaths are read only, so we are forced to edit the file with a hex editor or script to remove all filepaths. That makes the process…

  • Pack all files into the blender file
  • Save the blender file as uncompressed
  • Use the Blender Python api to walk through the bpy.data structure until all filepath instances are found
  • Use a hex editor or a script (like the above python script) to clear out all filepaths found in the file with a random string of the same length (like bbb)
  • Inspect the file with a hex editor to confirm all filepaths have been removed
  • Re-open the file in blender and walk through all filepath instances again to ensure all filepaths have been removed

Using this method with what I would consider a typical file (containing multiple mesh objects with multiple materials and dozens of packed images) resulted in no personally identifiable absolute or relative paths showing in a hex editor.

$\endgroup$
0
$\begingroup$

I edited this answer as it seemed to be incorrect.

When you find personal information in your .blend file (such as folder names), you can delete the entire DATA block that includes that information and the file is likely to still work. Do this in a copy to avoid mistakes.

Using any free hex editor (such as HxDen), open the .blend file and search for the personal information that you found in the .blend file. Personal information is usually around this string: "Save As Blender", without the quotes. Try searching for it. Now click-drag select starting from and including the "DATA" word that precedes the information that you want to delete, and select all the way until you reach the next "DATA" word. Stop the selection right before the next "DATA", don't include it in the selection. Press delete, save the file, open it in Blender and save it again so that any bad formatting is restored, if there was any.

$\endgroup$
1
  • 1
    $\begingroup$ I couldnt find a way to remove my user name and home directory, so what I did was to replace it with the exact same amount of letters, for ex: /home/myusername/ became /abcdxabcdefghij/ or the file will break on loading. I did not mess with / tho (it is like that because I use linux). I did not try your method tho :>. Also better not let blender compress the file to avoid being unable to edit like that. $\endgroup$ Dec 6, 2021 at 1:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .