haki Posted June 4, 2021 Share Posted June 4, 2021 Hey folks, Is it possible to make an HDA error out if the input node type is not of a particular required node type? Cheers, Hristo Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted June 4, 2021 Share Posted June 4, 2021 (edited) Hi Hristo, yes you can. With a Python node as the first node in your HDA, you can fetch the input node's type, and check if it is a type you want or not. In the example below, I check against a list to see if it is a type I don't want. The opposite would be easy to implement. wrongTypes = ["add", "box", "testgeometry_pighead"] node = hou.node(".").inputs()[0] nodeType = node.type().name() #print(nodeType) for type in wrongTypes: if nodeType == type: raise hou.NodeError("Node \"%s\" not compatible !" % nodeType) This method might not be the best, since if the input is animated, the Python node will evaluate at each frame. Since you have an HDA, you could go into the Type Properties, Script, then add an Event Handler "On Input Changed", and run (almost) the same code. That should be cleaner. errorOnInputNodeType.hipnc EDIT : Here's the code to do the opposite, to keep only the nodes for which the type has been specified. goodTypes = ["add", "box"] node = hou.node(".").inputs()[0] nodeType = node.type().name() #print(nodeType) found = 0 for type in goodTypes: if nodeType == type: found = 1 break if found == 0: raise hou.NodeError("Node \"%s\" not compatible !" % nodeType) Edited June 4, 2021 by Alain2131 1 1 Quote Link to comment Share on other sites More sharing options...
haki Posted June 7, 2021 Author Share Posted June 7, 2021 Hi Alain, This is fantastic! Much appreciated! I played around a little to find a way to get the error message to propagate upwards without throwing to the consol onInputChanged. I combined the 2 methods you wrote about (thanks for the great detail btw!). I left the python SOP alone in a separate branch and I run the cook() method on it onInputChanged. I don't know if that takes care of the cook-on-every-frame issue. This is what I've got: https://github.com/arabadzhiyski/update_curve_coordinates It must be the most useless, useful thing I've done yet.. Thanks again, Hristo 1 Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted June 7, 2021 Share Posted June 7, 2021 (edited) Hey Hristo, That's pretty cool ! I like your Try Except to set the switch as a workaround to "Error while cooking." Yet another way to do it would be to make the check in onInputChanged, and if problem, switch to the input 0. In the input 0, you can put an error node with your message. That way, it doesn't have the "Error: Error generated by python node." update_curve_coords.hda P.S. Nice cloud =P Edited June 7, 2021 by Alain2131 1 Quote Link to comment Share on other sites More sharing options...
haki Posted June 7, 2021 Author Share Posted June 7, 2021 Brilliant! I didn't even know the error node existed. Thanks for that! It's easier to understand what's going on that way. 42 minutes ago, Alain2131 said: P.S. Nice cloud =P - I saved it with the stashed curve, didn't I? 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.