load custom node as a box and not a reference

74 views
Skip to first unread message

s.des...@gmail.com

unread,
Sep 30, 2024, 4:20:45 AM9/30/24
to gaffer-dev

Hello,

I have a couple of custom nodes that I load at Gaffer startup using the technique described here: Gaffer Documentation.

The problem is that these nodes are loaded as references in the Graph Editor, and if the nodes are updated, renamed, or modified in any way, it can break the Gaffer script.

Is there a way to load the custom nodes as box nodes instead of reference nodes to avoid any issues?

Thx,

Seb

John Haddon

unread,
Oct 1, 2024, 3:58:07 AM10/1/24
to gaffe...@googlegroups.com
Hi Seb,

In the GraphEditor, you can right click on a Reference and choose "Duplicate as Box" to import the reference as a box.

Using the API, you could create the box directly in the first place like so :

```

box = Gaffer.Box()

root.addChild( box )

root.executeFile( "yourReference.grf", parent = box, continueOnError = True )

```


Cheers...

John


--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/295eabb8-5d16-4325-b8e4-e85fa684f36en%40googlegroups.com.

Sébastien Desmet

unread,
Oct 1, 2024, 11:52:17 AM10/1/24
to gaffe...@googlegroups.com
Hello John,

Thx for the help. I manage to make it works so my custom nodes are loaded directly as box instead of references.
There is still one issue, for a reason that I don't know, when I select one on my custom node in the tab menu, it create the box node correctly but duplicates all the plugs.
Do you have an idea why ?
boxStartup.png
This is the code that I use at gaffer startup:

import Gaffer
import GafferUI
import os

# root folder to copy the nodes
root_path = "/uvfx/Department/3D/SharedFiles/gaffer/startupNodes/"

def __node(nodeName):
    return Gaffer.Box(nodeName)

def __nodePostCreator(folder, node, menu):
    script = Gaffer.ScriptNode()
    root_path = "/uvfx/Department/3D/SharedFiles/gaffer/startupNodes/"
    reference_path = f"{root_path}{folder}/{node.getName()}.grf"
    script.executeFile( reference_path, parent = node, continueOnError = True )


nodeMenu = GafferUI.NodeMenu.acquire( application )

# scan sub folders in startupNodes folder
with os.scandir(root_path) as entries:
    for entry in entries:
        if entry.is_dir() and not entry.name.startswith('.') :
            folderName = entry.name
            # scan files in the sub folders
            directory_path = "/uvfx/Department/3D/SharedFiles/gaffer/startupNodes/{}/".format(folderName)
            files_list = os.listdir(directory_path)
            for file in files_list:
                filename, ext = os.path.splitext(file)
                # create nodes based on folder / files structure
                def createNode(nodeName=filename):
                    return __node(nodeName)
                # create custom gaffer menu based on folders and files structure
                def createPost(node, menu, folder=folderName):
                    return __nodePostCreator(folder, node, menu)

                nodeMenu.append(
                    path="/Artist Tools/{}/{}".format(folderName, filename),
                    nodeCreator=createNode,
                    postCreator=createPost,
                    searchText=filename
                )


Thx,

Seb

Murray Stevenson

unread,
Oct 2, 2024, 2:03:55 AM10/2/24
to gaffer-dev
Hi Seb,

I'd suggest trying to execute the file from the current script that you're adding the Box to. Currently in __nodePostCreator you're creating a brand new ScriptNode each time via `script = Gaffer.ScriptNode()`. Instead you can try accessing the existing ScriptNode from the newly created Box node by replacing that line with `script = node.ancestor( Gaffer.ScriptNode )`.

Cheers,

M

s.des...@gmail.com

unread,
Oct 2, 2024, 7:34:14 AM10/2/24
to gaffer-dev
Hello Murray,

Thanks for the fix. It works perfectly now

Seb
Reply all
Reply to author
Forward
0 new messages