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

    Replace Several Textures?

    Scheduled Pinned Locked Moved Developers' Forum
    32 Posts 3 Posters 4.4k Views 3 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.
    • sdmitchS Offline
      sdmitch
      last edited by

      @tntdavid said:

      The plugin is in the right place!

      I think the problem has to be tied to something else.

      Can you share your "rbz" file?

      Your soluition is great and very interesting.

      Thank you

      David

      Hope this helps.


      mats.rbz

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

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

        Thank you very much! 😄

        Moving from one material to another with Click-Kitchen 2, will be much faster and easier with your code. 😉

        I would make a small demo as soon as the code is applied to the plugin.

        Ps: My error was indeed the path to the materials file.

        File.join (File.dirname (__ FILE __). Gsub ('\\', '/'), "TNT_ClickCuisine2 / Materials /"
        

        Corrected like this:

        File.join (File.dirname (__ FILE __). Gsub ('\\', '/'), "Materials /"
        

        [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

          NEVER include a <space> between a method and its parenthesized arguments !
          AND you show some weird Capitalization and added spaces !

          So it IS NOT:
          File.join (File.dirname (__ FILE __). Gsub ('\\', '/'), "Materials /"
          BUT:
          File.join( File.dirname(__FILE__).gsub('\\', '/'), "Materials/" )

          In fact it'd be better as:
          File.join( File.dirname(__FILE__).tr("\\", "/"), "Materials" )

          Then the path can be joined to the files without the trailing '/' ??
          Suitable for all OSs.

          BUT the exactly correct way would be:
          File.expand_path( File.join(File.dirname(__FILE__), "Materials") )

          Which always uses / rather than \ ...

          TIG

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

            **OK TIG 😉

            How to do the same for components?

            Example:

            I have 3 boxes, "1-Box", "2-Box", "3-Box", they are in the folder "Plugins/ Click-Cuisine2/Components".

            I want to create an icon that calls a method of this type:

            1st Click

            Selects all components with the definition "1-Box ##", and replaces with "2-Box", which is in the "Components" folder.

            If no component with the definition " 1-Box" was found, send the message, "Import a Clik-Cuisine 2 furniture, to replace these components ".

            2nd Click

            Selects all components with the definition "2-Box ##", and replaces it with "3-Box".

            3rd Click

            Selects all components with the definition "3-Box ##", and replaces with "1-Box".

            Final objective:

            Click-Cuisine 2, will offer more than 20 IKEA handles that I want to interchange with one click.

            This can be done in Dynamic Components, but it is not suitable for such a large number of 3D models.

            If you can help me write this method, I would be very glad. ☀**

            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

              Clicks 1/2/3:
              Find all component instances matching a certain name.
              If none then messagebox, but if some are collected, then check if the particular replacement component definition exists and use that, otherwise load it from your SKP subfolder... swap the collected instances' definitions for the desired one...
              Here is an outline - assuming your clicks are suitably trapped in a Tool, or are buttons on a webdialog etc...
              Currently this is for filtered selected objects only:

              
              path_to_SKP_folder = "????????"
              # you must set this from knowing your File.dirname(__FILE__)
              # which can be joined with the SKP subfolder's name etc
              model = Sketchup.active_model
              defns = model.definitions
              ss = model.selection
              name = "Box-1" # we'll match the start of the names only /^.../
              instances = ss.grep(Sketchup;;ComponentInstance).find_all{|e| e.definition.name =~ /^#{name}/ }
              unless instances[0]
                UI.messagebox("#{name} NOT matched !")
                return
              else
                rname = name.next # e.g. Box-2
                unless defn = defns[rname]
                  defn = defns.load(File.join(path_to_SKP_folder, rname+".skp")) # you set up SKP path earlier !
                end
                instances.each{|e| e.definition = defn }
              end
              
              

              If you want to do it globally, then you need to grep model.entities and then all defns' entities in turn - filtering out .image? - to process only groups and component contexts...

              TIG

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                @tntdavid said:

                **OK TIG 😉

                How to do the same for components?

                Example:

                I have 3 boxes, "1-Box", "2-Box", "3-Box", they are in the folder "Plugins/ Click-Cuisine2/Components".

                I want to create an icon that calls a method of this type:

                1st Click

                Selects all components with the definition "1-Box ##", and replaces with "2-Box", which is in the "Components" folder.

                If no component with the definition " 1-Box" was found, send the message, "Import a Clik-Cuisine 2 furniture, to replace these components ".

                2nd Click

                Selects all components with the definition "2-Box ##", and replaces it with "3-Box".

                3rd Click

                Selects all components with the definition "3-Box ##", and replaces with "1-Box".

                Final objective:

                Click-Cuisine 2, will offer more than 20 IKEA handles that I want to interchange with one click.

                This can be done in Dynamic Components, but it is not suitable for such a large number of 3D models.

                If you can help me write this method, I would be very glad. ☀**

                thank you

                David

                This seems to work for me.

                      @mod = Sketchup.active_model
                      @ent = @mod.active_entities
                      @last ||= '1'; @next = @last.next; @next='1' if @next=='4'
                      last_name = @last + '-Box'; next_name = @next + '-Box'
                      cmp_folder = File.join(File.dirname(__FILE__).gsub('\\','/'),"TNT_ClickCuisine2/Components/")
                      cis = @ent.grep(Sketchup;;ComponentInstance).find_all{|ci|ci.definition.name[0..4]==last_name}
                      unless cis.empty?
                        for ci in cis
                          cd = @mod.definitions[next_name]
                          unless cd
                            cmp = cmp_folder+"#{next_name}.skp"
                            cd = @mod.definitions.load cmp
                          end
                          ci.definition = cd
                        end
                        @last = @next
                      else
                        UI.messagebox "#{last_name} not found."
                      end
                
                

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

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

                  **Great! Your two examples work perfectly. ☀

                  TIG with the method, I must manually select "Box-1", so that "Box-2", replaces it.

                  How to automatically select all the "Box-1" components, even those that are nested in a piece of furniture?

                  And How to switch from "Box-2" to "Box-3"?

                  Sdmitch your code is very surprising! 👍

                  All "1-Box", "2-Box" and "3-Box" components are selected and replaced automatically.

                  This works for all components at the first level of the structures list.

                  For "Boxes" that are inside a group or components, this does not work anymore.

                  How to solve the problem ?

                  Sorry, I forgot to specify this detail. 💚

                  The objectives are more and more precise:

                  1 - The user clicks on the icon "Change the Handles", to replace all the handles present in all the furniture. ( We are almost there. )

                  2 - If the user no longer wishes to modify some handles, he must select the furniture that he no longer wishes to modify then click on the icon "Freezing the Handles".
                  ( This action must rename the definition of all the handles present inside the selected furniture. )

                  Rename Definitions = Prevent the first code from acting on the handles.

                  How do you write this method?

                  Great thanks to both of you for your help.

                  See 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

                    If you want to do it globally, then you need to grep model.entities and then all defns' entities in turn - filtering out .image? - to process only groups and component contexts...

                    
                    instances = model.entities.grep(Sketchup;;ComponentInstance).find_all{|e|
                      e.definition.name =~ /^#{name}/
                    }
                    model.definitions.each{|d|
                      next if d.image?
                      next unless d.name =~ /^#{name}/
                      d.instances.each{|e| instances << e }
                    }
                    
                    

                    Now you have an array 'instances' that match that name pattern.

                    To process different names have your method take an argument - e.g.

                    
                    def swapper(name=nil)
                      return unless name
                      ### 'name' is set when calling the method
                      ### main code here
                    end
                    
                    

                    You then run the method as swapper("Box-1") or swapper("Box-2") etc...
                    Provided that you always swap by incrementing the name it works as the name.next turns "Box-1" into "Box-2" for the replacement etc...

                    To process just a selected instance's definition you use a context-menu that tests for ss.length==1 && ss[0].is_a?(Sketchup::ComponentInstance) ...
                    Then it runs some 'freezer' method code...

                    
                    name = "some_name_???" ### how is this to be set ?
                    defn = ss[0].definition ### selected instance
                    instances = defn.entities.grep(Sketchup;;ComponentInstance).find_all{|e|
                      e.definition.name =~ /^#{name}/
                    }
                    ds = []
                    instances.each{|e| ds << e.definition }
                    ds.uniq! ### all matching definitions
                    ds.each{|d| d.name = 'x' + d.name }
                    ### or however you will rename each definition...
                    
                    

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • sdmitchS Offline
                      sdmitch
                      last edited by

                      @tntdavid said:

                      **> How to automatically select all the "Box-1" components, even those that are nested in a piece of furniture?
                      David

                      **

                      Following up on TIG's idea of collecting instances, I think this solves the problem of the embedded components.

                            @mod = Sketchup.active_model
                            @ent = @mod.active_entities
                            @last ||= '1'; @next = @last.next; @next = '1' if @next == '4'
                            last_name = "#{@last}-Box"; next_name = "#{@next}-Box"
                            if @mod.definitions[last_name] && @mod.definitions[last_name].instances[0]
                              cd = @mod.definitions[next_name]
                              unless cd
                               cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{next_name}.skp")
                               cd = @mod.definitions.load cmp
                              end
                              @mod.definitions.find{|d|d.name==last_name}.instances.each{|ci|ci.definition=cd}
                              @last = @next
                            else
                              UI.messagebox "#{last_name} not found."
                            end
                      
                      

                      Nothing is worthless, it can always be used as a bad example.

                      http://sdmitch.blogspot.com/

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

                        **I'm sorry to take so much time to answer you but I'm overworked.

                        First tests on the cubes, all seems to work wonderfully.

                        I will test your codes directly on Click-Cuisine 2 and post here an example of the revolutions that it will bring to my tool.

                        I do not know how to thank you because your help allows me to move forward as never before.

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

                          **Hello, ☀

                          After some tests of your codes on Click-Cuisine 2, I noticed a small problem that I hope to solve with your help.

                          The change of component changes perfectly from 1 to 2 then to 3, except if one goes backwards.

                          Here is an example in image:

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

                          Same problem, if I close and I open the file because the script restarts to "1-Component".

                          How to work around the problem?

                          I think it is best to delete the error message, even though "1-Component" is not found.

                          You can download skp example below:

                          TESTE.skp

                          And below the rbz plugin:

                          TNT_Teste.rbz

                          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
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            Without even looking at the code consider this...
                            The 'file's suffix is to change thus:

                            1 >>> 2
                            2 >>> 3
                            3 >>> 1

                            So you don't use 'next' to increment the suffix just a 'case'...
                            In 'pseudo' code...
                            case suffix when '1'; suffix = '2' when '2'; suffix = '3' when '3'; suffix = '1' end#case

                            Attach the suffix the the files' base names as you look through...
                            If you want to remember the last used 'suffix' then use @suffix in a module or @@suffix in a class.
                            Then the next time the tool is used the last used enduring variable is recalled...
                            OR if you are getting the current value from a DC each tim then you can skip the enduring variable route ?

                            TIG

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

                              **Sorry TIG to come back so late, but this time I finally have time to devote myself fully to ruby. ☀

                              I would have to put "@@" into all the variables, but that is certainly not the solution you advise me. 💚

                              Here is the basic code written by Sdmitch, which is almost perfect:

                              def handles
                                    @mod = Sketchup.active_model
                                    @ent = @mod.active_entities  
                                    @last3 ||= '1' 
                                    @next = @last3.next
                                    @next = '1' if @next == '19'  
                                    last3_name = "#{@last3}-HANDLE"
                              	  next_name = "#{@next}-HANDLE"
                                    if @mod.definitions[last3_name] && @mod.definitions[last3_name].instances[0]
                                    cd = @mod.definitions[next_name]
                                    unless cd
                                    cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{next_name}.skp")
                                    cd = @mod.definitions.load cmp
                                    end
                                    @mod.definitions.find{|d|d.name==last3_name}.instances.each{|ci|ci.definition=cd}
                                    @last3 = @next
                                    else
                                    UI.messagebox "#{last3_name} not found."
                                    end
                                 end
                              

                              Before exploring your idea TIG:

                              Can your solution manage multiple SKP files or the status of the handles are different for each file?

                              For example :

                              My Project 1 has been saved with the definition in "9-HANDLE".

                              If I open this file the code must look for the definition "9-HANDLE", to replace it with "10-HANDLE".

                              My Project 2 is saved in "4-HANDLE".

                              If I open this file the code should look for the definition "4-HANDLE", to replace it with "5-HANDLE".

                              Another example:

                              If I go back with Sketchup, the code that is "4-HANDLE" will return to the "3-HANDLE" state.

                              If your idea fulfills all these conditions can you write an example?

                              Another idea would be to replace all the definitions that are called "Handle" in their definitions.

                              For example:

                              "1-Handle", "2-Handle" or "3-Handle" etc ...
                              Are replaced because they contain the name "Handle" in their definitions.

                              Is this easier to apply?

                              If so, how will you change the code?

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

                                **Hello,

                                To replace several definitions with the "next name" definition, I tried this:

                                def handles
                                      @mod = Sketchup.active_model
                                      @ent = @mod.active_entities  
                                      @last3 ||= '1' 
                                      @next = @last3.next
                                      @next = '1' if @next == '4' 
                                 
                                      last3_name = ['1-HANDLE','2-HANDLE','3-HANDLE']
                                      next_name = "#{@next}-HANDLE"
                                
                                      if @mod.definitions[last3_name] && @mod.definitions[last3_name].instances[0]
                                      cd = @mod.definitions[next_name]
                                      unless cd
                                      cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#
                                      {next_name}.skp")
                                      cd = @mod.definitions.load cmp
                                      end
                                      @mod.definitions.find{|d|d.name==last3_name}.instances.each{|ci|ci.definition=cd}
                                      @last3 = @next
                                      else
                                      UI.messagebox "#{last3_name} not found."
                                      end
                                   end
                                

                                But the code does not work for a list of definitions between these brackets "[]".

                                How to replace a list of definitions with the definition "next name" ?

                                Any help would be of great help to me.

                                Cordially

                                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

                                  **There is news ☀

                                  As my code is in a class, I tried to apply the advises of TIG, put in "@@".

                                  Now "@@ next" continues to evolve from 1 to 19, even if the definition that needs to be replaced is not found.

                                  Even if the situation is better than before, it is not perfect because the code restarts to
                                  "1-Handle" every time SketchUp runs.

                                  If the handles on the stage are defined "5-Handle", you have to click 4 times on the icon to change the handle.

                                  Thank you in advance for your help.**

                                  def Handle
                                      @@mod = Sketchup.active_model
                                      @@ent = @@mod.active_entities
                                      @@avant ||= '1'
                                      @@next = @@avant.next
                                      @@next = '1' if @@next == '19'
                                  	  
                                      @@last1 = "#{@@avant}-HANDLE"
                                      @@next_name = "#{@@next}-HANDLE"
                                  	  
                                   if @@mod.definitions[@@last1]
                                      @@cd = @@mod.definitions[@@next_name]	
                                      unless @@cd
                                      cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#
                                      {@@next_name}.skp")
                                      @@cd = @@mod.definitions.load cmp
                                   end
                                      @@mod.definitions.find{|d|d.name==@@last1}.instances.each{|ci|ci.definition=@@cd}
                                      @@avant = @@next
                                   else
                                      UI.messagebox "#{@@last1} not found."
                                   end
                                  end
                                  

                                  [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
                                  • sdmitchS Offline
                                    sdmitch
                                    last edited by

                                    I would suggest using attributes to keep tract of "next".

                                    @@avant = Sketchup.active_model.get_attribute("Handles","Last","1")
                                    @@next = @@avant.next
                                    Sketchup.active_model.set_attribute("Handles","Last",@@next)

                                    Nothing is worthless, it can always be used as a bad example.

                                    http://sdmitch.blogspot.com/

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

                                      **Great Thanks sdmitch.

                                      The general change of all the Handles furniture is finally perfect. 😉

                                      I will do the same for all the components of a kitchen, sink, taps, oven etc ...

                                      Thanks to your help, "Click-Cuisine 2" will be even easier than ever.

                                      A small remark without great consequence:

                                      The current code does not replace the unique handles, such as "1-HANDLE # 1".

                                      Is it possible to circumvent the problem, if so how?

                                      The 2nd Great Steps is to replace the Handles of a single piece of furniture selected, without affecting other furniture.

                                      How would you do that?

                                      Any help from you is very good news to 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
                                      • sdmitchS Offline
                                        sdmitch
                                        last edited by

                                        @tntdavid said:

                                        The current code does not replace the unique handles, such as "1-HANDLE # 1".

                                        Is it possible to circumvent the problem, if so how?

                                        @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
                                        

                                        The 2nd Great Steps is to replace the Handles of a single piece of furniture selected, without affecting other furniture.

                                        How would you do that?
                                        This would be difficult indeed. The easiest way would be to move the single piece to a new model, make the changes then import it back.

                                        David

                                        Nothing is worthless, it can always be used as a bad example.

                                        http://sdmitch.blogspot.com/

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

                                          **Thanks for your Sdmitch solution, but the definitions rendered unique "1-HANDLE # 1" still do not change.

                                          Maybe I made a mistake somewhere?

                                          def poignee
                                              @@mod = Sketchup.active_model
                                              @@ent = @@mod.active_entities
                                              @@avant = Sketchup.active_model.get_attribute("Handles","Last","1")
                                              @@next = @@avant.next
                                              @@next = '1' if @@next == '19'	
                                          	  
                                              @@last1 = "#{@@avant}-POIGNEE"
                                              @@next_name = "#{@@next}-POIGNEE"
                                          	  
                                          if  @@mod.definitions[@@last1]
                                              @@cd = @@mod.definitions[@@next_name]	
                                              unless @@cd
                                              cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#
                                              {@@next_name}.skp")
                                              @@cd = @@mod.definitions.load cmp
                                              end
                                              @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
                                              @@avant = @@next
                                              Sketchup.active_model.set_attribute("Handles","Last",@@next)
                                              else
                                              UI.messagebox "#{@@last1} not found."
                                            end
                                          end
                                          

                                          Perhaps it is more interesting not to reload the rendered unique models to find a solution to my 2nd Objective?

                                          Here is a simpler idea for the 2nd Objective:

                                          1 - I select a piece of furniture.

                                          2 - I Click on the icon "Freeze the model". (The method that is executed makes all unique components and subcomponents of my selection.)

                                          3 - I can execute the first code without changing the handles of the furniture made unique.

                                          How to write this method?

                                          Thanks in advance for your help.**

                                          [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
                                          • sdmitchS Offline
                                            sdmitch
                                            last edited by

                                            @tntdavid said:

                                            [size=110]Thanks for your Sdmitch solution, but the definitions rendered unique "1-HANDLE # 1" still do not change.

                                            Maybe I made a mistake somewhere?

                                            def poignee
                                            >     @@mod = Sketchup.active_model
                                            >     @@ent = @@mod.active_entities
                                            >     @@avant = Sketchup.active_model.get_attribute("Handles","Last","1")
                                            >     @@next = @@avant.next
                                            >     @@next = '1' if @@next == '19'	
                                            > 	  
                                            >     @@last1 = "#{@@avant}-POIGNEE"
                                            >     @@next_name = "#{@@next}-POIGNEE"
                                            > 	  
                                            > if  @@mod.definitions[@@last1]
                                            >     @@cd = @@mod.definitions[@@next_name]	
                                            >     unless @@cd
                                            >     cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#
                                            >     {@@next_name}.skp")
                                            >     @@cd = @@mod.definitions.load cmp
                                            >     end
                                            >     @@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
                                            >     @@avant = @@next
                                            >     Sketchup.active_model.set_attribute("Handles","Last",@@next)
                                            >     else
                                            >     UI.messagebox "#{@@last1} not found."
                                            >   end
                                            > end
                                            

                                            I think you need to use the same @@mod.definitions.find when checking for existence also.

                                            if @@mod.definitions.find{|d|d.name=~/#{@@last1}?/}
                                            	@@cd = @@mod.definitions.find{|d|d.name=~/#{@@next_name}?/}
                                            	unless @@cd
                                            		cmp = File.join(Sketchup.find_support_file('plugins'),"TNT_ClickCuisine2/Components/#{@@next_name}.skp")
                                            		@@cd = @@mod.definitions.load cmp
                                            	end
                                            	@@mod.definitions.find{|cd|cd.name=~/#{@@last1}?/i}.instances.each{|ci|ci.definition=@@cd}
                                            	@@avant = @@next
                                            	Sketchup.active_model.set_attribute("Handles","Last",@@next)
                                            else
                                            	UI.messagebox "#{@@last1} not found."
                                            end
                                            
                                            

                                            Nothing is worthless, it can always be used as a bad example.

                                            http://sdmitch.blogspot.com/

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

                                            Advertisement