Maniphest T63665

Auto Run Python Scripts not working
Closed, Archived

Assigned To
Campbell Barton (campbellbarton)
Authored By
Tom Wilson (hedgehog90)
Apr 16 2019, 8:47 PM
Tags
  • BF Blender
Subscribers
Campbell Barton (campbellbarton)
Jacques Lucke (JacquesLucke)
Sebastian Parborg (zeddb)
Stephen Swaney (stiv)
Tom Wilson (hedgehog90)

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?

Related Objects

Mentioned Here
rBdc8dd2435146: PyAPI: remove support for importing text blocks as modules
rB9099305771ec: Cleanup: rename BLI_kdtree vars & args for clarity

Event Timeline

Tom Wilson (hedgehog90) created this task.Apr 16 2019, 8:47 PM
Tom Wilson (hedgehog90) updated the task description.
Tom Wilson (hedgehog90) added a comment.EditedApr 16 2019, 10:14 PM

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.

Tom Wilson (hedgehog90) changed the task status from Unknown Status to Archived.Apr 16 2019, 10:15 PM
Tom Wilson (hedgehog90) changed the task status from Archived to Unknown Status.Apr 16 2019, 10:36 PM
Jacques Lucke (JacquesLucke) added subscribers: Campbell Barton (campbellbarton), Jacques Lucke (JacquesLucke).Apr 17 2019, 1:53 PM

Hm, not sure if this is a bug or intentional. Maybe @Campbell Barton (campbellbarton) knows.

Sebastian Parborg (zeddb) added a subscriber: Sebastian Parborg (zeddb).EditedApr 17 2019, 2:38 PM

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__.

Jacques Lucke (JacquesLucke) added a comment.Apr 17 2019, 2:40 PM

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

Stephen Swaney (stiv) added a subscriber: Stephen Swaney (stiv).Apr 17 2019, 4:50 PM
In T63665#662188, @Jacques Lucke (JacquesLucke) wrote:

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':
Campbell Barton (campbellbarton) changed the task status from Unknown Status to Unknown Status.Apr 18 2019, 3:04 PM
Campbell Barton (campbellbarton) claimed this task.

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