12
$\begingroup$

I am a keen user of Bassam's typewriter.py addon. It's not part of the official distribution, so I thought I could make my .blend projects more portable by including it as a text block.

I always need to run the block even though I checked the register checkbox. Are there any more requirements to having the .py extension that I need to do before the script will run on load?

$\endgroup$
15
$\begingroup$

Yes, if the addon is a single file (rather then a python package containing an __init__.py file).

At the end of the script, remove these two lines:

if __name__ == "__main__":
    register()

And add this line:

register()

In Python __name__ refers to the module name, which in this case is the name of the textblock (without .py, however if you run the script directly __name__ will be "__main__").

Removing this check before calling the register() function will run no matter how its executed.


Note, if you do this - The script won't be listed in the preferences as an addon, this wont cause problems, but a user has no way to disable besides restarting blender.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.