RhinoCommon - Pre-and Post- select subobjects

Last one for today - I am trying to figure out how to include a preselected set of subobjects (say, brep edges) into a selection process where one can continue selecting more edges and removing some of the existing ones from the selection.

I have tested many different variations, the best I have been able to do is run the process twice, once to get the preselection, and once to get the post selection, but I don’t know how to be able to interact with the preselected ones after (in case I want to deselect some).

The end goal is that the preselected subobjects will be chosen programmatically, not by hand, but for testing one can simply preselect a few with Ctrl+Shift+Pick. then in the script, I want to ask the user to edit the selection, either adding to or subtracting from it.

The following works for pre- or post selction, but not both. I have tried a bunch of other stuff, but to keep things short here, I will not post them all.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def TestSO(prompt,filt):
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt(prompt)
    go.GeometryFilter=filt
    go.SubObjectSelect=True
    go.ChooseOneQuestion = True
    go.GetMultiple(1,0)
    if go.CommandResult()!=Rhino.Commands.Result.Success:
        return go.CommandResult()
    objrefs = go.Objects()
    if not objrefs: return Rhino.Commands.Result.Nothing
    rc=[]
    for objref in objrefs:
        indices=[]
        for item in objref.Object().GetSelectedSubObjects():
            #select subobject
            objref.Object().SelectSubObject(item, True, True, True)
            #append index to return
            indices.append(item.Index)
        rc.append([objref.ObjectId,indices])
    return rc

prompt="Select some brep edges"
result=TestSO(prompt,Rhino.DocObjects.ObjectType.Curve)
print "{} edges selected".format(len(result))
1 Like

Anybody?

1 Like
2 Likes

How about this?

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def Test():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select edge curves")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.EdgeCurve
    go.SubObjectSelect = True
    go.GetMultiple(1, 0)
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return go.CommandResult()
    
    for objref in go.Objects():
        edge = objref.Edge()
        if edge:
            print(objref.Object().Id, edge.EdgeIndex)

Test()

– Dale

1 Like

HI @dale,

No unfortunately, that doesn’t do it - I have basically the same code, the problem is if some edges are preselected, when you run it, it simply returns those.

What I am looking for is some way to keep the preselected edges and then be able to ask the user to edit the selection - either adding additional edges or removing some of them from the original preselection. I tried a bunch of stuff, but so far no success. :confused:

1 Like

Hi @Helvetosaur,

I don’t recall why this sample came to be, but you might be able to gleam something from it.

SampleCsPrePostSelect.cs

– Dale

Yeah, that looks similar to the sample from here:

I wasn’t able to get it working with subobjects, but I will try again…

Is any body here

Hi @Helvetosaur and @rhinoceros.adv,

i’ve tried something which is based on Dale’s work. It returns a dictionary where key is the brep object id and value is a list of edge indices. It keeps edges selected after exit and during a command option change.

GetEdgesCustom.py (2.3 KB)

_
c.