• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

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.
  • T Offline
    TIG Moderator
    last edited by 26 Oct 2016, 20:18

    @TNTDAVID

    You have failed to appreciate that you need an instance variable @ to make it become available within a related module's methods [aka def]
    I explained the difference of the variable types at some length, last week...

    If you suddenly "out-of-the-blue" refer to something called command18, then that method will NOT understand what you mean by it.
    BUT if you had set it up earlier, within the module, as @command18=... then it would also be visible within the nested method...

    Also, please stop using confusing terminology !
    sang = Sketchup.active_model
    Why ??
    The sang is component in an old default template.
    Use model= or mod= etc
    Using 'ang' in a name hints that it might be an angle !

    TIG

    1 Reply Last reply Reply Quote 0
    • T Offline
      TNTDAVID
      last edited by 26 Oct 2016, 21:49

      Wow I am very pleased to see the Great Masters of ruby ready to help me. 😍

      I discovered the ruby, so thank you for your extreme indulgence.

      I added the "@", but it's always the same problem.

      Here is the updated code:

      def self.panel #method called by the command17, which must temporarily disable the command 18.
            command18.set_validation_proc{@MF_GRAYED}
            methode00
            panelmove
            $dc_observers.get_latest_class.close_configure_dialog 
            Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers))
            model = Sketchup.active_model 
            layers = model.layers 
            new_layer = layers.add "Click-Window 3D"
            new_layer.visible = true
      
            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)
      	  
            command18.set_validation_proc{@MF_ENABLED}
            end
      
            ###########
      
            command18 = UI;;Command.new("Opens Settings SketchUp"){ CW_Pro_mm.options }
      
            command18.small_icon = File.join(@@path_to_resources,"add_18.png")
      
            command18.large_icon = File.join(@@path_to_resources,"add_18.png")
      
            command18.tooltip = %Q(Opens Settings SketchUp)
      
            command18.status_bar_text = %Q(Opens Settings SketchUp)
      
            command18.menu_text = %Q(Opens Settings SketchUp)
           
            cc_menu.add_item(command18)
      
            tb.add_item(command18)
      
      

      What is my mistake?

      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
      • T Offline
        TIG Moderator
        last edited by 27 Oct 2016, 12:12

        Please indent your coe consistently and helpfully...
        You have NOT added the @ !
        None of your commands have a @ prefix.
        If this is all of your code it's also wrong in other ways.
        The various @ references need a commond 'parent' module, so they can be seen by the methods...
        It all needs to be inside your own module[s].
        The commands are set up as the code loads.
        These should have @ names so that the methods can also access them.
        Here is an outline - I have already given you something like this earlier in the week...
        Do NOT following the exact naming etc just understand how the parts work, and apply them to your own needs...

        module TNTDAVID
          module ClickWindow
            ### set up commands
            @commandA = UI.command.new('CmdA'){self.cmdA()}
            ### add icons, tooltips etc
            @commandB = UI.command.new('CmdB'){self.cmdB()}
            ### add icons, tooltips etc
            ### add it's toolbar
            ### add the buttons to toolbar to run the commands
            ### etc
            ### the methods run by the commands...
            ###
            def self.cmdA() ### the code run by commandA
              ### do stuff here, that can then 'see' the @commandA and @commandB
              ### which are instance variable references to the two commands !
              ### disable @commandB
              ### do some processing...
              ### if the user jumps out of processing before the end ensure that @commandB is re-enabled
              ###
              ### at the end re-enable @commandB
            end#method
            ### you say you want vice vers affects from the two toolbar buttons !
            def self.cmdB() ### the code run by commandB
              ### do stuff here, that can then 'see' the @commandA and @commandB
              ### which are instance variable references to the two commands !
              ### disable @commandA 
              ### do some processing...
              ### if the user jumps out of processing before the end ensure that @commandA is re-enabled
              ###
              ### at the end re-enable @commandA 
            end#method
          end#module
        end#module
        

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          TNTDAVID
          last edited by 27 Oct 2016, 15:44

          @tig said:

          o NOT following the exact naming etc just understand how the parts work, and apply them to your own needs...

          I understand your logic in your example!

          If I miss is the formulation of the code ....

          **module TNTDAVID
          module ClickWindow
          ### set up commands OK
          @commandA = UI.command.new('CmdA'){self.cmdA()}

          ### add icons, tooltips etc %(#FF0000)[OK]
          
          @commandB = UI.command.new('CmdB'){self.cmdB()}
          
          ### add icons, tooltips etc %(#FF0000)[OK]
          
          ### add it's toolbar %(#FF0000)[OK]
          
          ### add the buttons to toolbar to run the commands %(#FF0000)[OK]
          ### etc
          ### the methods run by the commands... %(#FF0000)[OK]
          ###
          
          def self.cmdA() ### the code run by commandA %(#FF0000)[OK]
          
            ### do stuff here, that can then 'see' the @commandA and @commandB %(#FF0000)[OK]
          
            ### which are instance variable references to the two commands ! %(#BF0000)[OK]
          
            ### disable @commandB %(#FF0040)[**1.how?**
          

          @cmdB.set_validation_proc{MF_GRAYED}

          The code does not work, even if I add an "@", between maybe curly braces.]

            ### do some processing... %(#FF0000)[OK]
          
            ### if the user jumps out of processing before the end ensure that @commandB is re-enabled 
          

          2.How should write the code?

            ### at the end re-enable @commandB **%(#FF0000)[3.how?]**
          
          end#method
          
          ### you say you want vice vers affects from the two toolbar buttons !** %(#FF0000)[OK]
          

          I think I expressed myself badly, is you do not have can understand my goals. 😕

          "cmdA" is "GRAYED" by défeaut which is (mode1), even when you start SketchUp.

          It remains "GRAYED" all the TIME! unless the user clicks on the icon "CMDB" to enter in the (mode2).

          Under this condition, the icon "cmdB" becomes "GRAYED" is "cmdA" becomes "ENABLED".

          ---cmdA- cmdB

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

          4.I think your example, does not have the same objectives?

          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
          • T Offline
            TIG Moderator
            last edited by 27 Oct 2016, 16:42

            Reread what you wrote...
            @cmdB
            is a method NOT a command, so try
            @commandB.set_validation_proc{MF_GRAYED}

            In Ruby there is the:
            begin ... #a rescue ... #b ensure ... #c end
            function

            After you disable @commandB then you ought to do all of your remaining processing within the ' begin......end' - starting at #a

            If these is a possibility that the user stops the process part way through, then you need to somehow spot it and then re-enable @commandB - that depends on your own code...

            If it fails with an error - it invokes 'rescue' at #b - so then you also need to re-enable @commandB in that part.

            The safety-net is the 'ensure' at #c - then you also need to re-enable @commandB in that part as well.

            For further confidence I'd also add a re-enable for @commandB after the end of the begin......end - although I think it'll survive without it [obviously I haven't tested any of the is !]

            NB: The re-enable code is:
            @commandB.set_validation_proc{MF_ENABLED}

            TIG

            1 Reply Last reply Reply Quote 0
            • T Offline
              TNTDAVID
              last edited by 27 Oct 2016, 17:48

              TIG, I just write code that conforms to your example:

              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))
              
                  @commandA = UI;;Command.new("mode1"){ ClickWindow.cmdA()}
                  @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"){ ClickWindow.cmdB()}
                  @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)
              	
                  tb.restore
                  file_loaded(__FILE__) 
                  end
              	
                  def self.cmdA() 
                  model = Sketchup.active_model  
                  model_definition = model.definitions
                  model_def = model_definition['Box']
                   
                  model_def.set_attribute 'dynamic_attributes','mode', '1'
                  model_def.set_attribute 'dynamic_attributes','_mode_label', 'mode'
                  model_def.set_attribute 'dynamic_attributes','_mode_units', 'STRING'
                  model_def.set_attribute 'dynamic_attributes','_mode_access', 'TEXTBOX'
              	
                  @commandA.set_validation_proc{MF_GRAYED}
                  @commandB.set_validation_proc{MF_DISABLED}
                  end
              	
                  ### you say you want vice vers affects from the two toolbar buttons ! ?????
              	
                  def self.cmdB() 
                  model = Sketchup.active_model  
                  model_definition = model.definitions
                  model_def = model_definition['Box']
                   
                  model_def.set_attribute 'dynamic_attributes','mode', '2'
                  model_def.set_attribute 'dynamic_attributes','_mode_label', 'mode'
                  model_def.set_attribute 'dynamic_attributes','_mode_units', 'STRING'
                  model_def.set_attribute 'dynamic_attributes','_mode_access', 'TEXTBOX'
              	
                  @commandB.set_validation_proc{MF_GRAYED}
                  @commandA.set_validation_proc{MF_DISABLED}
              	
                  end
              
                end
                 
              end
              

              Error message:

              @unknownuser said:

              Error: #<NameError: undefined local variable or method `commandA' for TesteCube::ClickWindow:Module>

              There is a problem with "@" because without it, there is no error.

              Or are my mistakes?

              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 27 Oct 2016, 18:14

                Just looking at the error: Error: #<NameError: undefined local variable or methodcommandA'`
                My guess would be you forgot to add the @ in these lines. If you don't add it, the commandA is not initialized/set.


                command.jpg

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 27 Oct 2016, 18:40

                  As @kaas succinctly says...

                  Your code is full of typos or un-corrected errors. 😕
                  Please proofread more closely [see below]...

                  Also learn to read the error messages - where the reference or the line is given in the error-message in the Ruby Console...

                  If you have Notepad++ and still can't locate the erroneous line, then you could select a variable's name and use 'find' to 'mark' all matching strings in your code.
                  Any strings with a similar, BUT not exactly-matching, name can be found using a 'find' etc...

                  This is an issue of attention to detail and care, rather than understanding how the code might work...
                  5/10 😮

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TNTDAVID
                    last edited by 27 Oct 2016, 22:35

                    Thanks you kaas for your advices.

                    I added the "@", and there is always the same error message.

                    @tig said:

                    Your code is full of typos or un-corrected errors.

                    Or are errors frape TIG?

                    That surprises me because the code works without any error message if there is no longer the @. 😮

                    To my typos, you refer to your examples:

                    @tig said:

                    @cmdA=UI.command.new('cmdA'){self.cmdA())

                    I had to correct like this:

                    @commandA = UI::Command.new("cmdA"){ ClickWindow.cmdA()}

                    If not, there was a lot of error messages for a single line.

                    Thank you to tell me that I have errors in my code, I would be happier if you show me. 😉

                    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
                    • T Offline
                      TIG Moderator
                      last edited by 27 Oct 2016, 23:39

                      OK, gloves off... 😕

                      You do not seem to be able to understand OR to appreciate good advice...
                      Many of us had offered tips, which you then ignore - often annoyingly !
                      ...

                      In the example code you posted, you use 'commandA' and 'cmdA' with no thought as to what they refer to !!!
                      One is a 'command' and the other is a 'method' resulting from that command...

                      So as it is this will certainly fail.

                      Please learn how to inspect your code, for at least some semblance of order, and correct it...


                      The rest of us have other lives to lead and work to do - please try to help us to help you................

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TNTDAVID
                        last edited by 28 Oct 2016, 00:43

                        @tig said:

                        OK, gloves off...

                        You do not seem to be able to understand OR to appreciate good advice...
                        Many of us had offered tips, which you then ignore - often annoyingly !

                        Of course I'm taking your advice and I'm doing my best to move forward.

                        I voluntarily writing new code, to follow your example, so it is not fair to say things like that. 😮

                        @tig said:

                        In the example code you posted, you use 'commandA' and 'cmdA' with no thought as to what they refer to !!!
                        One is a 'command' and the other is a 'method' resulting from that command...

                        I did the same thing on your example, "cmdA" is a method of command is "commandeA".

                        So I do not understand or you see a problem?

                        Perhaps if you do a simple copy / paste my code with your corrections, it would be much simpler and effective?
                        It's allow myself to understand my mistakes very quickly.

                        [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
                        • T Offline
                          TIG Moderator
                          last edited by 28 Oct 2016, 14:56

                          Sorry I got overwrought. 😳
                          But you can be very frustrating...

                          def self.cmdA() is the method that is run by the command @commandA

                          The reason you make it an instance variable with the @ is that the method should see the reference to the command, without it it will not.

                          As @kaas highlighted in yellow boxes you [correctly] set up @commandA and later on make a reference to commandA which will not work !
                          You also make the same error for @commandB...

                          Please read your code carefully.

                          With Notepad++ if you select the text @commandA all occurrences of it will be colored.
                          You can then 'mark' then, then select commandA [sans @] and all will color - including so that were not marked in the earlier step, because of the missing @...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TNTDAVID
                            last edited by 28 Oct 2016, 16:47

                            TIG no problem. 😉

                            Indeed "Kaas" had identified the problem!

                            As a noodle, I did not understand that the "@" missing, should be in brackets.

                            The solution to the error message is simply this:

                            cc_menu.add_item (@commandA) tb.add_item (@commandA)

                            And it's the same for "commandeB".

                            As this problem is resolved, we can move forward hopefully. 💚

                            TIG, the line of code:

                            @commandA.set_validation_proc{MF_DISABLED}

                            Does not work!

                            If there are orders below this line, they will not be executed.

                            I tried all possible variants, with the "@" among the accolades, but it does not change ...

                            1.Do you knows why?


                            Other subject:

                            The more I discovered the ruby, the more I realize that it is an incredible complexity. 😮

                            If I write this in ruby ​​consol:

                            model = Sketchup.active_model  
                            model_definition = model.definitions
                            model_def = model_definition['box']
                            valeur = model_def.get_attribute 'dynamic_attributes','mode'
                            

                            She references me the value of the "mode" attribute, which exists in the dynamic component, "box".

                            Let's say the result is 1.

                            If I add this logic test:

                            if valeur == 1
                            puts "MODE 1"
                            else
                            puts "MODE2"
                            end
                            

                            He answer each time, "Mode 2".

                            Or am i completely off base of wall, if who is the safest, or the ruby ​​script is not logical. 😮 😮 😮

                            2.Can you tell me, how such a thing is possible?

                            I thank you for your emotional support.

                            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
                            • T Offline
                              TIG Moderator
                              last edited by 28 Oct 2016, 17:23

                              Answering in reverse order...

                              DC values are strings
                              If it exists it might be say "1" rather than 1
                              If it doesn't exist it'd be nil - UNLESS you use a default response...
                              valeur = model_def.get_attribute('dynamic_attributes', 'mode', 'merde')
                              In which case you'd get a meaningful 'bad' result...
                              To see if it's getting read add in...
                              puts @commandA
                              It should show a valid command in the Ruby Console...
                              then try...
                              @commandA.set_validation_proc{ MF_DISABLED }
                              Try other alternatives: MF_ENABLED, MF_DISABLED, MF_CHECKED, MF_UNCHECKED, or MF_GRAYED.
                              ALWAYS test your code running it with the Ruby Console open, so you see the useful error messages...

                              Remember that the commands need to 'negate' their opposite sibling command...
                              Remember that your code needs to disable the opposite command as it starts and then re-enable it on completion of its processing, otherwise it'll remain disabled thereafter !

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • K Offline
                                kaas
                                last edited by 28 Oct 2016, 18:05

                                @TNTDAVID - to investigate problems like this yourself, you just do puts valeur just after valeur = model_def.get_attribute 'dynamic_attributes','mode'
                                At that moment you will see a value, an error, a string etc - when you expected an int etc etc. Next you can try to fix it.

                                If that puts returns a value though as expected you do the same in the next line where some code is executed etc etc. Repeat until you solved the problem.
                                Leaving the ruby console open is essential because errors are displayed there with some hints/line numbers where the code fails.

                                For anyone new in ruby (also for me), this really helps in learning why code fails. Asking here might result in a solution but you will learn not as much compared to trying to debug your code yourself.

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  TNTDAVID
                                  last edited by 28 Oct 2016, 19:06

                                  I do not have the expected result, but at least the code works with the "puts".

                                  @commandB.set_validation_proc{ puts MF_DISABLED }

                                  The ruby console goes crazy, and sending 0 continuously after clicking on an icon ...

                                  Here's the code:

                                  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))
                                  
                                      @commandA = UI;;Command.new("mode1"){ ClickWindow.cmdA()}
                                      @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"){ ClickWindow.cmdB()}
                                      @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)
                                  	
                                      tb.restore
                                  	
                                      file_loaded(__FILE__) 
                                  	
                                      end
                                  	
                                      def self.cmdA() 
                                      @commandB.set_validation_proc{
                                      puts MF_DISABLED
                                      }
                                      model = Sketchup.active_model  
                                      model_definition = model.definitions
                                      model_def = model_definition['Box']
                                       
                                      model_def.set_attribute 'dynamic_attributes','a0000mode', '1'
                                      model_def.set_attribute 'dynamic_attributes','_a0000mode_label', 'mode'
                                      model_def.set_attribute 'dynamic_attributes','_a0000mode_units', 'STRING'
                                      model_def.set_attribute 'dynamic_attributes','_a0000mode_access', 'TEXTBOX'
                                  	
                                      @commandB.set_validation_proc{
                                      puts MF_ENABLED
                                      }
                                      end
                                  	
                                      ### you say you want vice vers affects from the two toolbar buttons ! ?????
                                  	
                                      def self.cmdB() 
                                      @commandA.set_validation_proc{
                                      puts MF_DISABLED
                                      }
                                      model = Sketchup.active_model  
                                      model_definition = model.definitions
                                      model_def = model_definition['Box']
                                       
                                      model_def.set_attribute 'dynamic_attributes','mode', '2'
                                      model_def.set_attribute 'dynamic_attributes','_mode_label', 'mode'
                                      model_def.set_attribute 'dynamic_attributes','_mode_units', 'STRING'
                                      model_def.set_attribute 'dynamic_attributes','_mode_access', 'TEXTBOX'
                                  	
                                      @commandA.set_validation_proc{
                                      puts MF_ENABLED
                                      }
                                      end
                                  
                                    end
                                     
                                  end
                                  

                                  The code inside the methods are properly executed, but the icons state does not change.

                                  What's wrong?

                                  @tig said:

                                  DC values are strings
                                  If it exists it might be say "1" rather than 1

                                  TIG thank you, it works fine now. 👍

                                  The message is passed, "Kaas" I work only with the ruby consol to find my mistakes.

                                  I just noticed that the ruby consol, create the toolbar and the icons. 😛

                                  It lacks the "png", but this is normal.

                                  Big thank you to you both for your advice.

                                  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 28 Oct 2016, 19:51

                                    The 'crazy console' is because you put a puts at a very strange position ?!?

                                    @commandB.set_validation_proc{puts MF_DISABLED}

                                    Why did you put the puts there?? It makes no sense (to me). Think about the difference.

                                    @commandB.set_validation_proc{MF_DISABLED}

                                    1 Reply Last reply Reply Quote 0
                                    • K Offline
                                      kaas
                                      last edited by 28 Oct 2016, 20:34

                                      If I remove the strange puts it still doesn't work and I think the reason is; you mixed up the logic for enabling / disabling the buttons;
                                      if you enable A, you should disable B and vice versa. In your code you first enable A and then disable the same again.

                                      The code below does show switching icons. I used CHECKED instead of ENABLED so its more clear.

                                      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))
                                      
                                      				@commandA = UI;;Command.new("mode1"){ ClickWindow.cmdA()}
                                      				@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"){ ClickWindow.cmdB()}
                                      				@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)
                                      			 
                                      				tb.restore
                                      				file_loaded(__FILE__)
                                      			end
                                      		 
                                      			def self.cmdA()
                                      				#puts'cmdA'
                                      				@commandA.set_validation_proc{MF_CHECKED}
                                      				@commandB.set_validation_proc{MF_DISABLED}
                                      			end
                                      		 
                                      			def self.cmdB()
                                      				#puts'cmdB'
                                      				@commandA.set_validation_proc{MF_DISABLED}
                                      				@commandB.set_validation_proc{MF_CHECKED}
                                      			end
                                        end
                                      end
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        TNTDAVID
                                        last edited by 28 Oct 2016, 23:33

                                        Kaas Congratulations!

                                        A simple test of logic and the code works. 👍

                                        For "puts", I misunderstood fredo:

                                        @fredo6 said:

                                        This is a proc, so it is called by Sketchup and expect a return value to set the state of the icon. It is called almost continuously (you can check that by the statement command18.set_validation_proc { puts "icon proc" ; MF_GRAYED }.

                                        I can resume my labors, and I hold you informed of advancements or problems. 💚

                                        Thank you for your help!

                                        See you soon

                                        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
                                        • T Offline
                                          TNTDAVID
                                          last edited by 29 Oct 2016, 03:42

                                          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
                                          • 1
                                          • 2
                                          • 1 / 2
                                          1 / 2
                                          • First post
                                            17/37
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement