Can an Osnap be subtracted from a set in a Python script?

What I would like to be able to do is take a “snapshot” of the current Osnap state (easy to do) and subtract one from the current set. For example, let’s say the user has End, Near, Point and Cen active when the script begins. But I want whatever they had active to stay active with the exception of Near. Let the script execute with Near turned off, then when the script ends, restore their Osnap state (that part is easy to do too).

The next user might have Near, Point and Mid enabled, and I want that state to exist with the exception of Near. Each user might have a different Osnap state, so that’s why forcing certain Osnaps isn’t the answer (I already do that, I’m trying to improve on that).

Hope this makes sense,

Dan

Hi @DanBayn, you might try below:

import rhinoscriptsyntax as rs

def DoSomething():
    old_modes = rs.OsnapMode()
    rhOsnapModeNear = 2
    
    # check if Near is enabled
    if old_modes & rhOsnapModeNear:
        new_modes = old_modes - rhOsnapModeNear
    else:
        new_modes = old_modes
    
    # set new modes, but without Near
    rs.OsnapMode(new_modes)
    
    # prompt for a point
    point = rs.GetPoint("Pick a point")
    
    # reset to old modes
    rs.OsnapMode(old_modes)
    
DoSomething()

_
c.

2 Likes

Hi Clement,

Thanks, I will give this a try,

Dan