Auto Run Python Scripts not working #63665

Closed
opened 2019-04-16 20:47:47 +02:00 by Tom Wilson · 13 comments

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?

**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?
Author

Added subscriber: @hedgehog90-3

Added subscriber: @hedgehog90-3
Author

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.

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

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Author

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'
Member

Added subscribers: @ideasman42, @JacquesLucke

Added subscribers: @ideasman42, @JacquesLucke
Member

Hm, not sure if this is a bug or intentional. Maybe @ideasman42 knows.

Hm, not sure if this is a bug or intentional. Maybe @ideasman42 knows.

Added subscriber: @ZedDB

Added subscriber: @ZedDB

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

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

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.

Added subscriber: @StephenSwaney

Added subscriber: @StephenSwaney

In #63665#662188, @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':
> In #63665#662188, @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': ```

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Campbell Barton self-assigned this 2019-04-18 15:04:23 +02:00

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.

dc8dd24351

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. dc8dd24351
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#63665
No description provided.