galagast Posted March 15, 2016 Share Posted March 15, 2016 On the shell: 1. I stored a hou.node("/obj/geo1") onto a variable obj. 2. Then I deleted the geo1 object in the scene. 3. I check the obj variable, it now returns an error as expected: >>> obj Traceback (most recent call last): File "<console>", line 1, in <module> File "C:/PROGRA~1/SIDEEF~1/HOUDIN~1.393/houdini/python2.7libs\hou.py", line 8015, in __repr__ def __repr__(*args): return _hou.ObjNode___repr__(*args) ObjectWasDeleted: Attempt to access an object that no longer exists in Houdini. My question now is, how do I check if a node was deleted? Or if it is still valid? I'm looking for a command similar to MaxScript's isValidNode <var>: Returns true if <var> is a node value, and the node has not been deleted. Otherwise, it returns false. I'm planning to use it on an if statement like so: if isValidNode(obj): Quote Link to comment Share on other sites More sharing options...
Atom Posted March 15, 2016 Share Posted March 15, 2016 (edited) Holding a reference to a node, beyond it's current scope, is not wise. Simply fetch the expected node at the top of the code. If it exists, you will have a valid node to operate upon.There are some status functions associated with nodes, however, use print dir(obj) to review them. But if the node has been deleted those functions will not be available. Otherwise create your own test with a try/except to determine if the node is still valid. Edited March 15, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
galagast Posted March 15, 2016 Author Share Posted March 15, 2016 Thank you for the response Atom. I'll use print dir(obj) to study more of the associated functions of the node. Yes, my current workaround for now was I created a separate function with a try/except inside it to determine a node's validity. Quote Link to comment Share on other sites More sharing options...
galagast Posted March 15, 2016 Author Share Posted March 15, 2016 In relation to the question, is there a way to check if a provided path is valid? Say I have an input string of: foo = "/geo/box1" I then would later use that for: obj = hou.node(foo) But before I do, is there a way to check if the foo string path is a valid path on the current session? Quote Link to comment Share on other sites More sharing options...
willow wafflebeard Posted March 16, 2016 Share Posted March 16, 2016 (edited) import os.path obj = "" nodename = os.path.basename(foo) kids = map( lambda x: x.name(), node.children() ) if nodename in kids: obj = hou.node(foo) could this suffice? im sure you can use filter() straight after map() or you can just do: raise hou.Error("no such node in object") or raise ValueError("no such node in object") somewhere in the code edit: i noticed its a path Edited March 16, 2016 by willow wafflebeard Quote Link to comment Share on other sites More sharing options...
anim Posted March 16, 2016 Share Posted March 16, 2016 (edited) ...before I do, is there a way to check if the foo string path is a valid path on the current session? hou.node() will return None if the path is invalid so you can straight away just do: path = "/any/path" node = hou.node(path) if node: print "node %s exists and it's a %s" % (node.path(), node.type().name()) else: print "node %s doesn't exist" % path Edited March 16, 2016 by anim Quote Link to comment Share on other sites More sharing options...
galagast Posted March 16, 2016 Author Share Posted March 16, 2016 Thanks guys! @Willow: Those are new to me, I'm reading up on lambda, map and filter now. I will definitely consider its usage during my forays in python. @Tomas, awesome, I did end up doing that after a couple of tests last night Glad I was on the right path. 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.