# How to prevent bloated .blend files from storage of un-necessary internal python files

Note: This is a long read, and I've mostly resolved my problem. Your reasons for reading it will be curiosity about a limited critical analysis of blender, or the desire to set me straight if for some reason some part of my understanding is very wrong. ..I'm sure there is a better title for the post.

As a result of a long convoluted process, I realized that my .blend files were horribly bloated. This post put me onto the reason why. I discovered that each time I load a python file into the blender editor from outside the .blend file, an instance of that file is added to the internal text files stored by that .blend. If, instead, I use the alternate load option, that goes and gets the file from the "library" of internal text files, it just gets loaded up, no problem.

This question is going to be a bit rambling because most of it's purpose is to allow me to confirm my understanding of how things work, and why.

My understanding of why internal text-blocks (and internal data-blocks in general) exist is so that everything can be said to be well-organized. You do a whole ton of work, and at the end, you have one nice well-organized file. As opposed to a whole directory of different kinds of file, such that it becomes much easier to just miss something if you want to take your work elsewhere. You change operating system, computer, you need a backup, you need to send your work to somebody, etc.

Now.. what happens when I have, say 50 different .py files, all of which are parts of a larger program? And they all get imported by a master program? If I'm regularly editing them, changing them, I need to have all of them open somewhere somehow. I'm currently using multiple instances of blender to do this. Each blender window has a theme, and contains text-editor tabs with the different .py files of that theme. I could do all this instead with external text editors, but I've got used to using blender's editor. If people here end up staring at me like I'm some kind of alien, (people give me compelling reasons to..), I could switch over to using (one or multiple) external editors.

One obvious problem with the way I'm doing it is that I know how to import .py files into my (internal) script from -external- files, as modules with callable functions (def's), but I -don't- know how to import these same files, so that I can call these def's, from -internal- files. [Now, maybe that's actually the default way of doing things.. (importing from -external- files) ->you -do- have to perform the import, after all.] Now, you might not think that is a problem at all. Just import your files from the list of files external to your .blend file. [Problem: That (partially) negates the benefit of having all your files nicely organized within the .blend file.]

The real problem here, as I see it, is that this system, as designed, forces you to have duplicates of your files. It seems like in order to have a complex program, all the components of it -must- be stored external to the .blend file. On the other hand, in order to have these files opened in the blender editor for editing, they must -also- be stored inside the .blend file that contains the editor you're using for that file.

It also means that if you want to edit a certain file within a given blender window, (remember what I said about each blender window having a theme with related parts of the larger program?), and it isn't currently stored there internally, (and you've forgotten that), you first check for that code in the part of the editor that lists codes stored internally, and if it isn't there, you have to go to the other part of the editor and load it in from the external files. Again, this isn't really a huge problem, it's just a small amount of inefficiency.

Anybody who has read this far will probably call me a nit-picker, and they're probably right. So far, this whole thing originated from my ending up with massive .blend files because they were storing thousands of .py text files because I kept on loading up parts of my program from the external files, not realizing that I -should- be loading them up from the -internal- files [at which point, if that file had been changed by some other program, it would inform me -again, small amounts of time lost confirming that yes, indeed, I -do- want the updated file], which meant that it added a numbered copy of that file internally. So I ended up, essentially, with .blend files that each contained a whole long list of backups. (I have plenty of those already) :-)

It concludes with some relatively simple ways I can change the way I do things (open files the right way, only edit them in one place), and the big question of whether I should abandon the blender text-editor entirely. I've seen opinions that there are other much more powerful editors available. As for dealing with my bloated files, I'm just going to delete them. (After re-creating their essentials in other files). I've read enough posts expounding on the difficulty of effectively cleaning them up. Yay! Problem solved! :-D

• are you familiar with the Reload command in the [text editor]? Also, you probably shouldn't load whole files in Python, you might want to import the parts you want instead. Apr 24 at 14:53
• @MartyFouts Thank's for the link! I'll check out the reload command, and see if I find anything that surprises me. For importing, two comments: 1) I'm about to overhaul my whole system because I suspect I'm doing it wrong. 2) for the vast majority part, everything I import are files I've written myself, so I know that I need everything in them. well.. you're right, I might not need everything in them -everywhere-.. interesting point. The main thing I import currently as "bludgeon" import is numpy.. thanks for the tips! :-D Apr 24 at 17:01
• @MartyFouts -Yes, I'm aware at least that if a file has been modified externally, it will flash a warning, and you can tell it to re-load, if that's what you mean. I can't see the point of re-loading if I don't see that warning pop up. It seems to be pretty reliable. ..As for "loading whole files" versus importing.. I'm wondering if we're getting confused.. one imports a file so it can be used but doesn't show it, the other actually displays the file so it can be edited.. Parts of files can be imported, but only whole files can be loaded.. Apr 24 at 17:06

When you load a code into the blender editor from outside the .blend file, it creates a duplicate within the .blend file. This is a feature of blender, for good or ill. -If- there is already a file within this .blend file with the same name and type, the new file will get created with an incrementing number appended to it. In other words, if you're not aware of what is going on, your .blend file will just keep growing and growing. Until it takes up huge amounts of space and takes forever to backup to, say, a usb-key. The solution is simple: Just check if the file you want to edit is already inside the .blend file, and if so, load it from there. If it's been modified externally, it will flash a warning, and you can confirm that you want to load the new version.