magneto Posted August 6, 2012 Share Posted August 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
eetu Posted August 6, 2012 Share Posted August 6, 2012 The indices seem to work fine for me; if(ch("type") == 0, 1 ,0) parm.hip 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 6, 2012 Author Share Posted August 6, 2012 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? Quote Link to comment Share on other sites More sharing options...
eetu Posted August 6, 2012 Share Posted August 6, 2012 Yeah, you've mixed up the true and false values in your outer if clause. if(ch("type") == 2, 2 , if(ch("type") == 1, 1 ,0)) parm2.hip 1 Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 6, 2012 Share Posted August 6, 2012 (edited) 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 August 6, 2012 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
anim Posted August 6, 2012 Share Posted August 6, 2012 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 2 Quote Link to comment Share on other sites More sharing options...
hopbin9 Posted August 6, 2012 Share Posted August 6, 2012 (edited) 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 August 6, 2012 by hopbin9 2 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 6, 2012 Author Share Posted August 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
hopbin9 Posted August 6, 2012 Share Posted August 6, 2012 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 1 Quote Link to comment Share on other sites More sharing options...
graham Posted August 6, 2012 Share Posted August 6, 2012 Hscript doesn't support string comparisons using '=='. You need to use either strcmp() or strmatch() to test 2 strings for being the same. 2 2 Quote Link to comment Share on other sites More sharing options...
magneto Posted August 7, 2012 Author Share Posted August 7, 2012 Thanks guys, == not working for string surprised me, but thanks Graham for mentioning the string compare functions. I thought they didn't work for this before. Quote Link to comment Share on other sites More sharing options...
philpappas Posted December 13, 2018 Share Posted December 13, 2018 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? Quote Link to comment Share on other sites More sharing options...
Noobini Posted December 14, 2018 Share Posted December 14, 2018 shouldn't "solid" be 1 ? menu could be 0 - blah 1 - blah blah 2 - blah blah blah so you use 0, 1 or 2......not blah...coz that just for people to read.....machines want 0, 1 or 2.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.