I ended up getting the effect I was looking for but had to complete it in a strange way. Basically what I did is wrap the scriptOpen command into a callback and use PySide's QTimer.singleShot method with a time of 0 so the callback will immediately execute when the main event loop comes back. This should give Nuke time to finish it's launch procedures before running the scriptOpen method. I've included a snippet below in case anyone else needs to do something wacky like this in a startup script. Thanks again for the help everyone.
def on_startup(): nuke.removeOnUserCreate(on_startup, nodeClass="Root") script_path = os.environ.get("STARTUP_SCRIPT") if not script_path: return del os.environ["STARTUP_SCRIPT"] cb = lambda x=script_path: nuke.scriptOpen(x) from PySide import QtCore QtCore.QTimer.singleShot(0, cb) nuke.addOnUserCreate(on_startup, nodeClass="Root") Best, -tony On Thu, Mar 13, 2014 at 8:49 PM, Tony Barbieri <great...@gmail.com> wrote: > I've also tried using nuke.scriptReadFile(...) and then running > nuke.root().setName(file_path) but it seems that is not possible as it > errors out with invalid name. Even if I try to run setName in the script > editor once Nuke has launched and feed in exactly the name that is present > in the UI it will error out. I don't want to use scriptSaveAs because I > don't want to change the file contents on disk...a bit worried an error > could corrupt a valid file, plus doing a save during an open operation > doesn't feel like a good idea. > > Options are dwindling so I may resort to using the external script to > accomplish this. > > > > On Thu, Mar 13, 2014 at 6:05 PM, Tony Barbieri <great...@gmail.com> wrote: > >> I'm getting very close but still have one last hurtle to overcome. So I >> ended up using the onCreate callback with the flag nodeClass="Root": >> >> nuke.addOnCreate(on_startup, nodeClass="Root") >> >> All seems well and the on_startup function is called successfully. The >> last issue is I can't seem to get Nuke to open the file in the currently >> running session. The code I'm using is: >> >> nuke.scriptClear() >> nuke.Root().setModified(False) >> nuke.scriptOpen(*cmd.get("args", [])) >> >> Even with the scriptClear and the set root unmodified, Nuke still opens a >> new session for the file. I thought about using nuke.scriptReadFile(...), >> but that would put the file's contents into an Untitled file whereas I need >> to have the script open in the session so a user could save normally. >> >> If all else fails I'll go with the script technique. Ideally I'd like to >> not have to go that route because I'm trying to use as similar a technique >> across applications as I can. >> >> Thanks again for any help! >> >> -tony >> >> >> On Thu, Mar 13, 2014 at 1:48 PM, Tony Barbieri <great...@gmail.com>wrote: >> >>> Thanks for the replies, both options sound great. Appreciate you taking >>> the time! >>> >>> -tony >>> >>> >>> On Thu, Mar 13, 2014 at 1:04 PM, Brian Hawkins <bhawk...@reald.com>wrote: >>> >>>> If you want to open a file on launch using your "openfile.py" script, >>>> you can run nuke from the command line with your python script as the first >>>> argument: >>>> >>>> >>>> >>>> eg: >>>> >>>> "Nuke8.0.exe /path/to/your/script/openfile.py" >>>> >>>> >>>> >>>> If you use a python file instead of a nukescript in the command line >>>> nuke will run the script as soon as it has run its own startup procedures. >>>> >>>> >>>> >>>> *From:* nuke-dev-boun...@support.thefoundry.co.uk [mailto: >>>> nuke-dev-boun...@support.thefoundry.co.uk] *On Behalf Of *Tony Barbieri >>>> *Sent:* Thursday, March 13, 2014 10:51 AM >>>> >>>> *To:* Nuke plug-in development discussion >>>> *Subject:* Re: [Nuke-dev] Open file on startup >>>> >>>> >>>> >>>> The onScriptLoad callback doesn't seem to fire when launching. I'm >>>> adding the onScriptLoad callback in the init.py but it doesn't seem to >>>> "take" until I open a script after Nuke has launched. Trying to use the >>>> onCreate callback also doesn't seem to work as I am trying to open a script >>>> while everything is still instantiating. Not really sure how to proceed >>>> with this at this point. >>>> >>>> >>>> >>>> On Mon, Mar 10, 2014 at 3:29 PM, Tony Barbieri <great...@gmail.com> >>>> wrote: >>>> >>>> Thanks for your reply, Nathan. This seems like the most >>>> straightforward way to accomplish this. >>>> >>>> >>>> >>>> Thanks again! >>>> >>>> >>>> >>>> -tony >>>> >>>> >>>> >>>> On Mon, Mar 10, 2014 at 1:06 PM, Nathan Rusch <nathan_ru...@hotmail.com> >>>> wrote: >>>> >>>> The `onScriptLoad` callback runs after the Root's `onCreate` callback, >>>> which should be the last `onCreate` to run when a script is loaded. >>>> >>>> >>>> >>>> -Nathan >>>> >>>> >>>> >>>> *From:* Tony Barbieri <great...@gmail.com> >>>> >>>> *Sent:* Monday, March 10, 2014 7:58 AM >>>> >>>> *To:* nuke-dev@support.thefoundry.co.uk >>>> >>>> *Subject:* [Nuke-dev] Open file on startup >>>> >>>> >>>> >>>> Hello! >>>> >>>> >>>> >>>> I am trying to open a file on startup by using a custom open method >>>> written in python. I am trying to run the open code either in an init.py >>>> or menu.py that we use for our facility. Ideally this can happen in the >>>> init.py. The code appears to be running correctly but it seems that the >>>> file is zeroed out to a default scene due to it running "too early". >>>> >>>> >>>> >>>> Is it possible to open a file on Nuke launch without using the standard >>>> command-line file flag but do it via python? >>>> >>>> >>>> >>>> Thanks! >>>> >>>> >>>> >>>> -- >>>> -tony >>>> ------------------------------ >>>> >>>> _______________________________________________ >>>> Nuke-dev mailing list >>>> Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev >>>> >>>> >>>> _______________________________________________ >>>> Nuke-dev mailing list >>>> Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev >>>> >>>> >>>> >>>> >>>> >>>> -- >>>> -tony >>>> >>>> >>>> >>>> >>>> >>>> -- >>>> -tony >>>> >>>> >>>> ------------------------------ >>>> >>>> >>>> >>>> ****************************************************************************************** >>>> This email and any files transmitted with it are confidential and >>>> intended solely for the use of the individual or entity to whom they are >>>> addressed and may contain confidential and privileged information. No one >>>> else is authorized to distribute, forward, print, copy or act upon any >>>> information contained in this email. If you are not the intended recipient, >>>> please contact the sender by reply email and destroy all copies of the >>>> original message. >>>> >>>> ******************************************************************************************* >>>> >>>> ------------------------------ >>>> >>>> >>>> ****************************************************************************************** >>>> This email and any files transmitted with it are confidential and >>>> intended solely for the use of the individual or entity to whom they are >>>> addressed and may contain confidential and privileged information. No one >>>> else is authorized to distribute, forward, print, copy or act upon any >>>> information contained in this email. If you are not the intended recipient, >>>> please contact the sender by reply email and destroy all copies of the >>>> original message. >>>> >>>> ******************************************************************************************* >>>> >>>> _______________________________________________ >>>> Nuke-dev mailing list >>>> Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev >>>> >>>> >>> >>> >>> -- >>> -tony >>> >> >> >> >> -- >> -tony >> > > > > -- > -tony > -- -tony
_______________________________________________ Nuke-dev mailing list Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev