Hello, I’m trying to create a batch file that will run an export script of mine when Blender launches.
The .bat itself seems to run correctly, and what I’ve done is have it launch blender with a .blend file selected, and a python script. Unfortunately, it doesn’t like when I say “from . import ExportModel”. It seems that it doesn’t know where “.” points to. The error I get is:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 2, in <module>
SystemError: Parent module '' not loaded, cannot perform relative import
My question is: how can I rephrase the “from . import x” statement to import an addon in the blender scripts directory?
I’m sorry, I don’t understand. What I’m trying to do is run Blender from command line with some parameters so it opens a .blend file, runs an exporter add-on I’ve written, then closes. I guess I’m just wondering how to make use of the -P argument without running into this restricted access error.
So you basically want to load a .blend in background mode, ensure your exporter addon is activated, then execute a python script that calls an operator of your addon?
You should avoid any access to bpy.data and bpy.context in register() or functions you call from there in your addon. You should access them in the operator’s execute() method only, or in the python script you wanna execute after loading your .blend on the command line.