Use Sketchup Cursors in Custom Tool

I’m trying to create a custom move tool.

I see the following code to use a ‘built in’ SketchUp cursor:

# Here we have hard coded a special ID for the pencil cursor in SketchUp.
# Normally you would use `UI.create_cursor(cursor_path, 0, 0)` instead
# with your own custom cursor bitmap:
#
#   CURSOR_PENCIL = UI.create_cursor(cursor_path, 0, 0)
CURSOR_PENCIL = 632
def onSetCursor
   # Note that `onSetCursor` is called frequently so you should not do much
   # work here. At most you switch between different cursor representing
   # the state of the tool.
  UI.set_cursor(CURSOR_PENCIL)
end

Taken from this example:

I’m wondering if there is a list of values for other SketchUp cursors (specifically the move tool cursor), and if they are ‘safe’ to use in an extension.

I also noticed that using UI.create_cursor the cursor does not scale correctly on Windows 10 with one monitor (4K) set to 175%, and another monitor set to 100%. The build in cursors scale correctly as does the CURSOR_PENCIL = 632

On Mac all of the built-in cursor pdf images are in

/Applications/SketchUp 2020/SketchUp.app/Contents/Resources

I’m not sure what would happen if you passed one of these to UI.create_cursor, but I would guess that you’d get a new cursor that just happens to use the same file as the built-in.

I don’t know where the corresponding svg images are kept on Windows.

If there is a reference for the built-in cursor_id values, I don’t know it.

In win
c:\Program Files\SketchUp\SketchUp 2020\Images
c:\Program Files\SketchUp\SketchUp 2020\LayOut\Images\

Then I’m usually using Web-based vector graphics – Corel Vector to edit and create .pdf .png .svg files.
cursorpic.png
cursorpic.svg
cursorpic.pdf

Then I’m using something like this to define in code:

  if Sketchup.version.to_i >= 16 
    EXT_PIC ||= Sketchup.platform == :platform_osx ? '.pdf' : '.svg'
   else
    EXT_PIC ||= '.png'
  end

  MYCURSOR ||= UI.create_cursor(File.join(File.dirname(__FILE__), "/cursorpic#{EXT_PIC}"), 8, 24)

SketchUp only supports up to 150% display scaling (aka scaled resolution on Mac.)
But with regard to cursors and toolbar buttons, the image must be a vector SVG (or PDF on Mac,) in order to be correctly and precisely scaled. (Raster image formats can get blurry.)

Last cycle I sent in a request to support 4K (200%) and 5K (266%) displays. (I think it is past time.)


I remember starting a topic on this subject. An I think at one time I had a list of all the cursor IDs.
I’ll see if I can find it.

Sure, until they change. :wink:

Since they are undocumented, they’d be subject to change at anytime, without notice.
(I also don’t know if their use would pass the EW review.)

They might change, but their names have been the same for as long as I remember (currently 3~4 months
We use it all the time for support and training

UI.set_cursor( 641 )

(at 3rd trial I got it :wink: )

1 Like

Yeah I finally added an onKeyUp event to increment the cursor up and down in my tool until I found the right one. Thanks anyway.

3 Likes

BTW: Be careful with the integers in set_cursor, I don’t remember exactly which one but that caused a bugsplat crash… when I did the same trials not recently.

1 Like

I didn’t find the topic over at SketchUcation. And I don’t know where that old list is.

I did recreate a bit of the first step I did before. Which was to export (a few) PNG resource images from an old SketchUp executable using Visual Studio. They have the resource id as part of the image filename.

It’s tedious, and once they’ve all been exported compiling the list is a manual job.

sorry that I revive that topic.

How did you found that ID?
Was it only guessing?

I would like to find IDs for standard selection tool and eraser

That would be veerry helpful :slight_smile:

As I had said, I cannot find the list I had long ago created.

You can find the cursor IDs by using the attached tool. You see the cursors by scrolling the mouse wheel up and jiggling the mouse. The IDs start at 629 (for the 2 Point Arc tool.)

Cursor_ID_Sniffer.rb (1.7 KB)

You activate the tool via Tools > Cursor Test

The Cursor Test tool starts with the Select tool cursor shown (ID 633) .
You’ll find the Eraser tool cursor is 645.

3 Likes

thanks!
very clever script.
it’s working like a charm :slight_smile:

1 Like