lately I’ve been wanting to start learning scripting so I’ve been going through a few scripts (mostly exporters) and I’ve had a few questions.
if __name__ == "__main__":
register()
I’ve seen these pop-up in the scripts that I was reading and I’m not quite sure why it’s required… I’d also like to know what exactly I should include in the register()/unregister() functions
Also looking at the povray exporter
if "bpy" in locals():
import imp
imp.reload(ui)
imp.reload(render)
else:
import bpy
from bpy.props import *
from render_povray import ui
from render_povray import render
There’s this bit of code which I’m left slightly puzzled by. Why not just do regular imports? what is “imp”? the import module? I’ve also read a post or two mentioning that one should not use “from bpy.props import *” is this true?
from what i gather when you are doing a console session to figure out how to piece together your script you can happily do a
from whatevermodule import *
but if you are writing a script that you wish to distribute, then things are a little different. You really want to have control over what you are importing. By importing * you are in danger of polluting namespace
maybe a more gratifying set of answers is found here :
Oh right, I didn’t know there was a difference between “import bpy” and “from bpy import *”
As for the addon I’m writing it’s more of a “writing” exercise than anything else but I’d still like to write it so it would be something that could be handed out to others.
So far it really doesn’t do much but in case you’re curious here it is: