Cursor in ruby tutorial

I’m looking for a great tutorial for creating a new cursor in Ruby.

To create Icon I try to use Layout then export as pdf for mac and convert it into svg with online service.
But it didn’t work
I was suspecting the size of the pdf 72x72.[icons.zip|attachment]

After I try an online service to create and svg and convert it into pdf with another online service
the dimension of the pdf is now 24x24
But it didn’t work.

please find enclosed the all theicons.zip (61,5 Ko) file

So as alway , I use the same bad method that I always use with 64x64 png where I change the hot point depending of the platform ( mac or pc)

Please find enclosed fin actual code that work but not with svg or pdf (only png)

	class SimpleMoveTool


  	 	###################
  	 	###################
  	 	##### ICON  #####
  	 	###################
  	 	###################


        if(RUBY_PLATFORM =~ /darwin/)
		  middle_cursor_point = 45
          #iConeDeLoutil = "move_copy.pdf"
        else
		  middle_cursor_point = 22
          #iConeDeLoutil = "move_copy.svg"
        end

		extension_dir = __dir__.dup
		extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)

		cursorDir = File.join(extension_dir, "..", "icon")

        iConeDeLoutil = "move_yes.png"
		cursor_path = File.join(cursorDir, iConeDeLoutil)
		CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point, middle_cursor_point) if File.exist?(cursor_path)


	def initialize
         ....... 
		@current_cursor = C    URSOR_ID
    end

    def onSetCursor
			UI.set_cursor(@current_cursor)
	end

Don’t worry about file name (there is 3 icons )

I 'm looking an complete explanation about cursor inruby. Thanks for your help

There is one thing I can say about your previous example here …

… is that the pixel indices are zero based and therefore if cursors were standard on 64 pixels square, … then your y index is out of bounds because the first index is 0 and the last is 63.


I think Thomas has explained it in an older topic here somewhere.

On Windows at 100% display scaling the cursors are the same size as the large toolbar icons. (ie, 24 x 24 pixels, … small icons being based upon 16 x 16 pixels.) [The Ruby API documentation does not really note any difference between the Win and MacOS platforms.]

Which brings us to …

if(RUBY_PLATFORM =~ /darwin/)

BTW, Ruby doesn’t use parenthesis around conditional expressions unless we need to control the order of evaluation. Doing this makes code harder to read.

The test against the global RUBY_PLATFORM has always been discouraged in favor of other methods. Use it as a last resort. Since SketchUp 2014 the API has had the Sketchup::platform module method which should be preferred …

if Sketchup.platform == :platform_osx

If you support pre-2014 SketchUp versions (running Ruby 1.8.x) the method call to Sketchup::platform would raise a NoMethodError so a rescue in modifier position can trap this and use the fallback …

if Sketchup.platform == :platform_osx rescue RUBY_PLATFORM =~ /darwin/

Most coders set a platform constant(s) at the top of their extension module so that the platform test is only done once when the module loads. All conditional expressions depending upon platform then reference the boolean constant(s).

WIN = Sketchup.platform == :platform_win
MAC = !WIN

Continuing on the cursor subject …

SketchUp’s display scaling (aka scaled resolution on Mac) support will automatically scale up toolbar button images, cursors and click apertures. This should mean if you base your cursor hotpoint coordinates on the standard, then SketchUp should scale the location as appropriate for the users display scale setting.

If it doesn’t then it is a bug in the API and should be logged in the API Issue Tracker.

  • I’ll try and see if I can find Thomas’ previous example in the forum.
1 Like

This old topic seems to indicate that the standard size for cursors is 32 x 32 …

… the topic starter Bruce was also having issues trying to use 64 x 64 PNG images for cursors.

I change the hot spot and the way to check plateform and its works !

I put my final code below:

  ...
  	WIN = Sketchup.platform == :platform_win
  	MAC = !WIN
  ...

if MAC
	  middle_cursor_point = 12
	  icon_extension = ".pdf"
