Changing Command Icons of the Toolbar
-
In my 1st post I had a question about if it is posible to change icons after the command already had an icon set to it. I tried many differrent ways to write a script for that, but none of it worked. I've done many tests on that and figured out that once the icon is set for some command, it can not be changed. Here's one example that icon cannot be changed:
toolbar=UI;;Toolbar.new("Test") cmd=UI;;Command.new("clear_selection") { Sketchup.active_model.selection.clear } cmd.small_icon = cmd.large_icon = "image01.png" toolbar.add_item(cmd) # Changing item icon after adding the item doesn't work. cmd.small_icon = cmd.large_icon = "image02.png" toolbar.show()
After Command "clear_selection" was added to the toolbar, another code activated to change the icon of "clear_selection" command, but could not really change it.
So, my question: Is there a way to change an icon even though i think there isn't?
-
replace the icon png with a different one
-
You can even edit toolbars that come with ridiculous number of icons like this one to have less icons.
As for changing icons, you simply do as Jeff says, pick your desired new icon as same it in the same location with the same name and size (24px x 24px or 16px x 16px)
Here's my custom Extrusion Toolset toolbar with less options and different icons...
-
No u didn't get it, I want to toggle between two or more icon images in the same command button. Like toggling between play and pause icon images. Ex: Click play icon changes to pause image, then click again icon changes back to play image. Is there a way for that?
-
@anton_s said:
Is there a way for that?
oh.. in that case, i don't know.
ask one of these guys --->
[fwiw, i've never seen the behavior before but who knows..]
-
Hay, thanks >>>>>>>>>>>>> I will!!!!!!!!!!!!!
And by the way nice Pen tool, It's much more comfortible to use them!!!! Thanks!!! -
@anton_s said:
Hay, thanks >>>>>>>>>>>>> I will!!!!!!!!!!!!!
well, hopefully, they'll come along and see the question..
you might have a better chance of the right people seeing your question in the developer's forum instead of the newbies section.
-
Well I tested a couple of ideas on this and it doesn't seem to work, Ruby has very limited reach into SU tool/menu system so you can only really add things and not change them once that is done.
You could do a little cheat by making two identical toolbars then hide the first and show the second, and vice versa.
But again Ruby has no control over how the toolbars are positioned so it may end up being a silly jumping button. -
If you create your toolbar within the tools module/class and then refer to the definition of the command as class variable - e.g.
@@cmdA=UI::Command.new("MyToolA"){Sketchup.active_model.select_tool(MyModule.MyToolA.new())} @@cmdA.small_icon=File.join(File.dirname(__FILE__),"MyImages","myToolA_Green.png")
etc... then as circumstances change the image file that's used...
@@cmdA.small_icon=File.join(File.dirname(__FILE__),"MyImages","myToolA_Red.png")
etc...
You can therefore have your various tool-commands permanently referenced as @@cmdA, @@cmdB etc and swap their icons, tooltips and so on, as circumstances change...
-
Thanks TIG, but I already tried that way and it didn't work after the command was added to the toolbar, u can refer to the Mr.K post above.
-
@anton_s said:
Thanks TIG, but I already tried that way and it didn't work after the command was added to the toolbar, u can refer to the Mr.K post above.
It will change ToolTips etc so perhaps if you hide/show the toolbar ?
-
Ya I tried this several ways, text does change but the icons never do(hide, show, remove toolbar and add it again nothing changes).
It seems SU only loads those images once and they can't be refresh through Ruby. -
Yup. Seems that only the tooltip in the Command objects are actually linked to the toolbar objects it represent. The rest seem to be forgotten.
-
Bum!
The best you could do then for something like a 'Play' > 'Stop' button is to have two buttons side by side, with one disabled [grayed-out] if the other one is enabled - using a validation_proc... -
@tig said:
Bum!
The best you could do then for something like a 'Play' > 'Stop' button is to have two buttons side by side, with one disabled [grayed-out] if the other one is enabled - using a validation_proc...Or for Play/Stop, just make the Play button pressed or not pressed - using
MF_CHECKED
andMF_UNCHECKED
. -
@thomthom said:
@tig said:
Bum!
The best you could do then for something like a 'Play' > 'Stop' button is to have two buttons side by side, with one disabled [grayed-out] if the other one is enabled - using a validation_proc...Or for Play/Stop, just make the Play button pressed or not pressed - using
MF_CHECKED
andMF_UNCHECKED
.Yeah Thanks!...
This would not be a bad idea.
I think changing toolbar icons should be part of SU 9 wishes. -
I've found this rather old topic, and have a question is it possible now to change toolbar icons.
I would like to change tool icon when some variable (@@active_extension) is changed.
[ruby]@@activateCmd.set_validation_proc(){ puts "Active #{@@active_extension}" puts "before #{@@activateCmd.small_icon}" if @@active_extension == 'ext1' @@activateCmd.small_icon = File.join(icons_dir,"ext1_16.png") @@activateCmd.large_icon = File.join(icons_dir,"ext1_24.png") elseif @@active_extension == 'ext2' @@activateCmd.small_icon = File.join(icons_dir,"ext2_16.png") @@activateCmd.large_icon = File.join(icons_dir,"ext2_24.png") end puts "after #{@@activateCmd.small_icon}" MF_ENABLED }[/ruby]
This part of code validates command and prints correct icon path (which is changed in accordance with @@active_extension variable), but tool image in toolbar is not updated.
I've also tried to put this change not in set_validation_proc(), but in code after variable is changed. Again correct values are printed, but image remains the same.
Thanks in advance,
Marija -
Hi Marija, I just tested changing icons on SU2016, on Windows OS, and it still doesn't work.
-
Thanks Anton,
I was thinking, that I'm doing something wrong, but it seems that this behaviour is not changed yet.
Advertisement