Renaming a node with Python

Renaming a node with Python

labbejason
Advocate Advocate
1,183 Views
3 Replies
Message 1 of 4

Renaming a node with Python

labbejason
Advocate
Advocate

Hi there,

 

I'm testing out if we can fit Bifrost in certain parts of our pipeline and got into scripting a graph. I did run into a problem when trying to rename a node though. It looks like Bifrost acts like Maya, in the sense that if you try to name a node to something that already has the same name, it will automatically increment the name by 1. This is fine and I'm very used to it in cmds, but in cmds it returns the result, while it looks like Bifrost's cmds.vnnCompound(renameNode) returns nothing at all. This is an issue because if the node I'm trying to rename has a conflict I'll suddenly lose reference to the node!

 

Is there some workaround to get its real name in case of a conflict? Ideally cmds.vnnCompound would also have a name parameter that you can set right off the bat, just like cmds.createNode.

0 Likes
Accepted solutions (2)
1,184 Views
3 Replies
Replies (3)
Message 2 of 4

labbejason
Advocate
Advocate
Accepted solution

This is the best I have so far, but quite the overkill 🙂

Would love to hear if there's a better solution.

 

node = cmds.vnnCompound(graph, "/", addIONode=True)[0]  # Create node.
graph_nodes = cmds.vnnCompound(graph, "/", listNodes=True)  # List all nodes in graph.
graph_nodes.pop(graph_nodes.index(node))  # Remove new node from the list.
cmds.vnnCompound(graph, "/", renameNode=(a, "NEW"))  # Rename it.
new_graph_nodes = cmds.vnnCompound(graph, "/", listNodes=True)  # Re-list all nodes in graph.
node = next(iter(set(new_graph_nodes).difference(graph_nodes)))  # Re-assign value to the one new node.

 

0 Likes
Message 3 of 4

jonah.friedman
Community Manager
Community Manager
Accepted solution

Hi Jason,

 

That's indeed a known issue and it's logged as BIFROST-1648 so you can look out for it in future release notes.

 

Your solution looks like the kind of workaround I'd suggest except your Python is nicer. (I like that last line, readable and compact). 

Jonah Friedman
Bifrost Product Manager
0 Likes
Message 4 of 4

labbejason
Advocate
Advocate

Gotcha, thanks Jonah, I'll keep on eye out on the release notes for future updates!

0 Likes