A plugin I've been working on stops working in new files.

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

Maybe need to match these in the new blends?

bpy.context.space_data.transform_orientation = 'GLOBAL'
bpy.context.space_data.pivot_point = 'CURSOR'

Change the arguments as needed.

Nice channel btw. Thanks for the tuts.

Could you define ‘to install the plugin into a new blender file’? Also it would be nice to see the actual code you need help with.

I have tried making these consistent - both files have the same setting for this.

Thank you :slight_smile:

The code doesn’t work in another file, no matter how it is used.

For example, if I open a new Blender file, go to file --> user preferences --> add-ons --> install add-on from file and select the .py file, it doesn’t work.

It also stop working if I copy and paste the code into the text editor in a new Blender file.

The reason I haven’t shared is because I’m planning to release this commercially on BlenderMarket. Would you have a look at the code if I sent you it privately?

Sure I can have a look. If I understand what’s wrong, I’ll help, but I would make an effort to describe it here publicly in general terms, so I don’t mess with your business but this thread is still useful for whoever stumbles upon it.