[Question] Icon pressed
-
i scared you, eh?
-
wow Matt - i thought all i had to do was to check that the 'send.action' had worked: select the arc tool > check that it is active > return value (piece of cake)
i didn't imagine i was stepping into such quicksands - no wonder even a genius like me couldn't figure it out.
Thanks!!!
-
Here is a small code to retrieve all Tool IDs...
Enter "retrieve_ToolID" in the ruby console, and click on each icon you want to retrieve. The id will be returned in the console
-
well Matt, it works great - i will try to implement the other icons and see where i get.
if the global variable conflicts with others i shall find out! (and cry for help! )
-
Hi CadFather !
Sorry, but your demand is quite difficult@unknownuser said:
i have looked at validation_proc but i cannot seem to implement it.. am i looking in the right place?
Yes, but also a tool observer.
I found one solution, but I use a global variable... I've asked ruby masters how to not use it, I wait for the answer...For the moment, here is the test I've made.
The Observer Code :class ToolsObsTest < Sketchup;;ToolsObserver def onActiveToolChanged (tools_object, toolname, toolid) $id_of_the_changed_tool = toolid #Global variable that record ID of the new tool activated end end
The code that give you the action of the icon, and its validation
module Matt_Test #Code that been used for all your icons def self.t1(action) # Action = Name of the action to send to Sketchup model = Sketchup.active_model model.tools.add_observer(ToolsObsTest.new) # Activate the Tool observer Sketchup.send_action(action) # Send the action you need end # Code for the validation of the icon. def self.obs(id) # ID = Id of your Icon action if $id_of_the_changed_tool && id == $id_of_the_changed_tool #if ID of the tool activated = ID of your icon return MF_CHECKED else return MF_UNCHECKED end end end
Loading icon and the tool associated
if not file_loaded?("observerTest.rb") plugins = Sketchup.find_support_file("Plugins") tb = UI;;Toolbar.new("Observer Test") cmd = UI;;Command.new("TestCircle") { Matt_Test.t1( "selectCircleTool;" ) } # Here, the icon action is "Circle". cmd.small_icon = cmd.large_icon = File.join(plugins,"f2f_cursor.gif") # Put another icon name if you want to try ;) cmd.tooltip = cmd.status_bar_text = "Test -> T1 ; Circle & ObserverTest" cmd.set_validation_proc { Matt_Test.obs 21096 } # 21096 = Circle. tb.add_item cmd end file_loaded("observerTest.rb")
Don't hesitate to tell me if you need help for all your icons.
EDIT1 : Code updated. No global variables in the code
you have to use this script like a function. Please see below how to use it.
-
Hi cadFather !
I've updated the script in the attachment post.Don't modify this file, please! And don't add anything after. Just place the icon_observer script in the plugins folder.
Create a new file to put your icons code. To call the icon_observer, you have to put this line at the beginning of your icon script :
require 'icon_observer.rb'
Now use codes below to use this script :
Icon_Observer.go ( Name of the action )cmd = UI;;Command.new("Circle") { Icon_Observer.go( "selectCircleTool;" ) } # Here, the icon action is "Circle".
Icon_Observer.obs ( ID of the tool )
cmd.set_validation_proc { Icon_Observer.obs 21096 } # 21096 = ID of the Circle Tool.
Enjoy !
-
Thanks Matt!!!!!!!!!!!!!!
will report back..
-
Matt, is it possible to use the id in the first part? -
for example:
cmd = UI::Command.new("Circle") { Icon_Observer.go( 21096 ) }
when i tried it didn't work..SUPER EDIT: sorry Matt..it DOES work!!
-
Hi Matt
i'm getting a console error of "retrieve_ToolID" in version 7 -
Error; #<NameError; (eval);145; undefined local variable or method `retrieve_ToolID' for main;Object> (eval);145
is it fixable? (if/when you have a bit of time)
basically i'm trying to find the id for the new DC icons
-
Hi CadFather !
Perhaps the case of the text... I don't have Su 7, so can you try this :retrieve_ToolId
Your 'D' is 'd' in the code...
-
, , , ,
THANKS!
only one tool shows the id - the others are ruby calls in .rbs files i cannot access..
-
THX! -
inject that into your code..at "icon_observer.rb"
# Code for the validation of the icon. def self.obs(id) # ID = Id of your Icon action
>> p "This is SU Bug.."
and watch them scroll all the way eternity....
-
@gultekinmg said:
inject that into your code..at "icon_observer.rb"
Code for the validation of the icon.
def self.obs(id) # ID = Id of your Icon action
>> p "This is SU Bug.."and watch them scroll all the way eternity....
NO do NOT do this !
-
ONLY determine if the return value of the validation proc is
MF_CHECKED
,MF_GRAYED
orMF_ENABLED
. -
Keep conditional evaluations (and any other,) at the bare minimum.
ALL visible toolbar validation procs are called by the Sketchup application's main loop, each time the user interface needs to be redrawn (including each time the mouse is moved !!) Menu validation procs are called when a specific menu needs to be displayed.
-
Advertisement