Scripting deselection


The situation:
I want to create geometry on certain sub-curves of a polycurve.
What I would like to do is
1 - select the polycurve
2 - explode the curve
3 - let the user edit the selection of exploded subcurves (de-select/re-select)

Does anybody have an idea how to approach this?
Specifically I’m looking for a way to have a selection active and toggle selection from it by user pick.

I have it working but only blindly; I cannot have the current selection selected while in a rs.GetObjects()

Working with Displayconduit I got a little further:
Question now would be how to catch an object click/pick.
In other words how catch clicking on an object.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import System.Drawing as SD
import Rhino

class DrawCurves(Rhino.Display.DisplayConduit):
    def __init__(self, curves):
        self.color = SD.Color.FromArgb(255 ,255, 0)
        self.curves = curves

    def DrawOverlay(self, e):
        #print 'drawing'
        for curve in [rs.coercecurve(curve) for curve in self.curves]:

def EditSelection(selection):
    # filter to only select objects in selection
    def selFilter(rhino_object, geometry, component_index):
        return rhino_object.Attributes.ObjectId in selection
    new_selection = selection [:]
    conduit = DrawCurves(new_selection)
    while True:
        conduit.Enabled = True
        objs=rs.GetObjects("Toggle Objects",custom_filter=selFilter)
        if not objs: 
            conduit.Enabled = False

        for obj in objs:
            if obj in new_selection: #delete from new_selection
            elif obj in selection: #add to new_selection

    conduit.Enabled = False
    return new_selection
def Test():
    polycrvs = rs.GetObjects('curves',filter=4)
    if not polycrvs: return
    exploded = rs.ExplodeCurves(polycrvs, delete_input=False)
    curves = EditSelection(exploded)


Hi Willem,

Are you trying to replicate the interface provided by the ExtractSubCrv command?

– D

Hi Dale,

First of all thanks for pointing to ExtractSubCrv never used it and it indeed seems close to what I need.

In the example images above the indentations on the rectangular shape need no tabs when laser cut.
So what I want to do is select the complete closed curves and next deselect ( via window selecting) the curves forming the indentations and deselect them. I was looking for a way to do this that provides some visual feedback and can have itterations to correct possible mistakes in de-selecting.

I have a working script ATM , yet as an exercise I was wondering if I could not streamline it and get a script to select-toggle selection of objects.

So for now don’t spend much time on this, only if you have something at hand.