Interactively deselect objects

Hi all

I have a script that builds and then selects a few objects.
Then the user has to be able to deselect some of the already selected objects.
Currently I use a workaround.
But I’d like to learn how to do that in a more straightforward way if possible.
That is: How can I make the user able to deselect already selected objects ?
( I tried running Rhino.Input.Custom.GetObject on the selected objects, pushing Ctrl to deselect, but it did not work )

Thanks

maybe u could try using internal rhino command through rs.Command(), for example,
rs.Command("_SelBrush") could solve your problem, or check out rhinoscript FirstObject(), NextObject() commands

Ciao @emilio,

i’ve tried Rhino.Input.Custom.GetObject and it seems to work, make sure you have something selected before running the script:

import Rhino
import scriptcontext
    
def Deselect():
    go = Rhino.Input.Custom.GetObject()
    go.EnablePreSelect(False, True)
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False
    go.AlreadySelectedObjectSelect = True
    go.SetCommandPrompt("Click on selected object to unselect")
    while True:
        get_rc = go.Get()
        if get_rc == Rhino.Input.GetResult.Object:
            obj_ref = go.Objects()
            obj_ref[0].Object().Select(False,True)
            scriptcontext.doc.Views.Redraw()
            continue
        break
    # TODO: 
    # get the remaining selected object ids
Deselect()

However, i cannot find something like the ControlKeyDown argument which seems to be available only with Rhino.Input.Custom.GetPoint.

c.

Ciao Clement !

That works perfectly :slight_smile:

I had not thought about using GetObject() this way …
Nice idea !

Thanks a lot for your help !

P.S.

I’m not able to see the ControlKeyDown argument in GetPoint
Which method ?

P.P.S

Thanks @texbls for your reply.

great it is working :wink:

I’ve meant this which seems to work when used in conjuction with Rhino.Input.Custom.GetPoint to check if the CTRL key was pressed while a point was picked, but you are picking objects…

c.

OK
Thanks for clarifying Clement !

Hi all,

It would be possible to convert Clement’s script into RhinoScript Editor?
Thank you.

@0904, i am not sure i understand. Do you want to use RhinoScript (rvb) instead of python ?

_
c.

Yes, exactly.

My vbscript is a bit rusty but try attached to pick and unselect single objects from a pre-selection:

PromptForDeselect.rvb (2.6 KB)

_
c.

1 Like

It’s perfect compliments, it was just the result that I wanted :slight_smile:
Thanks Clement again Congratulations

Here is another way to do this - with RhinoScript.

It uses an external HTML file that allows to run a script within a script to pre-select objects while at Rhino.GetObjects prompt.
The sample HTML file should be saved in C:\ root folder for testing but with a bit more code it could be created on the fly by the script calling it. With this method, the deselection happens same way as in Rhino (with CTRL), also allowing for multiple object deselect.

unselect.zip (1.1 KB)

Here is the same sample with no need for additional HTML file (HTML is embedded in the RhinoScript and created only on the first run of the script):

InteractiveDeselectWithHTML.rvb (3.4 KB)

Thanks Jarek and thanks to all for the help :slight_smile:
are long scripts, alone it was impossible for me

Congratulations guys you are amazing