Jump to content

convert name to uppercase


Juraj

Recommended Posts

Hello,
I want to convert node's name to uppercase with On Name Changed event.

So I tried this code

node = kwargs["node"]
name = node.name()
node.setName(name.upper(), True)

But if I try to rename the node, I get error

Unknown error when generating backtrace.

And the name is converted to uppercase but from node abc becomes node ABC498 :)

Not sure where this 498 number and error come from.

I guess I am doing some beginner mistake.

 

Thanks,
Juraj

Link to comment
Share on other sites

Hi, I checked content of "name", it seems fine.
If I use 

node.setName(name.upper(), False)

Then it works fine, but every time I change name, I get this error

Traceback (most recent call last):
  File "opdef:/Sop/jt_OUT?OnNameChanged", line 3, in <module>
  File "/opt/hfs15.5.607/houdini/python2.7libs/hou.py", line 5458, in setName
    return _hou.Node_setName(*args, **kwargs)
OperationFailed: The attempted operation failed.

Any clues?
I will test in another OS and machine.

jt_OUT.hdanc

Link to comment
Share on other sites

Maybe it is related to the fact that you are changing the name in the name change event? Consider my image. I have relplaced your name.upper() with a fixed uppercase string of "ABC". I have added prints.

node = kwargs["node"]
name = node.name()
print node.name()
node.setName("ABC", False)
print node.name()

So the first thing that happens is we print out the original name. "OUT_". Then we change the name to "ABC" successfully. Then we come back into the event (for some reason..?) and we print the name again, which is "ABC". Then we try to change the name to "ABC" but the name is already "ABC" so we get an error. If you think about it, your "OUT_" falls into the same boat. Because "OUT_" is already upper case you are essentially changing it to the same name.

What if you wrote some code to detect if the new name is the same as the old name, and only assign the new name if it is different?Untitled-1.jpg

 

This seems to work. Try setting your initial name to "out_" in the onCreate event and then you'll see it gets renamed to "OUT_"

node = kwargs["node"]
name = node.name()
s = node.name().upper()
if s != name:
    node.setName(s, True)
print node.name()

 

Edited by Atom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...