Changing icons on Mac and PC

Hey everyone, I’ve got an extension I’m trying to modify… Right now the icons for this extension are SVG files, so they currently only work on PC installs. I’d like for them to work on the Mac, and for that I need PDF icons. I have both of those made already.

What I’m having trouble with is modifying my ruby script to detect Mac VS PC

Here’s the current snippet of code for my icons:

icon = File.join(PATH, PLUGIN_ID, “test.svg”)

cmd.small_icon = icon
cmd.large_icon = icon
cmd.tooltip = "test tooltip"
cmd.status_bar_text = "Test Extension"
cmd.menu_text = "Test Extension"
toolbar = toolbar.add_item cmd

Is there some way I can do an IF statement that tests for Mac, and if it’s not, it’ll do the PC icons? I’ve tried a few things, and I can’t get anything to work…

Since SketchUp 2014 you can test Sketchup.platform, see the Ruby API documentation. For older versions it was typical to test whether RUBY_PLATFORM =~ /darwin/ to detect Mac.

perhaps:

EXT_PIC ||= Sketchup.platform == :platform_osx ? '.pdf' : '.svg'
...
icon = File.join(PATH, PLUGIN_ID, “test#{EXT_PIC}”)
...

Thanks for the fast response!

Ok, I tried this:
toolbar = UI::Toolbar.new “blah.com

cmd = UI::Command.new("blah.com") {
	self.export
}

EXT_PIC ||= Sketchup.platform == :platform_osx ? 'cnc.pdf' : 'cnc.svg'

icon = File.join(PATH, PLUGIN_ID, “cnc#{EXT_PIC}”)
     
@cmd.large_icon = icon
@cmd.small_icon = icon
 
cmd.tooltip = "blah.com"
cmd.status_bar_text = "blah"
cmd.menu_text = "blah.com"
toolbar = toolbar.add_item cmd

And the extension is failing to load… I’m sure I’m missing something basic…

PS, I am NOT an experienced developer :slight_smile:

Check the difference! :stuck_out_tongue_winking_eye:

Ah, I fixed that and my extension is still failing to load…

I’ve go to be missing something really basic here… Is there anything else I need to do to make this work?

Be wary of copying code when it is not properly wrapped in the forum (as you did above.)
The forum replaces double quotes with smartquotes, which Ruby cannot understand.

Also in your code snippet you have both a local reference (cmd) and an instance reference (@cmd.)

Other than these, you’ll need to quote the error message.

THAT was it!

Thanks Dan, and @dezmo. It works perfectly now, thanks so much!!

1 Like