Command icon
-
Hey,
I 'm working on a toolbar for my script, but the icon that i've asociated with the command won't appear on the button.
Does anyone see what i'm doing wrong?
This is my code snippet:$plugins = Sketchup.find_support_file "Plugins", "/" result = UI;;Command.new("Print results"){print_info} result.status_bar_text = "Print the resultfile" result.small_icon = File.join($plugins,"Icons","Result.png") toolbar = UI;;Toolbar.new("SuFiQuaD") toolbar = toolbar.add_item result toolbar.show
Does the image of the icon has to be exactly 16x16 or 24x24 pixels? Can i put the image file in the Plugins folder?
Why is there a difference between small and large icon?
thanks a lot for any help. -
You can put the icons wherever you want. I would recommend a sub folder in the plugins folder, just to keep things cleaner in your user's plugins folder.
There are 2 sizes, and they do have to be correct size - SU will resize them. But they foten gets messed up on Mac's and SU does a poor job resizing them, so you lose quality. And the 2 sizes correspond to the user setting of displaying large icons or small icons.
As for the code?, well I'm really bad with file handling so I'll let someone else look that over. Files still cause me headaches, even for the simplest of tasks. I know its easy enough, it just somehow always get the better of me. so good luck on that!
Chris
-
@chris fullmer said:
And the 2 sizes correspond to the user setting of displaying large icons or small icons.
They are user settings? Thought they where fixed to 32px and 24px...
-
Not user settings to control the pixel sizes, just to control if they display the large or the small size. They don't get to control the dimensions beyond saying big or little.
But that is why there is the 2 different sizes in the API, which is what I thought the question. Maybe I misunderstood.
-
Yes exactly, that was my question, i didn't understand why i needed to add two different sizes of icons to the Command.
I think i did everything as explaned in the API docs, but i still won't display the icon. Are there any settings that i should check? Or something like .visible = true? -
Are you getting the toolbar with no icons on it? Or no toolbar at all?
-
The two different icon sizes are used for the two sizes of toolbar buttons - large and small. If you only provide the large one the other will be inferred from that, but it might be not as sharp as making one for each size...
If you have the image files in the Plugins folder it gets cluttered so it's recommended you keep them in a sub-folder - your script then needs to find them so code the path in.
For example, in a mythical plugin [XXX.rb] you locate the ruby file's directory, then set the image file's path to the images' sub-folder [XXXimages] that's in the Plugins folder [or where the .rb file resides] thus:
dir = File.dirname(__FILE__)+"/XXXimages/"
then I set the images thus:assuming the command has been set and is called somehow - like...
cmd = UI::Command.new("XXX"){xxx()}
if it's a def() or if it's a 'tool' like...
cmd = UI::Command.new("XXX"){Sketchup.active_model.select_tool(XXX.new)}
then you set the icons thus...
cmd.small_icon = dir + "XXX_small.png" cmd.large_icon = dir + "XXX_large.png"
or whatever you have actually called the images...
Incidentally you add a tooltip to the cmd/button thus:
cmd.tooltip = "XXX's Tooltip..."
If you get a toolbar that works without images on the buttons then the images' path is wrong.
If you get no toolbar and you can't activate it from the View > Toolbar menu then the code is wrong.
-
@kat said:
Yes exactly, that was my question, i didn't understand why i needed to add two different sizes of icons to the Command.
I think i did everything as explaned in the API docs, but i still won't display the icon. Are there any settings that i should check? Or something like .visible = true?From your code it appear you only added small icon. Hav eyou set your toolbar view to Small Icons? The default are Large.
Advertisement