Jump to content

How to compare ordered menus in VOP code?


Recommended Posts

I have a VOP node that has an ordered menu. I need to call different functions depending on the selection but I can't figure out how to compare them, because it throws a compile error when using:

if($type == "nurbs")

or

if($type == nurbs)

which seems to turn the compiled code into:

if(nurbs == nurbs)

Here nurbs is the token value. Should I be using integers? Even then it will just be 0 == 0. I looked at other VOPs but not sure which one actually has an example with an ordered menu.

Thanks :)

Link to comment
Share on other sites

Guest mantragora

Ordered menu returns integer. Think about VEX more like about C, where everything is number, not C#.

EDIT:

Actually you can use strings as a token too but you have to add double quotes yourself to it. You can't just put there as token

nurbs

it has to be

"nurbs"

It doesn't matter for the Label. But Token needs "" them.

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

Thanks guys. I was actually talking about VEX Builder Node, where you write inner/outer code. It seems like different operators use different approaches. Like some of the operators like Color Mix was using integers like you said, but Composite VOP was using strings for menus. Although the thing that made me confused is, this string comparison doesn't work implicitly in the Inner Code. To make it work you have to create a function in the Outer Code that takes a string explicitly, then the string comparison work. That's how it's done in the Composite VOP.

Link to comment
Share on other sites

Guest mantragora
That's how it's done in the Composite VOP.

For me string as token doesn't work if I don't add double quotes explicitly to it.

EDIT one again !: CompositeVOP doesn't use OrderedMenu. If you look under gear icon "Edit Parameter Interface" you can see that it uses "string" not "ordered menu". It looks the same from outside, but it's not.

Edited by mantragora
Link to comment
Share on other sites

Yes but it's still a menu, right? Like if you create an ordered menu with tokens as strings (without quotes) and then change the type to string, it works. That's how I did it. I think Houdini knows if has a menu, that it's not really a single string parameter.

Also how it doesn't work for you? Are you using something like:

if ($menu == "value")

inside Inner Code?

Because that doesn't work for me either. You have to have a function that takes a string in the Outer Code like:

func(string item)
{
    if (item == "value")
    ...
}

then call it like:

func($menu);

inside Inner Code.

Link to comment
Share on other sites

Guest mantragora

I just added Ordered menu to InineVOP and sended its output to PrintVOP. Tokken without double quotes errors out. Add quotes and it works.

That way this:

if ($menu == "value")

works in Inner Code without problems.

No need for some workarounds with functions. Everything should works in InnerCode.

Edited by mantragora
Link to comment
Share on other sites

How did you add an ordered menu to Inline VOP? Using Edit Parameter Interface? How do you refer to the parameter name afterwards? I thought inline VOP only allows adding parameters ($parm) using its fixed list of values which has basic value types only.

Link to comment
Share on other sites

Guest mantragora

Using Edit Parameter Interface?

How do you refer to the parameter name afterwards?

I thought inline VOP only allows adding parameters ($parm) using its fixed list of values which has basic value types only.

1) Yes.

2) The same like to any other input or anything that sends data inside the InlineVOP code, with a help of "$".

3) If you couldn't add anything to InlineVOP, SESI wouldn't add Gear icon to it. ;) You can customize any node. You can create your own variations with your custom menu For example i got Primitive Normal VOP with "op:" syntax preset, that adds string parameter and sends it to "Geometry File" parameter. That way I and specify normal on my geometry without saving geo. Saves a little writing.

  • Like 1
Link to comment
Share on other sites

Guest mantragora

Thanks man. I tried what you said with this code:

printf("%s\n", $menu);

and it says "mismatched quotation marks". I don't see what's wrong. Or where is the extra quote coming from.

Where you added printf ? To what ? InlineVOP ?

Can you add you file ? Because right now I don't get what you are doing ?

Link to comment
Share on other sites

Guest mantragora

Check this file. Don't be scared of my inlineVOP. I cut most of the options from it.

If you want to print values in VOPS, don't use "printf". You have to force recook by hitting Apply or turning on/off your VOP network. It's better to use PrintVOP. It have options to turning printing on/off so its better for cases like this.

test.hip

  • Like 1
Link to comment
Share on other sites

I pressed Apply several times but it didn't recook I think. I didn't try turning of the VOP network.

Also do presets also allow you to modify existing parameters, hiding them, etc? Is this what you did with your Inline VOP where it always show up as this?

Thanks this is exactly what I needed to see. Also just set your menu to string and removed the quotes from the tokens, and that worked too. Did you try like that? So I guess many different ways to do this. That's what makes it harder to figure out I think.

Link to comment
Share on other sites

Guest mantragora
Also do presets also allow you to modify existing parameters, hiding them, etc? Is this what you did with your Inline VOP where it always show up as this?

Yes.

Also just set your menu to string and removed the quotes from the tokens, and that worked too. Did you try like that?

Yes. Anyway, you propably got warning when you loaded the file ? This means that Houdini doesn't like quotes in Ordered Menu. It works but better be save and use String with Menu turned on.

So I guess many different ways to do this. That's what makes it harder to figure out I think.

No. Maybe. Yes. Sometimes. ;)

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