Jump to content
vrman

cant rename node with variable

Recommended Posts

i dont know why i cant rename my nodes with str variable , can anyone tell me what is the problem ? setName not working with getChildrenName variable , but you can change it with typing string directly , for example newNodeGroup.setName('Hello')

here is the code

myNodes = hou.selectedNodes()
getChildren = myNodes.children()[0]
getChildrenName = getChildren.name()
newNodeGroup = myNodes.createNode('group')
newNodeGroup.setName(getChildrenName)

thanks

Share this post


Link to post
Share on other sites

Not sure if this is related, but you have a bug in second line, since selectedNodes() returns a tuple, so you can't call children() on that. 

Also setName() can throw an exception if name isn't correct, like empty string, so most probably your getChildrenName has some issue. 

Share this post


Link to post
Share on other sites
24 minutes ago, symek said:

Not sure if this is related, but you have a bug in second line, since selectedNodes() returns a tuple, so you can't call children() on that. 

Also setName() can throw an exception if name isn't correct, like empty string, so most probably your getChildrenName has some issue. 

yes you right , here is the corrected script , but still rename not working , and i dont know why :

myNodes = hou.selectedNodes()
getChildren = myNodes[0].children()[0]
getChildrenName = getChildren.name()
newNodeGroup = myNodes[0].createNode('group')
newNodeGroup.setName(getChildrenName)

the problem is in last line , if you change that to :

newNodeGroup.setName(getChildrenName{0])

you can get characters by changing that number , but i cant get full name

Edited by vrman

Share this post


Link to post
Share on other sites

It is not working because you are trying to rename your new node to the same exact name as an existing node.

Try something like this...

getChildrenName = "from_code" + getChildren.name()

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×