sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Question] Icon pressed

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 5 Posters 966 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CadFatherC Offline
      CadFather
      last edited by

      i have replicated some sketchup icons - i have made a script where i use
      Sketchup.send_action "selectArcTool:"

      the script works but the problem is that the icon does not remain pressed - i have looked at validation_proc but i cannot seem to implement it.. am i looking in the right place?

      can someone write a quick snip for me?

      Thanks
      Max

      1 Reply Last reply Reply Quote 0
      • CadFatherC Offline
        CadFather
        last edited by

        i scared you, eh?

        1 Reply Last reply Reply Quote 0
        • CadFatherC Offline
          CadFather
          last edited by

          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!!! πŸ˜„

          1 Reply Last reply Reply Quote 0
          • M Offline
            Matt666
            last edited by

            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 πŸ˜‰


            retrieve_ToolId.rb

            Frenglish at its best !
            My scripts

            1 Reply Last reply Reply Quote 0
            • CadFatherC Offline
              CadFather
              last edited by

              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! πŸ˜‰ )

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by

                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.


                Just the code.

                Frenglish at its best !
                My scripts

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Matt666
                  last edited by

                  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 ! πŸ˜„

                  Frenglish at its best !
                  My scripts

                  1 Reply Last reply Reply Quote 0
                  • CadFatherC Offline
                    CadFather
                    last edited by

                    Thanks Matt!!!!!!!!!!!!!!

                    will report back.. πŸ˜„

                    1 Reply Last reply Reply Quote 0
                    • CadFatherC Offline
                      CadFather
                      last edited by

                      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!! 😲 πŸ˜„ πŸ‘

                      1 Reply Last reply Reply Quote 0
                      • CadFatherC Offline
                        CadFather
                        last edited by

                        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

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          Matt666
                          last edited by

                          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...
                          πŸ˜‰

                          Frenglish at its best !
                          My scripts

                          1 Reply Last reply Reply Quote 0
                          • CadFatherC Offline
                            CadFather
                            last edited by

                            😲, πŸ˜’, πŸ‘, 😳, πŸ’­

                            THANKS! πŸ˜„

                            only one tool shows the id - the others are ruby calls in .rbs files i cannot access.. 😞

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              googlo
                              last edited by

                              πŸ˜„ πŸ˜„ πŸ˜„
                              THX!

                              1 Reply Last reply Reply Quote 0
                              • G Offline
                                Gultekinmg
                                last edited by

                                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....

                                1 Reply Last reply Reply Quote 0
                                • Dan RathbunD Offline
                                  Dan Rathbun
                                  last edited by

                                  @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 !

                                  1. ONLY determine if the return value of the validation proc is MF_CHECKED, MF_GRAYED or MF_ENABLED.

                                  2. 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.

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement