Hi Nathan, thanks for the suggestion. Works like a breeze.
Cheers, Sebastian On Friday, November 7, 2014, Nathan Rusch <nathan_ru...@hotmail.com> wrote: > You probably also want to call os.path.abspath after joining everything: > > path = os.path.abspath(os.path.join(os.path.dirname(callingFile), path)) > > > *From:* Nathan Rusch > <javascript:_e(%7B%7D,'cvml','nathan_ru...@hotmail.com');> > *Sent:* Friday, November 07, 2014 6:18 PM > *To:* Nuke Python discussion > <javascript:_e(%7B%7D,'cvml','nuke-python@support.thefoundry.co.uk');> > *Subject:* Re: [Nuke-python] Using the Nuke resolution of relative > filenames > > I don't think it's doing anything special to resolve the relative > filenames... I think it just keeps track of where the current init.py is > being executed from, and resolves non-absolute paths relative to that. > > You can do pretty much the same thing from within your customAdd function > by pulling the calling file from the stack: > > import inspect > import os > > def customAdd(path): > if not os.path.isabs(path): > callingFile = inspect.getfile(inspect.currentframe(1)) > path = os.path.join(os.path.dirname(callingFile), path) > # Do something with full path... > > > This obviously won't work for calls to customAdd from the script editor, > but nuke.pluginAddPath doesn't resolve relative paths at that point either, > so you wouldn't be skipping over any functionality. > > Hope this helps. > > -Nathan > > > *From:* Sebastian Kral > <javascript:_e(%7B%7D,'cvml','m...@sebastiankral.de');> > *Sent:* Friday, November 07, 2014 5:48 PM > *To:* Nuke Python discussion > <javascript:_e(%7B%7D,'cvml','nuke-python@support.thefoundry.co.uk');> > *Subject:* [Nuke-python] Using the Nuke resolution of relative filenames > > Hi all, > > I am trying to re-purpose the code from pluginAddPath(). Copying the > behavior especially the resolution of relative filenames. > > The idea is to have a function which will be executed in a similar fashion > inside init.py scripts. It would be very neat if I could run > customAddPath('./custom') and Nuke would resolve the path for me. I don't > want my custom path to be added to the pluginPath in the end. I would just > add it and remove it again to use the resolution part. > > My first approach was to add the path to the plugin path so Nuke resolves > it but before I do that make a backup and after Nuke resolved the path > revert pluginPath to the backed up list. > Unfortunately this doesn't work because _nuke.pluginPath() is not a list > but a function. > > e.g. pretty close to Nuke8.0v6/plugins/nuke/overrides.py - pluginAddPath() > # Nuke does it's own resolution of relative filenames, so that they > end up > # relative to the right location. Rather than duplicating that logic > here, > # we just get the difference between the pluginPath before and after > we've > # added the new paths. > backup_plugin_path = _nuke.pluginPath > oldPluginPath = tuple(_nuke.pluginPath()) > > for i in args: > _nuke.pluginAddPath(i) > > newPaths = [p for p in _nuke.pluginPath() if p not in oldPluginPath] > for path in newPaths: > if path not in custom_paths: > custom_paths.insert(0, path) > > _nuke.pluginPath = backup_plugin_path > > Two questions come to mind: > 1. Is there a way I can remove paths from the pluginPath()? This way I > could use the resolution but remove what I added afterwards. > 2. Can I just use the resolution of relative paths which is Nuke using > internally? > > Perhaps someone has a good idea. > > Thanks, > Sebastian > > ------------------------------ > _______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk > <javascript:_e(%7B%7D,'cvml','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 > <javascript:_e(%7B%7D,'cvml','Nuke-python@support.thefoundry.co.uk');>, > http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > > -- Sent from mobile device
_______________________________________________ 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