Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I have a question regarding writing multiple conditions in Python. I wanted to write a set of rules in Grasshopper Python that has a set of conditions. So, what I initially plan to do is for the code to go 'if A is True then go to B and if B is true then go to C and if all is true then the answer is X'. But in my current script, the codes are very repetitive and doesn't work that way. Do any of you know how to make this script more efficient? Thank you in advance. I would appreciate your help.

Views: 514

Replies to This Discussion

Python is not my thing, but considering the genericness of the problem, I would break up the logic thusly (in C#):

// Reject numeric cases.

if (a >= 10 || c != 0) return -0.4;

// Reject textual cases.

if (b != "Square" && b != "Circle") return -0.4;

// Handle final case.

if (d <= 1) return -0.5;

if (d == 2) return -0.3;

if (d >= 4) return -0.2;

return -0.4;

I think the problem might be that all your 'and' and 'or' keywords are on the same level. It think you need to combine the two statements on either side of the 'or' operator into a single block, probably using precedence brackets.

Dear David,

Thank you for the reply. I have used your concept and it works well. Thank you very much for your help.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service