Quickly reading through the code, I have a feeling this could be condensed
a lot. The OS module can create folders, I don't see the point of going
through a subprocess. Also this whole script tag thing could just be
skipped.
Then I haven't used python for nuke studio yet so I might be entirely wrong.
On 6 May 2015 19:24, <i...@visualplastic.net> wrote:

>  Hi Mads,
>
> thank you for sharing your code! this looks good :)
> But still I'm wondering that this can't be as simple as it is with
> standard nuke. I hoped to get away with something that works for all nuke
> flavours. Something like telling the "backgound-render-nuke-instance" to
> execute 'nuke.addBeforeRender(fustoms.createWriteDir)' when it starts the
> thread?
>
> cheers,
> Fabian
>
> Am 06.05.2015 um 12:40 schrieb Mads Lund:
>
> Im not sure if it is my thread from back in november you are refering to,
> but I did find a good solution for us back then.
> I create the Nuke scripts, then select the media in the timeline view and
> hit a custom menu button connected to this funciton (note that our scripts
> automatically create a tag called "script" on the media):
>
>
>  #Use this script to add a auto floder creation option.
> #All you need is the \AutoWriteFolder.py file in your .nuke folder
> def folderfix():
>  import hiero
>  HasExecuted = False
>  print "Fixing Path AutoCreation"
>  for item in
> hiero.ui.TimelineEditor.selection(hiero.ui.getTimelineEditor(hiero.ui.activeSequence())):
>     for items in item.tags():
>         Tags = items.metadata()
>         if Tags.hasKey("script"):
>             print Tags.value("script")
>
>  
> subprocess.Popen([nuke.EXE_PATH,'-t',os.path.dirname(os.path.realpath(__file__))+'\AutoWriteFolder.py',
> Tags.value("script")])
>             HasExecuted = True
>  if not HasExecuted:
>     nuke.message("ERROR - Did not patch any files! \nMake sure that you
> select item(s) in the timline with a NukeScript tag.")
>
>
>
>  The key part here is "subprocess.Popen" that will make the script run in
> its own nuke thread
> The AutoWriteFolder.py looks like this:
>
>
>  import nuke
>  import os
> import sys
> def RecursiveFindNodes(nodeClass, startNode):
>      if startNode.Class() == nodeClass:
>         yield startNode
>     elif isinstance(startNode, nuke.Group):
>         for child in startNode.nodes():
>             for foundNode in RecursiveFindNodes(nodeClass, child):
>                 yield foundNode
>
>  if len ( sys.argv ) != 2:
>   print 'Usage: NUKE autoWriteFolder.py <nuke_script>' + str(len (
> sys.argv ))
>   sys.exit(-1)
>
>  inScript = sys.argv[1]
> nuke.scriptOpen( inScript )
>
>  allWriteNodes = [w for w in RecursiveFindNodes('Write', nuke.root())]
>
>  for write in allWriteNodes:
>   write['beforeRender'].setValue( """if not
> os.path.exists(os.path.dirname(nuke.thisNode().knob("file").value())):
> os.makedirs(os.path.dirname(nuke.thisNode().knob("file").value()))""" )
>
>  nuke.scriptSave( inScript )
>
>
>
>
> On Wed, May 6, 2015 at 12:23 PM, Fabian Fischer <i...@visualplastic.net>
> wrote:
>
>> Hi,
>> has anyone come up with a solution for this yet? There is a thread in the
>> nuke-user list back from november, but no real solution was found.
>> For nuke and nuke x, I'm calling this function (it is within my own
>> module):
>>
>> def createWriteDir():
>>     import os
>>     file = nuke.filename(nuke.thisNode())
>>     dir = os.path.dirname( file )
>>     osdir = nuke.callbacks.filenameFilter( dir )
>>     if os.path.exists(osdir) == False:
>>         if nuke.ask(osdir+"\nOutput dir does not exist. Create?"):
>>             os.makedirs( osdir )
>>
>> I'm calling it from init.py:
>>
>> nuke.addBeforeRender(fustoms.createWriteDir)
>>
>> This seems not to work for Nuke Studio when rendering from the timeline -
>> which is really annoying...
>>
>> Any help highly appreciated! Thank you,
>>
>> Fabian
>> _______________________________________________
>> 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 listnuke-pyt...@support.thefoundry.co.uk, 
> http://forums.thefoundry.co.uk/http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
>
> --
> Fabian Fischer
>
> Compositing  & VFX | f...@visualplastic.net | +49  170  15 20 750
>
>
> _______________________________________________
> 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

Reply via email to