Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Juraj

convert name to uppercase

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

Share this post


Link to post
Share on other sites

Looks fine here. Did you check what's displayed if you print the content of "name"? Maybe there is a strange sign in there.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Tried it on another machine with Windows and I am getting the same error. It seems like really simple task, what am I doing wrong?

Share this post


Link to post
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

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