Issue
This was raised by @dgovil in Slack that there is no such API in existence. Element::setName() will just the name but not update references resulting in breaking connections.
Proposal
- The suggestion as to add a optional argument to
setName(name, updateReferences=false) which defaults to not updating references.
This might work but only Node and NodeGraph classes support the require call to find downstream pots.
- Another suggestion would be to add this on the derived classes of
Node and NodeGraph.
- Another possibility is to add in a
rename() method.
Implementation
This is what I cam up with as the logic required.
def renameNode(node, newName : str, updateReferences : bool = True):
if not node or not newName:
return
if not (node.isA(mx.Node) or node.isA(mx.NodeGraph)):
print('A non-node or non-nodegraph was passed to renameNode()')
return
if node.getName() == newName:
return
parent = node.getParent()
if not parent:
return
newName = parent.createValidChildName(newName)
if updateReferences:
downStreamPorts = node.getDownstreamPorts()
if downStreamPorts:
for port in downStreamPorts:
#if (port.getNodeName() == node.getName()): This is assumed from getDownstreamPorts()
oldName = port.getNodeName()
if (port.getAttribute('nodename')):
port.setNodeName(newName)
print(' > Update downstream port: "' + port.getNamePath() + '" from:"' + oldName + '" to "' + port.getAttribute('nodename') + '"')
elif (port.getAttribute('nodegraph')):
port.setAttribute('nodegraph', newName)
print(' > Update downstream port: "' + port.getNamePath() + '" from:"' + oldName + '" to "' + port.getAttribute('nodegraph') + '"')
elif (port.getAttribute('interfacename')):
port.setAttribute('interfacename', newName)
print(' > Update downstream port: "' + port.getNamePath() + '" from:"' + oldName + '" to "' + port.getAttribute('interfacename') + '"')
node.setName(newName)
It might be "nice" to add in a renameConnection() which would check the usage of interfacename or nodename or nodegraph. Long term it would better to just use 1 connection string identifier.
Issue
This was raised by @dgovil in Slack that there is no such API in existence.
Element::setName()will just the name but not update references resulting in breaking connections.Proposal
setName(name, updateReferences=false)which defaults to not updating references.This might work but only
NodeandNodeGraphclasses support the require call to find downstream pots.NodeandNodeGraph.rename()method.Implementation
This is what I cam up with as the logic required.
It might be "nice" to add in a
renameConnection()which would check the usage ofinterfacenameornodenameornodegraph. Long term it would better to just use 1 connection string identifier.