I’m trying to use GetOption in Rhinoscript, but I can’t figure out how to make it persistent so that a user can select & change more than one of the items. Is there a way to do this? I want it to persist until the user clicks enter.
Recall getOption in a while loop until enter or cancel or failure.
Hi Peter - I think all this stuff is way easier using the ‘sticky’ dictionary in conjunction with RhinoCommon - it may be that you can make an equivalent less persistent thing by putting the GetOption in a loop, and replacing the current option value with the new onw as you go.
You can checkout the script I posted earlier that uses exactly what you need (bolt script)
Pascal, thanks but I don’t really get python. Is there another (more vbscript-y) way to use RhinoCommon?
Regarding putting it in a loop - yeah, that’s what I’ve tried to do, but I can’t figure out how to create a loop with GetOption. Well, I can put it in a loop, just can’t get out of the loop. There is no escape unless I make one of the clickable command-line options “done”.
Here’s the example from the RhinoScript help file (modified slightly so that it runs):
Const OPT_SGL = 0 Const OPT_BLN = 1 Const OPT_INT = 2 Const OPT_DBL = 3 Const OPT_LST = 4 Dim arr0, arr1,arr2, arr3, arr4 Dim lst, opt, rc,i, X lst = Array("One", "Two", "Three", "Four") arr0 = Array(OPT_SGL, "Single") arr1 = Array(OPT_BLN, "Boolean", "Off", "On", False) arr2 = Array(OPT_INT, "Integer", 4, "New value", 2, 10) arr3 = Array(OPT_DBL, "Double", 34.76, "New value", 1.0, 100.0) arr4 = Array(OPT_LST, "List", lst, 0) opt = Array(arr0, arr1, arr2, arr3, arr4) rc = Rhino.GetOption("Scriptingoptions", opt) x = 0 If IsArray(rc) Then For Each i In rc Rhino.Print i Next End If
Thanks, but the GetOption in those scripts is not persistent - it just goes from one GetOption to the next GetOption, right? GetOption lets me put multiple options on the command line at once so I’m wanting the user to be able to change more than one of the options. I’m probably not making sense.
I’ll probalby just use GetString instead (easy to loop until user hits enter) - I was just thinking that GetOption seemed like the logical tool. But, the big downside to GetString is that I can’t use equal signs in the clickable items.
Hi Peter - see if this does anything for you - I pared it down to one option -
Call TestOptions() Sub TestOptions Const OPT_INT = 2 Dim arr2 Dim lst, opt, rc,i Dim intVal: intVal = 4 Dim X: x = True Do arr2 = Array(OPT_INT, "Integer", intVal, "New value", 2, 10) opt = Array(arr2) rc = Rhino.GetOption("Scriptingoptions", opt) If IsArray(rc) Then If rc(0) = intVal Then Exit Do Else intVal = rc(0) End If Else Exit Do End If Loop End Sub
So…it’s looking to see if intVal is new, and escapes if it is not. I guess, if opt has more arrays in it, I could check and if none of the values changed, then I could escape the loop. Thanks - I’ll try it.
Pascal, unfortunately that’s not going to work. One of the main purposes of having command-line options is so that a macro can be made, but if I have more than one command-line option and if the macro’s first value is the same as the default, the do loop ends. That might sound like an unlikely scenario, but I’d probably fill those default values with the last-used value, making it actually really likely to be a problem. For example, if I create a macro like:
! -loadscript “test.rvb” integer 4 integer2 1 enter
For the following script, it kicks me out before the 2nd item (integer2) can be read.
Const OPT_INT = 2 Dim arr1, arr2 Dim lst, opt, rc,i Dim intVal1: intVal1 = 4 Dim intVal2: intVal2 = 2 Dim X: x = True Do arr1 = Array(OPT_INT, "Integer", intVal1, "New value", 2, 10) arr2 = Array(OPT_INT, "Integer2", intVal2, "New value", 0, 10) opt = Array(arr1, arr2) rc = Rhino.GetOption("Scriptingoptions", opt) If IsArray(rc) Then If rc(0) = intVal1 And rc(1) = intVal2 Then Exit Do Else intVal1 = rc(0) intVal2 = rc(1) End If Else Exit Do End If Loop Rhino.Print "Integer is " & intVal1 & " and integer2 is " & intVal2
Not sure if I follow you. In my script I have 3 options that can be changed indefinitely until the user presses enter to go to inserting the chosen bolt. I thought that is what you needed?
that’s because this becomes true:
I was looking at your version addBolt_v0.4 - It does look like you are doing what I want in v0.7. I’ll give it a closer look. Though, as I said, I’m not familiar with Python script and I’m not ready to go down that road. Thanks a lot!
Yeah, I get that - but I don’t see a way around it in Rhinoscript.