else
	  middle_cursor_point = 12
	  icon_extension = ".svg"
end

	extension_dir = __dir__.dup
	extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)
	cursorDir = File.join(extension_dir, "..", "icon")

iConeDeLoutil = "move_yes#{icon_extension}"
	cursor_path = File.join(cursorDir, iConeDeLoutil)
	SSIMPLE_MOVE_CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point, middle_cursor_point) if File.exist?(cursor_path)
1 Like

Sorry, im back about cursor :frowning:
The svg that I use for cursor appear as a black square on a Windows10surface pro, Sketchup pro 2020
I check the svg with W3C validator and its ok.
I compare with a native cursor of sketchup (cursor_offset.svg) and the only difference was on svg structure.
I make this try:

  • On mine svg I don’t have < title > and < desc > markup. I try to add it be nothing change.
  • A another difference was the width and height. They are define as “24” instead of “24px”. I update it but nothing change.

On my svg I have something in the markup. On the offset svg I haven’t. I don’t know the way to change that.

Please find the svg file
simple_move_yes.svg.zip (1,8 Ko)

find the original sketchup cursor cursor_offset.svg.zip (2,2 Ko)

The code to load the SVG ( that work for the pdf on mac)

...
    if MAC
	  middle_cursor_point = 12
	  icon_extension = ".pdf"
    else
	  middle_cursor_point = 12
	  icon_extension = ".svg"
    end

	extension_dir = __dir__.dup
	extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)
	cursorDir = File.join(extension_dir, "..", "icon")
	# NORMAL CURSOR
    iConeDeLoutil = "simple_move_yes#{icon_extension}"
	cursor_path = File.join(cursorDir, iConeDeLoutil)
	SSIMPLE_MOVE_CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point,

There are old topics about this. Try using Inkscape to resave the SVG. Or perhaps GIMP ?

argggggggggggg
Inkscape isn’t compatible on the last release of Mac and Gimp rasted the svg , …
I will try all free tool on the web and comeback

Thanks @DanRathbun

A Cursor manual is missing.

After few quick and unsuccessful research and try, I decide to use png :sob:

thanks for sharing this

Bonjour Denis, est-ce les coulisses du Plugin Simple Tools?
J’ai regardé la vidéo de présentation hier et je suis très intéressé!
Est-ce possible de configurer des composants pour faire un mix entre Simple Tools et Woody?
J’ai démarré le Ruby il y a un an…c’est long et laborieux mais je ne lâche pas!
Je cherche à faire un petit plug-in pour les charpentes et les mur ossatures bois que nous fabriquons notamment des caissons Ossature bois isolation paille.

J’espère pouvoir échanger avec toi prochainement en PM.
Bien cordialement,

Bonjour,
Oui après relecture c’est bien simple tool.
J’ai passé la barre des 100 repo github dont la plupart sont des extensions Sketchup.
Pour répondre à ta question de mix: bien sur contact moi en MP
Sinon, on cherche activement quelqu’un pour faire des extensions et d’autres dev. :slight_smile:

1 Like

What didn’t work?

The SVG support in SU for icons is somewhat limited. There’s a few features in SVG that isn’t working. I’ve been running into this myself and it’s been a hit and miss. We’ve been talking about this internally. Personally I’d like to look for a better SVG library that we can use on both Windows and Mac such that extensions only need to ship with a single image file (short of the need for backwards compatibility.)

I’ve created icons in a new different ways. Some times I create a SketchUp model and take that into LayOut for a Vector render. From LO I export a PDF and then convert that to SVG. The SVG conversion can be a hit and miss due to the limited SVG support.

In other cases I create the icons in InkScape and then convert the SVG to PDF.

When I’ve had icons that needed individual adjustments for the large vs small sizes I’ve often used Illustrator because it allows multiple artboards and I can work on both versions in the same file.

I even made myself a reminder of the process for TrueBend:
true-bend/Process.md at master · thomthom/true-bend (github.com)