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

    ICON MF_ENABLED, MF_CHECKED

    Scheduled Pinned Locked Moved Developers' Forum
    37 Posts 5 Posters 3.7k 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.
    • TNTDAVIDT Offline
      TNTDAVID
      last edited by

      A question that comes to mind. 💚

      How an icon can be activated and deactivated with each click.

      Example:

      1st click on iconeA = "MF_CHECKED"
      2nd click on iconeA = "MF_ENABLED"
      3rd click on iconeA = "MF_CHECKED" ....

      I tried this line of code:

      @commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }

      It does not work.

      Do you know the method to be followed?

      Thank you

      [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

      1 Reply Last reply Reply Quote 0
      • K Offline
        kaas
        last edited by

        No surprise it doesn't work - you are making up code that doesn't exist in the API. http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_proc

        Just make a @variable to store the current state (0/1/2) and after clicking on an icon read the variable, use the proper MF_... and set the @variable to another value.

        Off-topic; coming from someone who is selling a SketchUp plugin for E99,- I find your questions and knowledge of Ruby rather 'strange'...

        1 Reply Last reply Reply Quote 0
        • TNTDAVIDT Offline
          TNTDAVID
          last edited by

          I discovered the ruby ...

          My plugins are tools that work only with Dynamic Components.

          Many underestimate the power of dynamic components, which offer unlimited possibilitys.

          Example:

          Click-Change or Click-Kitchen, totaling 100,000 downloads, and more than a Million views in the entropot extensions.

          And 100% of my clients are satisfied.

          I am currently working on an updated Click-Window 3D, which will bring a lot of positive change.

          If I cling to the ruby, it's in the one and only goal, to offer even more to my customers.

          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            With your code
            @commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }
            It should set the @commandA menu item to be checked and enabled.
            It probably won't 'check' the toolbar button - which should be enabled or disabled/grayed ?
            BUT before you do that have you added
            puts @commandA in a line immediately before.
            When you run the command from its button, then it is shows up in the Ruby Console as a reference to a command if it's working right, but if it's nil it's somehow coded wrongly...

            TIG

            1 Reply Last reply Reply Quote 0
            • TNTDAVIDT Offline
              TNTDAVID
              last edited by

              Good evening,

              Icon 1, use the following method:

              def self.panel
                    model = Sketchup.active_model 
                    layers = model.layers 
                    new_layer = layers.add "Click-Window 3D"
                    if new_layer.visible?
                    new_layer.visible = false 
                    else
                    new_layer.visible = true 
                    end
                    end
              

              Icon 2, uses this method:

              def self.layerhid
                    model = Sketchup.active_model 
                    layers = model.layers
                    new_layer = layers.add "Click-Window 3D"
                    new_layer.visible = false
                    instance.layer = new_layer
                    end
              

              When I use the two icons, the visibility of the layer starts to bugger.

              Even if the code activates or deactivates the layer in the Layers window, the composents with this layer do not change state.

              Do you know why this strange bug?

              If so, how to avoid it?

              Thank you in advance for your help.

              David

              [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

              1 Reply Last reply Reply Quote 0
              • K Offline
                kaas
                last edited by

                If you added some puts to your code, you could get some more info on what your code is doing and where/why your code fails.

                In short:
                your first block (self.panel) is just toggling the visibility of new_layer
                your second block (self.layerhid) is always hiding the visibility of new_layer

                instance has not been defined in that second block so if you try to change its layer using instance.layer= it will fail. It probably has to be @my_instance that you have defined elsewhere. There probably was an error message about that in the Ruby Console that you forgot to read/post...

                
                def self.panel
                	model = Sketchup.active_model
                	layers = model.layers
                	new_layer = layers.add "Click-Window 3D" 
                	if new_layer.visible?
                		new_layer.visible = false
                		puts %(self.panel is setting visibility to false)
                	else
                		new_layer.visible = true
                		puts %(self.panel is setting visibility to true)
                	end
                end
                
                def self.layerhid
                	model = Sketchup.active_model
                	layers = model.layers
                	new_layer = layers.add "Click-Window 3D"
                	new_layer.visible = false
                	puts %(self.layerhid is setting visibility to false)
                	instance.layer = new_layer
                	puts instance.layer
                end
                
                1 Reply Last reply Reply Quote 0
                • TNTDAVIDT Offline
                  TNTDAVID
                  last edited by

                  @tig said:

                  With your code
                  @commandA.set_validation_proc{ MF_CHECKED; MF_ENABLED }
                  It should set the @commandA menu item to be checked and enabled.

                  Thank you for that clarification, TIG.

                  @kaas said:

                  instance has not been defined in that second block so if you try to change its layer using instance.layer= it will fail. It probably has to be @my_instance that you have defined elsewhere. There probably was an error message about that in the Ruby Console that you forgot to read/post...

                  Oops! I made a mistake in my copy / pasted, instance.layer should not exist in "Method layerhid".

                  As I noticed the error in the ruby ​​console, and there to any subject in the API on "instance.layer", I ended up deleting it.

                  Regarding "Puts", I added them more, because it can prevent in some cases, a method of work.

                  Example:

                  if new_layer.visible?
                       puts new_layer.visible = false # action 1A
                       puts Sketchup.send_action "selectSelectionTool;" # action 2A
                       elsif
                       puts new_layer.visible = true # action 1B
                       puts Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B
                       end
                  

                  This does not work!

                  If I remove the puts as:

                  if new_layer.visible?
                       new_layer.visible = false # action 1A
                       Sketchup.send_action "selectSelectionTool;" # action 2A
                       elsif
                       pnew_layer.visible = true # action 1B
                       Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B
                       end
                  

                  The code works!

                  With or without "Puts", the console displays the line number or there is an error.

                  So what are the avanatges of "Puts"?

                  @kaas said:

                  def self.panel
                      model = Sketchup.active_model
                      layers = model.layers
                      new_layer = layers.add "Click-Window 3D"
                     if new_layer.visible?
                        new_layer.visible = false
                        puts %(self.panel is setting visibility to false)
                     else
                        new_layer.visible = true
                        puts %(self.panel is setting visibility to true)
                     end
                  end

                  def self.layerhid
                      model = Sketchup.active_model
                      layers = model.layers
                      new_layer = layers.add "Click-Window 3D"
                      new_layer.visible = false
                      puts %(self.layerhid is setting visibility to false)
                      instance.layer = new_layer
                      puts instance.layer
                  end

                  Thank you for your example code.

                  Unfortunately the problem still exists.

                  Here is the error message:

                  @unknownuser said:

                  self.layerhid is setting visibility to false
                  Error: #<NoMethodError: undefined method transform!' for #<Sketchup::ComponentDefinition:0x0000000e47fb40>> c:/users/david/appdata/roaming/sketchup/sketchup 2015/sketchup/plugins/su_dynamiccomponents/ruby/dcclass_v1.rbs:454:in redraw'
                  c:/users/david/appdata/roaming/sketchup/sketchup 2015/sketchup/plugins/su_dynamiccomponents/ruby/dcclass_v1.rbs:406:in redraw_with_undo' C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Pro_mm/logic.rb:217:in mode1'
                  C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Pro_mm/logic.rb:252:in block in <module:CW_Pro_mm>' SketchUp:1:in call'

                  Here are the relevant lines:

                  L217 - $dc_observers.get_latest_class.redraw_with_undo(model_def) # mode 1

                  L252 - @commandA = UI::Command.new("Mode 1"){ CW_Pro_mm.mode1 }

                  L406 - command12.tooltip = %Q(add Crank Window)

                  L454 - @commandO.small_icon = File.join(@@path_to_resources,"add_O.png")

                  I'm surprised these lines triggers an error message!

                  They exist in other methods or command, with these objects that works.

                  It is therefore difficult to understand the reasons of the error message. 😮

                  Thank you

                  David

                  [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    I think the changing of button states on the fly is an issue.
                    So try this alternative:

                    module TesteCube
                    	module ClickWindow
                    		@@path_to_resources = File.join(File.dirname(__FILE__), 'Resources')
                    		if ! file_loaded?(__FILE__)         
                    				su_menu = UI.menu("Plugins")
                    				cc_menu = su_menu.add_submenu(%Q(TesteCube))
                    				tb = UI;;Toolbar.new(%Q(TesteCube))
                    				
                    				@disableA=false
                    				@disableB=false
                    
                    				@commandA = UI;;Command.new("mode1"){ @disableB=true; self.cmdA(); @disableB=false }
                    				@commandA.small_icon = File.join(@@path_to_resources,"add_A.png")
                    				@commandA.large_icon = File.join(@@path_to_resources,"add_A.png")
                    				@commandA.tooltip = %Q(Opens Settings SketchUp)
                    				@commandA.status_bar_text = %Q(Opens Settings SketchUp)
                    				@commandA.menu_text = %Q(Opens Settings SketchUp)
                    				cc_menu.add_item(@commandA)
                    				tb.add_item(@commandA)
                    		 
                    				@commandB = UI;;Command.new("mode1"){ @disableA=true; self.cmdB(); @disableA=false }
                    				@commandB.small_icon = File.join(@@path_to_resources,"add_B.png")
                    				@commandB.large_icon = File.join(@@path_to_resources,"add_B.png")
                    				@commandB.tooltip = %Q(Opens Settings SketchUp)
                    				@commandB.status_bar_text = %Q(Opens Settings SketchUp)
                    				@commandB.menu_text = %Q(Opens Settings SketchUp)
                    				cc_menu.add_item(@commandB)
                    				tb.add_item(@commandB)
                    				
                    				@commandA.set_validation_proc{
                    					if @disableA
                    						MF_DISABLED
                    					else
                    						MF_ENABLED
                    					end
                    				}
                    				@commandB.set_validation_proc{
                    					if @disableB
                    						MF_DISABLED
                    					else
                    						MF_ENABLED
                    					end
                    				}
                    		 
                    				tb.restore
                    				file_loaded(__FILE__)
                    		end
                    
                    		def self.cmdA()
                    			UI.messagebox('cmdA')
                    		end
                    
                    		def self.cmdB()
                    			UI.messagebox('cmdB')
                    		end
                    	end
                    end
                    

                    It sets two possible states for the buttons and sets/resets those each time the commands are run, running the code between those 'bookends'...
                    I've made it a UI.messagebox so you can the affect on the toolbar buttons - otherwise it'll be transitory...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • TNTDAVIDT Offline
                      TNTDAVID
                      last edited by

                      TIG thank you, but the state of the buttons is not the problem!

                      The bontons work fine with my current code.

                      I was wrong on all the line! 😳

                      The problem is this object:

                      $dc_observers.get_latest_class.redraw_with_undo(model_def)

                      It is used in this method:

                            def self.mode1
                            @commandA.set_validation_proc{MF_GRAYED}
                            @commandB.set_validation_proc{MF_ENABLED}
                            @commandP.set_validation_proc{MF_GRAYED}
                            @commandO.set_validation_proc{MF_ENABLED}
                      	  
                            model = Sketchup.active_model  
                            model_definition = model.definitions
                            model_def = model_definition['Control Panel']
                            model_def.set_attribute 'dynamic_attributes','a0000mode', '1'
                            model_def.set_attribute 'dynamic_attributes','_a0000mode_label', 'a0000mode'
                            model_def.set_attribute 'dynamic_attributes','_a0000mode_units', 'STRING'
                            model_def.set_attribute 'dynamic_attributes','_a0000mode_access', 'TEXTBOX'
                            $dc_observers.get_latest_class.redraw_with_undo(model_def)  
                            end
                      

                      This method changes a component attribute that uses the "Click-Window 3D"

                      Once this method is used, the component's display starts messing.

                      Here is my problem:

                      http://i.imgur.com/kYuvpNF.gif

                      Have you an idea of the problem?

                      Thank you

                      [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        Isn't that method used on the currently selected DC instance NOT a definition !?
                        So perhaps it should be something like
                        $dc_observers.get_latest_class.redraw_with_undo(model_def.instances[0])

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • TNTDAVIDT Offline
                          TNTDAVID
                          last edited by

                          @tig said:

                          Isn't that method used on the currently selected DC instance NOT a definition !?
                          So perhaps it should be something like
                          $dc_observers.get_latest_class.redraw_with_undo(model_def.instances[0])

                          It is in this kind of situation that your experience is very beneficial, TIG.

                          Congratulation! 👍

                          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

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

                          Advertisement