init.py and menu.py are executed by the interpreter rather than imported as
modules, which is why __file__ doesn't work. You can use the inspect module
to retrieve the path to the currently executing script though:
import inspect
path = inspect.getfile(inspect.currentframe())
However, you should seriously consider factoring your color bootstrapping
code into a central module so you don't have to worry about maintaining many
parallel copies.
Hope this helps.
-Nathan
-----Original Message-----
From: Dan Rosen
Sent: Wednesday, October 17, 2012 10:35 AM
To: Foundry
Subject: [Nuke-python] init.py abspath
Hello,
I'd like to figure out the absolute path to the currently executed
init.py or menu.py when nuke is loading. I am trying to define the
show by path for these files dynamically at load time rather than hard
code the show name. For example I can have my per show init.py
register the Viewer gizmo based on the path that the init.py is in
versus hard coding it. We also do some databasing for this, but I'm
testing this out to see if I can quickly implement a new show by
simply dropping in another directory with some of these dynamic
components.
I think that "__file__" doesn't work on OSX? and/or it's a different
mentality when Nuke loads the init.py versus running python at the
Terminal.
this file:
/Tools/Settings/nuke/nuke_EEPShows/hrd/init.py
registers the show colorspace gizmo:
nuke.ViewerProcess.register("hrd_cSpace", nuke.Node, ("hrd_cSpace", ""))
but could be something dynamic like?:
path = os.path.abspath(os.path.dirname(__file__))
pathParts = path.split(os.sep)
show_cSpace = pathParts[5] + "_cSpace"
nuke.ViewerProcess.register(show_cSpace, nuke.Node, (show_cSpace, ""))
thx
Dan
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python