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

    Automatically load a component.

    Scheduled Pinned Locked Moved Developers' Forum
    70 Posts 5 Posters 5.6k 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

      Component Option

      result = Sketchup.send_action 50168

      Component Attribute

      result = Sketchup.send_action 50170

      Do not ask me how I found the ID, because you will not believe me. 💚


      Edit : I just noticed that the ID of the toolbar "Dynamic Component" is random and changes each computer.

      I must again begin my research. 😢

      [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
      • TNTDAVIDT Offline
        TNTDAVID
        last edited by

        To turn the tool "Interact with the Dynamic Component", it is very easy:

        result = Sketchup.send_action 50167

        As against the "Component Options" is much more difficult!

        Someone has a solution? 😲

        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
        • TNTDAVIDT Offline
          TNTDAVID
          last edited by

          @tig said:

          Please don't capitalize code inappropriately, it can break it.

          Sorry, this is due to my translator and my lack of attention!
          I edited several of my messages to correct these silly mistakes.

          @tig said:

          Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers))

          Wooow gorgeous, this code it works great!

          How did you find this solution?

          I have some beginner questions:

          1 - How to activate several actions if a condition is met?

          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
          

          Two "puts", it does not work!
          Is there a way to acomplire both A shares, if the layer is visible or both B shares, otherwise?

          2 - How to check if a tool is selected?

          For example :

          Sketchup.active_model.select_tool (DCInteractTool.new ($ dc_observers))

          3 - How to check if an " Existing " layer is visible?

          For example:

          The layer, "Click-Window 3D".

          In advance, thank you for your answers.

          [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 Online
            TIG Moderator
            last edited by

            1. I messed on until I found some DC related code that worked - it was NOT simple...
            2. Try this alternative...
             puts vis = new_layer.visible?
            if vis # 'true' = visible so we switch it off...
              new_layer.visible = false # action 1A
              puts Sketchup.send_action("selectSelectionTool;") # action 2A
            elsif # 'false' = not visible so we switch it on...
             new_layer.visible = true # action 1B
             puts Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B
            end
            

            It should return true OR false, then toggle the layer's visibility on/off, and exit to the select-tool or interact-tool as appropriate.
            2. You could get the active_tool... BUT if it's Ruby based, just that - not it's name...
            3. layer = Sketchup.active_model.layers.add("Click-Window 3D") sets layer to be the layer of that given name, and it makes it IF it doesn't already exist.
            Then use
            vis = layer.visible?
            which as we have seen in 1. above vis returns true or false...

            TIG

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

              @tig said:

              puts vis = new_layer.visible?
              if vis # 'true' = visible so we switch it off...
                new_layer.visible = false # action 1A
                puts Sketchup.send_action("selectSelectionTool:") # action 2A
              elsif # 'false' = not visible so we switch it on...
               new_layer.visible = true # action 1B
               puts Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers)) # action 2B
              end

              TIG thank you, your code works very well! 👍

              Out of curiosity, I tested variants to see if I could simplify your example.

              I finally found it:

              
                 if new_layer.visible?
                    new_layer.visible = false 
                    Sketchup.send_action("selectSelectionTool;")
                    elsif
                    new_layer.visible = true 
                    Sketchup.active_model.select_tool(DCInteractTool.new($dc_observers))
                    end
              

              The error in my first example is:

              puts new_layer.visible = false

              You just had to remove the "puts", which does not work with "=".

              Through your example, I found my main mistake. 😉

              1.For another tool, such as "Move", how to tell if it is selected?

              2.Even if the existing layer is, we are forced to use the "layers.add" method, to know whether the layer is visible?

              3.If the layer exists, layers.add replaces the layer or it is ignored?


              Come on we will move to supperior level. 😄

              In the sample code below, we will add 2 attributes to a component box.

              The first defined a color for the "Material" attribute.

              The second adds a fonctione "REDRAW" to attribute "Onclick".

              Here is the example GIF:

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

              Here's the code:

              UI.menu("Plugins").add_item('MyBox Red') {
              	  
                    sang = Sketchup.active_model
                    sang_definition = sang.definitions
                    sang_def = sang_definition['box']
              	  
                    sang_def.set_attribute 'dynamic_attributes','material', 'red' 
                    sang_def.set_attribute 'dynamic_attributes','_material_formula', '"red"'
              
                    sang_def.set_attribute 'dynamic_attributes','onclick', 'REDRAW()'
                    sang_def.set_attribute 'dynamic_attributes','_onclick_formula', '"REDRAW()"'
              	  
                    dcs = $dc_observers.get_latest_class
                    dcs.redraw_with_undo(sang_def) 
                    }
              

              The "REDRAW" in OnClick, is the best way I've found to redraw the attributes of my component.

              To redraw a dynamic component in ruby, I found this code written by DanRathbun in this forum:

              def recalc_dc(inst)
              return nil unless defined?(DCObservers)
              if inst.is_a?(Sketchup;;ComponentInstance) &&
              inst.attribute_dictionary('dynamic_attributes')
              if @dc_observers.nil?
              ObjectSpace.each_object(DCObservers) {|o| break @dc_observers = o }
              end
              return nil unless @dc_observers.respond_to?(;get_latest_class)
              latest_dc_class = @dc_observers.get_latest_class
              return nil unless latest_dc_class.respond_to?(;redraw_with_undo)
              latest_dc_class.redraw_with_undo(inst)
              end
              nil # (there is no particular return value)
              end
              

              4.How to use the code of DanRathbunwith my example?

              5. How to integrate my code in a method?

              I tried this:

              def Mybox
                    sang = Sketchup.active_model
                    sang_definition = sang.definitions
                    sang_def = sang_definition['box']
              	  
                    sang_def.set_attribute 'dynamic_attributes','material', 'red' 
                    sang_def.set_attribute 'dynamic_attributes','_material_formula', '"red"'
              
                    sang_def.set_attribute 'dynamic_attributes','onclick', 'REDRAW()'
                    sang_def.set_attribute 'dynamic_attributes','_onclick_formula', '"REDRAW()"'
              	  
                    dcs = $dc_observers.get_latest_class
                    dcs.redraw_with_undo(sang_def)
                    end	
              

              But it does not work!

              Thank you in advance for your help.

              PS: We are on a completely different subject, is it a good idea to open a new topic?

              [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 Online
                TIG Moderator
                last edited by

                1. The active_tool etc should spot 'Move', but why do you need to find it ?

                2. You do not need to use the layer = layers.add("layer_name") method, BUT it is a simple way to either add a new layer by that name, and get a reference to it, OR, if it already exists then it returns a reference to that existing layer...

                3. See 2. above - that does NOT 'replace' the layer, it simply returns a reference to that layer by name - either if it's newly made, or it's preexisting...

                TIG

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

                  @tig said:

                  1. Le active_tool etc devrait repérer 'Move', mais pourquoi avez - vous besoin de le trouver?

                  For my general culture ruby script. 💚

                  I have the same question but an icon from my toolbar:

                  I need to check or uncheck a icon!

                  1. If the icon in "command18" and is checked, the icon "command17" is automatically unchecked.

                  We see the example in the SketchUp toolbar "styles".

                  2. I want to check the icon of the "command1" with the first click, then uncheck the 2nd click. And so on ...

                  Here is my code:

                        command17 = UI;;Command.new("Opens Settings Panel"){ CW_Pro_mm.panel }
                  
                        command17.small_icon = File.join(@@path_to_resources,"add_17.png")
                  
                        command17.large_icon = File.join(@@path_to_resources,"add_17.png")
                  
                        command17.tooltip = %Q(Opens Settings Panel)
                  
                        command17.status_bar_text = %Q(Opens Settings Panel)
                  
                        command17.menu_text = %Q(Opens Settings Panel)
                  	  
                        command17.set_validation_proc {
                  	  
                        if Sketchup.active_model # ..... ???
                        MF_ENABLED
                        else
                        MF_CHECKED
                        end
                       }
                  

                  Thank you 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
                  • TNTDAVIDT Offline
                    TNTDAVID
                    last edited by

                    I'm looking everywhere, I can not find a solution.

                    Like my icons have no name, should I use the method in my code?

                    By exeple:

                    if Sketchup.active_model.selection.panel?

                    Reminder, I wish to know the code to verify if my icon " command17 " which call the " panel " method, is "on" or "off"?

                    It is certainly not difficult, but I find the answer anywhere. 😲

                    I need your helps.

                    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 Online
                      TIG Moderator
                      last edited by

                      You are muddling up functions and methods again.
                      The ' selection' has no method .panel?

                      I don't quite understand your terminology or what it is you hope to achieve.

                      If you have a toolbar with let's say two buttons and you want only one to be enabled at a time...
                      You have already found the set_validation_proc method...
                      http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_proc
                      In the example in the API usage it checks:
                      if Sketchup.active_model.selection.length == 0
                      i.e. that nothing is selected.
                      If so, then it disables that command, otherwise it is enabled...
                      This works in menus and toolbars alike...

                      To make a working example of this make your two commands and add set_validation_proc code to each command, make the test a simple one like if something is selected in the model [as in the API example] but reverse the logic in the second command...
                      there are several ways to do that...
                      The if becomes unless or if ! or if not, OR change the test from == 0 to != 0

                      This way your menu/toolbar buttons are enabled/disabled depending on a selection...
                      You can of course make lots of different tests, what is it you need ??

                      TIG

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

                        I do not want to enable or disable a button, depending on a selection in the model.

                        I want to enable or disable a button, depending on the selection of another button.

                        Example Image:

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

                        [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 Online
                          TIG Moderator
                          last edited by

                          You have started another thread and I've replied there.
                          I know you do not want to trigger it depending on a selection - I just used that as an example...
                          In the example you show the other buttons are not disabled.
                          When one is active it's shown 'depressed', when another is click that takes the focus and appears depressed.
                          It the other buttons were actually 'disabled', then they would not be clickable and you'd never get out of the first clicked button's state !

                          TIG

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

                          Advertisement