Is there a way change selection filter before command and restore after?

Hello.

Is there a way create a macro that would change selection filter, run the command and then restore filter after command ended/canceled?

Thank you.

hi @vano_artful

you could run a python script to set filters, run the command you want, then reset the filters, e.g.:

import Rhino
import scriptcontext as sc

def SetTemporarySelectionFilter():
    filters = Rhino.ApplicationSettings.SelectionFilterSettings

    # 1. Store the current filter state so it can be restored later
    saved_state = filters.GetCurrentState()

    try:
        # 2. Set the filters you want active for this operation
        filters.Enabled = True
        filters.GlobalGeometryFilter = (
            Rhino.DocObjects.ObjectType.Curve |
			Rhino.DocObjects.ObjectType.Brep |
			Rhino.DocObjects.ObjectType.Surface
        )
        filters.SubObjectSelect = False

        # ... do the work that depends on this filter here ...
        sc.doc.Objects.UnselectAll()
        Rhino.RhinoApp.RunScript("_SelAll", False)

    finally:
        # 3. Always restore the original filter state, even on error/Esc
        filters.UpdateFromState(saved_state)
        print("")

if __name__ == "__main__":
    SetTemporarySelectionFilter()