Symbolic Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
SpencerL Posted May 14, 2009 Share Posted May 14, 2009 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 Quote Link to comment Share on other sites More sharing options...
Symbolic Posted May 14, 2009 Author Share Posted May 14, 2009 (edited) 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 May 14, 2009 by Symbolic Quote Link to comment Share on other sites More sharing options...
graham Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
graham Posted May 14, 2009 Share Posted May 14, 2009 (edited) 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 May 14, 2009 by graham Quote Link to comment Share on other sites More sharing options...
Symbolic Posted May 14, 2009 Author Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
graham Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
Symbolic Posted May 14, 2009 Author Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
graham Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.