Noob Question

I’m trying to give myself an easy introduction to RhinoPython by writing a simple script I can attach to a hotkey.
The purpose is to be able to toggle PointsOn and PointsOff using one hotkey instead of two.
If I have objects selected I want to be able to turn on points, or otherwise turn points off (unless someone has a better suggestion). The first part is working.
I’m getting stuck on the _PointsOff part.

objects = rs.SelectedObjects()
if objects: [rs.EnableObjectGrips(obj) for obj in objects]
Any help would be appreciated.

Hi André,

there might me several ways to do this. One simple way is to asume that whenever an object is selected, you want to turn its points on and unselect it. Since you cannot select objects which have points enabled, i´ve asumed that if nothing is selected, you want to turn points off instead. The last step acts globally and turns points off for all objects like the Rhino command does.

import rhinoscriptsyntax as rs

def TogglePoints():
    objects = rs.SelectedObjects()
    if objects: 
        for obj in objects:

if __name__=="__main__":

Another way would be to add the object ids of the previously selected objects in the sticky context of the scriptcontext module. When the script is run again, those ids can be iterated and if the objects have points on, they could be turned off. If you want to go this route, take a look at the “sticky” example under help / samples of the python editor.


Thanks so much for your help. That’s exactly what I was looking for.
I knew there must have been a simple way to replicate the keyboard Rhino command “_PointsOff”, For the life of me I just couldn’t find it. I’m not sure how I missed it in my Google hunts :blush:

I originally thought of doing as you suggested for the alternate solution and use the object ids of the previously selected objects to turn them off, but I thought this might lead to some undesired behaviour if the script wasn’t used to turn points on in the first place. Or check the status of every object in the scene (even worse idea). The solution you provided is exactly what I wanted.

I better finish reading the Rhino Python Primer…

Edit: to any other noob who wants to assign this to a hotkey…
! _-RunPythonScript “C:\Users*user*\Rhino*user*\scripts\” (305 Bytes)

PS Generally unrelated to scripting and tangentially related to the script above (I thought someone out there might think the following is useful).
I bought a Space Navigator (SN). Since it requires one to keep on hand on the mouse and one hand on the SN, it leaves me one hand short for the keyboard. Going back and forth between keyboard is a bit tedious, develops the bad habit of defaulting using icons too much and therefore adding too many mouse miles. 3Dconnexion offers higher end devices with programmable buttons but at a higher cost. I wanted to save a bit of money so I purchased a Logitech G600 mouse with 20 programmable buttons. It sounds like a lot of buttons but I don’t want to waste any space using two buttons for what can be accomplished with one (hence the excuse to bone up on python scripting, and the script above). So I’m loading it up with the hotkeys, macros, and scripts that best suit my workflow. So far its been great. For example, just having a few simple keys on the mouse like Ctrl, Alt, Shift, Ctrl+Shift, '_-Gumball, _Sweep2, ! _Split _Pause _Isocurve, Undo/ Redo (on the mousewheel tilt), etc has been very handy. (By default it comes set up as a number pad which was a pretty good start to begin with).

Hi André, intersting mouse. Thanks for posting.