Cursor type change from RhinoCommon sample?

Hi All,

Does anyone have experience with changing the look of the cursor via scripting? (Python + RhinoCommon). For now I am interested in the Rhino built-in types like the zoom/pan/rotate view navigation symbols that replace the arrow cursor on view navigation, or a crosshair when drawing…

Thanks for any suggestion.

–jarek

Yes I did this before, I’ll see if I can dig up an example

You change it through Rhino.UI.CursorStyle:

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_UI_CursorStyle.htm

example is when using GetPoint: (example from https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Input_Custom_GetPoint__ctor.htm with added cursor code)

import Rhino
import scriptcontext
import System.Guid

def AddLine():
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Start of line")
    gp.Get()
    if gp.CommandResult()!=Rhino.Commands.Result.Success:
        return gp.CommandResult()
    pt_start = gp.Point()

    gp.SetCommandPrompt("End of line")
    gp.SetBasePoint(pt_start, False)
    gp.DrawLineFromPoint(pt_start, True)
    gp.SetCursor(Rhino.UI.CursorStyle.Magnify)
    gp.Get()
    
    if gp.CommandResult() != Rhino.Commands.Result.Success:
        return gp.CommandResult()
    pt_end = gp.Point()
    v = pt_end - pt_start
    if v.IsTiny(Rhino.RhinoMath.ZeroTolerance):
        return Rhino.Commands.Result.Nothing

    id = scriptcontext.doc.Objects.AddLine(pt_start, pt_end)
    if id!=System.Guid.Empty:
        scriptcontext.doc.Views.Redraw()
        return Rhino.Commands.Result.Success
    return Rhino.Commands.Result.Failure

if __name__=="__main__":
    AddLine()
1 Like

thanks Gijs, this is interesting and the sample works well.
In the docs I can only find the .SetCursor being available for GetPoint or GetTransform.

What if I just wanted to change the cursor independently of any “getters”? Say:

  1. Print something
  2. Change cursor
  3. Wait
  4. Print something else
  5. Change cursor back

Is that currently possible ?

thanks!

–jarek

I figured out how to do it using System cursors; would it be possible to use the cursors available in Rhino in a similar way?

from System.Windows.Forms import Cursor, Cursors
import rhinoscriptsyntax as rs

# Turn on the waiting or busy cursor symbol
Cursor.Current = Cursors.WaitCursor
rs.Sleep(1000)
# Turn on the waiting or busy cursor symbol
Cursor.Current = Cursors.Hand
rs.Sleep(1000)
# reset cursor
Cursor.Current = Cursors.Default

thanks!

–jarek

Yes I think that’s the only way afaik

1 Like