Jump to content

renaming nodes and error checking.


Symbolic

Recommended Posts

Hi,

Once again a HOM and docs mystery.

from the docs:

setName(self, name, unique_name = False)

Sets the name of this node. ... Raises hou.OperationFailed if the node could not be renamed (for example, another node already exists with the name, the node is the root node or top-level manager, or the node is inside a locked asset). ...

How this is going to work in real life?

ex:

hou.node('/obj/geo1/hello').setName('hello', unique_name = False)

Thanks.

Link to comment
Share on other sites

Hi,

Once again a HOM and docs mystery.

from the docs:

setName(self, name, unique_name = False)

Sets the name of this node. ... Raises hou.OperationFailed if the node could not be renamed (for example, another node already exists with the name, the node is the root node or top-level manager, or the node is inside a locked asset). ...

How this is going to work in real life?

ex:

hou.node('/obj/geo1/hello').setName('hello', unique_name = False)

Thanks.

This is what you want

hou.node('/obj/geo1').setName('geo2', 1)

The "1" is in there in case the node you are trying to rename it already exists, there for it will increment it to the next available number. In this case if /obj/geo2 already exists, it will rename it /obj/geo3

Link to comment
Share on other sites

This is what you want

hou.node('/obj/geo1').setName('geo2', 1)

The "1" is in there in case the node you are trying to rename it already exists, there for it will increment it to the next available number. In this case if /obj/geo2 already exists, it will rename it /obj/geo3

Thanks SpencerL!

But in my script there is possibility that the user will try to rename it with the same name. So I need a clean exit if the node already exists with the same name.

Thats why:

hou.node('/obj/geo1/hello').setName('hello', unique_name = False)

I have the same name set-up and unique_name turned off. I am wondering how the "RISE" function works here if the node already exists?

"Raises hou.OperationFailed if the node could not be renamed"

Thanks.

Edited by Symbolic
Link to comment
Share on other sites

Basically it works as advertised. It lets you set the name of nodes, except manager nodes like /obj /shop, etc. The unique_name argument is for resolving name conflicts with existing nodes.

For example, if you have a node called "hello" and attempt to name another node "hello" it will raise an error since there is already a node with that name. If you do setName("hello", True), it will automatically bump the new nodes name to "hello1", like Houdini would do if you tried to name it through the interface.

Link to comment
Share on other sites

If the user can rename the node to the same name then you should check the new name against the nodes current name before trying to set it and if it's the same name then do nothing. Also you can except the exception if another node with that name exists.

if not newname = node.name():
	try:
		node.setName(newname)
	except hou.OperationFailed:
		raise hou.Error("A node with that name already exists")

Edited by graham
Link to comment
Share on other sites

In my case:

My python script fails.

Error: Python error: Traceback (most recent call last):

File "<stdin>", ...

return _hou.Node_setName (*args, **kwargs)

OperationFailed: The attempted operation failed

It is a simple python code on a "script sop"

Works fine with the unique name... but error if it is executed again and the names are already fixed.

Link to comment
Share on other sites

I'm afraid without a more detailed description and at least some script code that error message isn't very helpful in diagnosing the problem. My suggestion would be to do what I posted above to ensure the name is not set if it's already the name you want.

Link to comment
Share on other sites

Thanks graham!

Your approach helped alot. At least the Script SOP is not failing now. But It seems like I am not getting that fancy "A node with that name already exists" error box?

Do I need to include an additional library for that?

Things like hou.ui.displayMessage("Blah!") seems to work in other sections.

Link to comment
Share on other sites

This is a touchy issue since the raise command in this context will promote the error to the sops error flag and not display a message. You basically have to put a hou.ui.displayMessage in your except block above your raise hou.Error to throw up the message before the node errors. You can also do some sort of custom exception redirection stuff but that is more complicated.

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...