Grasshopper

algorithmic modeling for Rhino

After running a python script in rhino, can I have more options to click when prompted?

Hi guys!

Sometimes I find it takes a lot of time to input some same numbers when prompted after running python scripts in rhino, like rs.GetReal function.

For example, What I am doing now is something like:

rs.GetObject(....)

rs.GetReal(....)<=======Pause

rs.GetReal(....)<=======Pause

what I want is like:

please select a curve to do something (optionA = DefaultSettingA, optionB = DefaultSettingB, optionC = DefaultSettingC and etc.):

If I want to modify a certain curve's attribute, I can click optionA or optionB to do that. But most of the time I repeat the same action. I don't want to get paused by setting ABC everytime.

So, any idea to create this kind of thing? Just like what we see when we click the Polyline button in rhino:

Next point of polyline. Press Enter when done ( PersistentClose=No  Close  Mode=Line  Helpers=No  Length  Undo ):

Views: 925

Replies to This Discussion

I think you might have better luck answering this over on the McNeel Discourse forum. Under the scripting category to be more exact..

Hi Wang,

Anders is right, this is more of a rhino python, not a grasshopper scripting question. So better place would be the forum he posted.

Still, the response is simple:

You can set rs.GetReal to some default value, and just press Enter (or right mouse click) to comfirm the usage of default value, once promted to input some real numer. In the example bellow 10.0 and 20.0 are default values:

import rhinoscriptsyntax as rs

curveId = rs.GetObject("pick up your curve", 4)
n1 = rs.GetReal("input some number", 10.0, 1.0)
n2 = rs.GetReal("input some other number", 20.0, 2.0)

If you do not want to type in some numeric value, but rather choose between two options (like in Polyline command you mentioned) use rs.GetBoolean function:

import rhinoscriptsyntax as rs

curveId = rs.GetObject("pick up your curve", 4)
settings = ["optionA", "DefaultSettingA", "customSettingA"], ["optionB", "DefaultSettingB", "customSettingB"], ["optionC", "DefaultSettingC", "customSettingC"], ["optionD", "DefaultSettingD", "customSettingD"]
pickedAttributes = rs.GetBoolean("choose curve's attributes", settings, [True, True, True, True])
for patt in pickedAttributes:
    print patt

Boolean values which you got from "pickedAttributes" list could then be further used to process your data (for example as indexes for picking items from some list - True equals to 1, and False to 0).

Where's the like button when you need it :)

Hi djordje!

Thank you for your always being kind to help! You've given me a detailed answer and I have tried that! I can have clickable options now! I used to do just like your first method. I'll consider your second one and find out how to combine it with my scripts! :-)

Hi Anders!

Thank you for giving me such a good advice. I'll search this forum to check if there has been similar question. :-)

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service