Jump to content

How to use string tokens in expressions in parameter fields?


Recommended Posts

Hi,

I have an ordered menu with items that have tokens similar to Sphere SOP's Primitive Type, which have string based tokens. Using them in Switch SOP's using ch() works based on their order in the menu, which is fine.

But I want to use logical comparison inside a parameter field to see if it's a particular value. I tried both indices and the tokens like this, but they don't work:

if(ch("../primType") == "poly", 1, 5)

Thanks :)

Link to comment
Share on other sites

Thanks Eetu, I noticed those worked for me as well, but after trying 2 if statements, they seem to stop working:

if(ch("type") == 0, if(ch("type") == 1, 1, 2), 3)

I would have suspected the if statements but I used multiple ifs successfully before. Do you think this is a bug, or am I missing something? :)

Link to comment
Share on other sites

Guest mantragora

Thanks Eetu, I noticed those worked for me as well, but after trying 2 if statements, they seem to stop working:

if(ch("type") == 0, if(ch("type") == 1, 1, 2), 3)

I would have suspected the if statements but I used multiple ifs successfully before. Do you think this is a bug, or am I missing something? :)

1) What @eetu said.

2) Don't you prefer to do it this way ?

{
    # Come back, come back to me
    comeback = 0;

    # I'll be waiting,
    ptype = ch("../torus1/type");    
    if (ptype == 0) 
    {
        comeback = 0;
    }
    else if (ptype == 1) comeback = 1;
    else comeback = 2;

    # patiently
    return  comeback;
}

Yes, you can write hscript this way.

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

you can simply use arg() Hscript expression for this

if your type parameter returns values like 0,1,2

then

arg("1 2 3", ch("type"))

will return 1 for ch("type") == 0

2 for ch("type") == 1

3 for ch("type") == 2

so in the space separated string you can choose whatever you want to return for every index instead of huge nested if expression

  • Like 2
Link to comment
Share on other sites

if(ch("../primType") == "poly", 1, 5)

The "ch" expression always returns a numeric value. You should be using "chs" if you want the parameter to eval to a string result.

If you reference an ordered menu using "ch" it will return the index of the selected item, but if you use "chs" it will return the token string for the menu item.

if(chs("../primType") == "poly", 1, 5)

Edited by hopbin9
  • Like 2
Link to comment
Share on other sites

Thanks alot guys, very good tricks.

Btw hopbin, I tried using chs and string comparison but it returns 0 no matter what. Did you have success with that? You can try it but I couldn't get the values, but instead 0.

Yea you're right, it appears to be an issue with how hscript handles strings in integer fields. I don't think it's return zero, but rather it's failing to parse and not displaying an error. For example; "string1"=="string1" should eval to 1 but it doesn't.

If you used a Python expression, then I think it would work.

We should report this as a RFE

  • Like 1
Link to comment
Share on other sites

  • 6 years later...

i am trying to change the value of Polybevels filletshape (round, solid, crease etc) through HScript, this is how far i got.

if(ch("../thickness")*2 < ch("../basebevel") || ch("../basebevel") < 0.16), "solid", ch("../filletshape"))

it doesnt work though, what am i doing wrong?

 

btw chs does not work for this ordered menu. even when i am pasting relative references from another Polybevel node filletshape menu. i suppose it expects the index of the item?

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