import GafferScene
reader = GafferScene.SceneReader()
root.addChild(reader)
/startup/gui
- 1. Without relying on the global "root" variable in the Script console how do I add a node to the currently active scene? I was able to do:
import GafferScene
reader = GafferScene.SceneReader()
root.addChild(reader)How do I do this in an external script without having the "root" variable? How do I get the current scene for example?
- 2. I couldn't find how to save as, save or open a scene in Gaffer. Where's that one hidden?
I'm particularly looking for load, save and a query to see if current scene has unsaved changes.
https://github.com/GafferHQ/gaffer/blob/bbd76c537110ebd62232a4b149588bb678a9af05/python/GafferUI/Filhttps://github.com/GafferHQ/gaffer/blob/bbd76c537110ebd62232a4b149
588bb678a9af05/python/GafferUI/FileMenu.py#L29
- 3. I was able to generate a menu at startup going from the tutorial in the documentation: http://www.gafferhq.org/documentation/0.50.0.0/Tutorials/Scripting/AddingAMenuItem/index.html
Thanks for that! However, could I also add the menu at runtime? If so, how would I do it?
- 4. After I know the above. If I were to run a startup script that should always run as Gaffer initializes (even if it were without gui) yet I also wanted to allow that to trigger a function that adds the runtime menu? How could I detect Gaffer is running with a gui or not? Plus, how do I make sure the gui is initialized (if the startup script must reside outside of
/startup/gui
Hey Roy,Glad things have been going well so far!
- 1. Without relying on the global "root" variable in the Script console how do I add a node to the currently active scene? I was able to do:
import GafferScene
reader = GafferScene.SceneReader()
root.addChild(reader)How do I do this in an external script without having the "root" variable? How do I get the current scene for example?Are you able to elaborate a little on how you are running your code?The Gaffer app itself can have multiple scripts (scenes) open at once. Gaffer can also be imported as a module on its own. As such, the answer to this depends on how your code is invoked.Within the app, the ScriptEditor for example is able to offer the root variable as it is a child of a ScriptWindow, and so has access to its scriptNode accessor (via self.ancestor( GafferUI.ScriptWindow) ). The same would be true of any menu items.If you’re in a stand-alone python script, and have just imported gaffer, it’s more a case of rolling your own ‘current’:script = Gaffer.ScriptNode()
script["fileName"].setValue( "/path/to/your/file.gfr" )
script.load()
- 2. I couldn't find how to save as, save or open a scene in Gaffer. Where's that one hidden?
I'm particularly looking for load, save and a query to see if current scene has unsaved changes.Have a look in FileMenu.py (https://github.com/GafferHQ/gaffer/blob/master/python/GafferUI/FileMenu.py) which shows how the menus do their thing (which also illustrates how to get back to the scriptNode In a variety of ways, and determine if there are unsaved changes).
- 3. I was able to generate a menu at startup going from the tutorial in the documentation: http://www.gafferhq.org/documentation/0.50.0.0/Tutorials/Scripting/AddingAMenuItem/index.html
Thanks for that! However, could I also add the menu at runtime? If so, how would I do it?You can run that code at any time. All those startup files just do it run code when gaffer starts.You can also register menu items such that they are built on the fly whenever the menu is accessed. The Open Recent menu is an example of this (https://github.com/GafferHQ/gaffer/blob/bbd76c537110ebd62232a4b149588bb678a9af05/python/GafferUI/FileMenu.py#L53).You should be able to do this to create the top-level menus too.
- 4. After I know the above. If I were to run a startup script that should always run as Gaffer initializes (even if it were without gui) yet I also wanted to allow that to trigger a function that adds the runtime menu? How could I detect Gaffer is running with a gui or not? Plus, how do I make sure the gui is initialized (if the startup script must reside outside of
/startup/guiThe startup script subdirectories are run at appropriate points in the apps startup cycle, or when the modules load. As such, if you have code that you want to run in the gui, the only way to do that safely is in the startup/gui folder, the other non-module folders refer to the other apps (see https://github.com/GafferHQ/gaffer/tree/master/apps). You wouldn’t want to use use the GafferUI module folder as that is imported in to many different UI apps that aren’t the main gaffer ui.So you'd need to split your code up so it runs at the appropriate point.
The script is basically triggering from a separate Qt user interface that wants to create a node in the current active view/scene in the Gaffer UI. I couldn't figure out how to easily find which scene was currently opened, kind of like doing a `maya.cmds.file(query=True, sceneName=True)`. In my case I triggered a User Interface from a menu bar entry that just shows a generic Qt interface (that is agnostic across multiple DCCs, as such passing along a handle wouldn't fit my needs). It's more a matter of finding "what script/scene is currently open"?
Ah, the real thing I couldn't find out was how to just the right "application" variable to start appending the menus as per the example. Since in my separate method/package I didn't have the global `application` variable available. How would I retrieve the "active application" or alike? Can I get that from GafferUI?