Jump to content

Only allow HDA inputs of a particular node type


haki

Recommended Posts

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
Link to comment
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
Link to comment
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
Link to comment
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?

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