I recently finished making a python script for Blender, which I edited using an external editor. During development, I had a simple script running in Blender that would pull in the .py file that I was editing in sublime. It looked something like this:
This stub runs a python script relative to the currently open
blend file, useful when editing scripts externally.
import bpy
import os
Use your own script name here:
filename = “standalone_plugin.py”
filepath = os.path.join(os.path.dirname(bpy.data.filepath), filename)
global_namespace = {“file”: filepath, “name”: “main”}
with open(filepath, ‘rb’) as file:
exec(compile(file.read(), filepath, ‘exec’), global_namespace)
Now the problem is, when I try to install the plugin into a new blender file, it doesn’t work as expected. The UI seems fine, but a big part of the plugin is how it translates objects, and the translations are all happening incorrectly.
I can also replicate this problem if I create a new Blender file, and import the script with the snippet attached above. It seems like there’s something about the original file that is getting the plugin to work.
The only difference I can find is in the “scene” tab, under “custom properties”, my original (working) blender file has a property called “my_tool”. If I delete this, my file stops working too (even though running the script adds the same property “my_tool” again).
Very confused by this and I’d appreciate your help on fixing this. I’ve attached a screenshot of the correct outcome, and the outcome I get in new .blend files.
Correct result - builds a physics structure
Incorrect - weird structure whenever I open the script in a new blender file