Page MenuHome

Auto Run Python Scripts not working
Closed, ArchivedPublic

Description

Blender Version
Broken: blender-2.80.0-git.9099305771ec
Worked: 2.79

I have Auto Run Python Scripts enabled, Excluded Paths: empty.
I load the python file (named autorun.py) externally into the script editor and tick Register.
On loading the blend file however it simply doesn't run, I have to Alt-P it every time.
It's not throwing any errors, just to make sure I've tried with a python file consisting of print("HELLO"), but it never greets me :(
I've tried saving the file internally, Reloading it with Alt-R, absolutely nothing works.
Is this a bug or has something changed between 2.79 and 2.8 that I'm not aware of?

Details

Type
Bug

Event Timeline

Sorry, I was at fault. It's working fine.

EDIT:
Reopened, not sure if it's a bug, but I realised name equals the script name on startup (ie, if it's called run.py, it'll equal "run"), but equals "main" the rest of the time.
So the following never fires on startup:

if __name__ == "__main__":
	register()

Seems like a bug, can't find any mention of this elsewhere.

Unless this has changed, then this is how it is supposed to work: https://www.geeksforgeeks.org/__name__-special-variable-python/

On startup, the file is run by an other python module and thus the __name__ can not be __main__.

Well, technically, when you run the script using the "Run" button, it is not __main__ either.

Well, technically, when you run the script using the "Run" button, it is not __main__ either.

At the risk of looking even stupider than usual, who *is* running the script when you press "Run"?

I can see an argument for 'run at startup' vs 'press Run' being two separate use cases. It is not clear how to reconcile them. But if you want a quick hack...

if __name__ == '__main__' or __name__ == 'foo':

This was working as intended, however it added quite a lot of overhead to support importing text blocks as modules. Removed this feature, now "Run" and "Register" work the same way.

rBdc8dd24351462e73c5d0260564aad9cd56fd6c33