Jump to content

How to use another operator if an input is empty?


magneto

Recommended Posts

I am trying to make a digital asset using a subnet that takes a curve input. I wanna make it so that if there is no curve provided then it will use the curve inside my subnet, else it will use the provided input curve.

I thought I might be able to do this using a switch operator but when there is no input, it errors out.

Is there a way to do this? Perhaps with an expression?

Link to comment
Share on other sites

Switch SOP with two connected inputs. First input is from a Null SOP connected to a subnet input, and the second is a default curve SOP.

For the switch value, set the expression as npoints("../null1") == 0

If the null1 has no points, then it'll set the switch to use the second switch input.

  • Like 2
Link to comment
Share on other sites

Yes, if nothing is connected at a specific input index it will return an empty string. The null is not necessary since it is just asking the parent asset what it's Nth input is and doesn't care about the input connected to the switch. The indirect input can be plugged directly into the switch's first input, or you can put other things between since it doesn't really matter.

Edited by graham
  • Like 1
Link to comment
Share on other sites

Thanks a lot guys, getting better with every post :)

EDIT: @anim: Just tried it, but it says, not enough sources specified, so errors out.

Should I use null for this one?

Slightly off topic, but a gem I often forget about:

From the help card for the switch sop:

Often, you can use a Switch in a network that could potentially have errors to bypass the failing nodes. One way to do this is to use the following expression in the Select input parameter:

if (strmatch("*Error:*", run("opinfo " + opfullpath("../" + opinput(".", 1)))), 0, 1)

With this expression, the switch will use the second input, unless it has an error, in which case it will switch to the first input.

  • Like 1
Link to comment
Share on other sites

Great thread guys!

Another trick, if you're going to make the subnet an asset. Create a integer parameter called "connected" and assign the !opexist(opinputpath('.',0)) as it's default expression, then make the parameter visible.

Now, when you create parameters you can disable them based upon the "connected" value. So when you connect an input it becomes enabled or disabled.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Billy and Magneto, I think what Hopbin meant two years ago was that if you have an digital asset with inputs, and you want some of your parameters to be enabled or disabled based on the existence of connection on, let's say first input...

You can use:

opexist(opinputpath('.',0))[/CODE]

(documentation) [/font][/color][color=#282828][font=helvetica, arial, sans-serif]as default value on a integer or toggle parameter which will gives you a boolean value where 1 means the first input has a connection and 0 means no connections. [/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]Then you can hide this parameter but you can use it as reference for the other parameters in [b]Disable When[/b] and [b]Hide When[/b] fields using [/font][/color][color=#282828][font=helvetica, arial, sans-serif]

[CODE]{toggle == 0}[/CODE]

[/font][/color]

Edited by cparliaros
  • Like 1
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...