REQ - python get real / boolean

just a request for a UI element in rhinoscriptsyntax which combines GetReal and GetBoolean in one shot…
scripting with that rhinocommon stuff is too much for me… (ie- frustrating/ boring / loss of interest / etc :slight_smile: )

basically, a dialog (or, i guess it’s command line options… i just call it a dialog because of how it looks on mac) which has some checkboxes and will also accept numbers.

i don’t really have ideas for how exactly it should be implemented but i wish it was nonetheless.

thanks

Yes, I have asked for this before for Rhinoscript/Rhinoscriptsyntax… You can program custom HTML dialogs (not sure that works on Mac) but that is still a lot of work… I have wished for a rs.GetOptions() method that allows one to combine any number of get strings, get numbers, get booleans, etc. on one command line. Maybe someday…

–Mitch

Hi Mitch, as far as i know the HTMLBox method is ot implemented yet in Python, even on windoze… or did this change in the past and i missed it ?

thanks,
c.

yes… that sounds about right :ok_hand:

No, but there is a tutorial out there by some guy which is what I was thinking of… But you need to have his custom module, which makes the script less portable. I think you can also do it with tkinter… But again, you need to import the module, it won’t be on all installations.

–Mitch

I don’t believe tkinter is going to work with the python implementation inside of Rhino.

Creating dialogs from python is not currently very easy in Rhino, but I’m hoping that will change in the future. Once we have some good cross platform UI tools in place, we should be able to write some simplified UI construction routines. Sorry, but this won’t happen until V6 though.

1 Like

OK, thanks Steve…

getrealbool.py (1.0 KB)

getrb.py (342 Bytes)

Here is my attempt.
No GUI (on win), only a plain GetNumber().
… And very quick & dirty …

First file is the library
Second is a very simple test script

FWIW …

1 Like

Yeah, the main problem again is that the script isn’t completely portable, you need to be able to import the library file (i.e. it has to be on your computer somewhere). It should of course be relatively easy if you have a standard place to put the library files and can set a path to them (I think that’s currently only possible with Windows Rhino).

I think my approach would be to create a bunch of re-usable code functions - pretty much exactly like your library file - and then just paste the appropriate function definition into the script when writing it. That way the script self-contained, anyone can use it. I might make some of these definitions as an exercise for myself later this week…

Cheers, --Mitch

i’m not exactly sure where i’d have to put the library on mac for it to work as you’ve set it up
but if i use the two as one, it does do what i was thinking in the original post:

it properly registers feet&inches with the lazy inch so that’s cool too.

what’s the difference between getReal and getNumber anyway? [edit]nvrmnd… i misinterpreted what you wrote about “just a plain GetNumber” [/edit]


so, is it ok if i use this function in other scripts? (as in- i’m asking your permission to do so)


don’t be afraid to share them :smile_cat:

What I post here is in the public domain, anyone is free to use it as he/she likes.
Just don’t complain if a hidden bug happens to corrupt something … :smile:
( BTW, this script does not check anything … so that is up to you :wink: )

As usual, I’m not aware of what works and what does not work on the Mac, sorry …
But I agree with Mitch that manually importing functions is a nice idea and I’m glad it works for you :smiley:

p.s.

about library files …
What about putting them in the same place as rhinoscriptsyntax.py ?
… well … assuming that such a file exists on the Mac …

Yes, Mitch, good workaround when we cannot use libraries !

You made me remember that that was what I’ve been doing in Rhino 2 and 3 for RhinoScript.
There were not so many RhinoScript methods then, and I liked using my own library functions … which were copied in new scripts when needed.
I thought that maintaining a library of function was too complex and could very easily break older code. Also did not allow me to adapt a helper function to a particular script.
And, last but not least, without external references the scripts could be posted on the NG without problems … :smiley:

Cheers

great. thanks! and don’t worry, i won’t come crying to you when i break your code :wink:

[quote]
But I agree with Mitch that manually importing functions is a nice idea and I’m glad it works for you [/quote]

might be cool to use with an editor which can store snippits… does the built in editor on windows do that? i’ve tried out Atom before which does it pretty easily.



put to use here:

"""ExtrudePlanarCurves -- note* if using BothSides option, the overall extrusion
will be the entered distance.. this is different than bothSides in typical
Rhino Commands in which the distance entered will be 1/2 overall extrusion"""


import rhinoscriptsyntax as rs
import Rhino
import scriptcontext


def extrudePlanar(crv, opts, distance):

    for i in range (len(crv)):
        curve = crv[i]
        plane = rs.CurvePlane(curve)
        origin = plane[0]
        vec = plane[3]
        
        direction = rs.VectorScale(vec, distance)
        point = rs.PointAdd(origin, direction)

        if opts[1]:
            bsdir = rs.VectorScale(vec, distance/2)
            bspoint = rs.PointAdd(origin, bsdir)
            trans = (origin - bspoint)
            newcrv = rs.CopyObject(curve, trans)
            ext = rs.ExtrudeCurveStraight(newcrv, origin, point)
            rs.DeleteObject(newcrv)
        else:
            ext= rs.ExtrudeCurveStraight(curve, origin, point)
    
        if opts[0]:
            rs.CapPlanarHoles(ext)
        if opts[2]:
            rs.DeleteObject(curve)


def getnumbools( prompt, default, boolnames, boolvals ):
    while True:
        scriptcontext.escape_test()
        gnu = Rhino.Input.Custom.GetNumber()
        gnu.SetCommandPrompt( prompt )
        gnu.SetDefaultNumber( default )
        indexlist = []
        optionlist = []
        for ix in range( len( boolnames ) ):
            index, option = gnu.AddOptionToggle( boolnames[ ix ],
                Rhino.Input.Custom.OptionToggle( boolvals[ ix ], 'No', 'Yes' ) )
            indexlist.append( index )
            optionlist.append( option )
        gnu.Get()
        if gnu.CommandResult() == Rhino.Commands.Result.Cancel:
            return []
        res = gnu.Result()
        if res == Rhino.Input.GetResult.Option:
            opind = gnu.OptionIndex()
            ix = indexlist.index( opind )
            option = optionlist[ ix ]
            boolvals[ ix ] = option.CurrentValue
        elif res == Rhino.Input.GetResult.Number:
            number = gnu.Number()
            break
    result = [ number ] + boolvals
    return result



def input():

    crv= rs.GetObjects('Select planar curves to extrude', 4, True, True)
    if not crv: return
    for i in range (len(crv)):
        if not rs.IsCurvePlanar(crv[i]):
            print 'All curves must be planar'
            return

    nas = [ 'Solid', 'BothSides', 'DeleteInput' ]
    vas = [ True, False, False ]
    dft = .75

    tp = getnumbools( 'Extrusion Distance', dft, nas, vas )
    if not tp: return

    distance = tp.pop(0)
    if distance == 0:
        return

    extrudePlanar(crv, tp, distance)

input()

that’s way way better for me :smile:

it’s a good prototype of what could eventually be added to the standard library (imo)