Jump to content
haki

Only allow HDA inputs of a particular node type

Recommended Posts

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

Share this post


Link to post
Share on other sites

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)

errorOnInputType.thumb.gif.955914d3e33296f233bb8b52e17d3337.gif

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.
image.thumb.png.20fd742b3800e51637c1c5699874e542.png

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 by Alain2131
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
Share on other sites

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."
image.thumb.png.6794b6039d6e9aab79c929c1dbf9da32.png

update_curve_coords.hda

P.S. Nice cloud =P

Edited by Alain2131
  • Thanks 1

Share this post


Link to post
Share on other sites

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?

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

×