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

    Import 2 components with a single icon.

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 3 Posters 1.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.
    • TNTDAVIDT Offline
      TNTDAVID
      last edited by

      Starting from the base code, I changed the lines of code :

      @@path_to_00 = File.join(path_to_components,'Componant1.skp','Componant2.skp')
      

      I get this message: File not found or invalid

      def add_00
            Sketchup.active_model.import(@@path_to_00)
            Sketchup.active_model.import(@@path_to_01)
          end
      

      Only the model @@Path_to_01 is imported.

      Unfortunately I do not find the solution. 😞

      If someone who masters the code goes through, I would be very grateful to have help.

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

        Unfortunately your code makes little sense.

        Try using a p or puts in front of the reference setting line[s] so you can see what is going on in the Ruby Console...
        ` p path_to_components = File.join(File.dirname(FILE), 'Components')

        "The_user_path_to/Plugins/Your_Extension/Components"
        p @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp')
        "The_user_path_to/Plugins/Your_Extension/Components/00-Control-Panel-Trial-mm.skp"

        p @@path_to_00 = File.join(path_to_components,'Componant1.skp','Componant2.skp')

        "The_user_path_to/Plugins/Your_Extension/Components/Componant1.skp/Componant2.skp"`
        So obviously the file does NOT exist... 😮
        You need to sort out the paths so they are defined properly...

        This is quite basic stuff...
        So I suspect that you are just too close to your code to be able to step back and see the wider picture...

        Using temporary p or puts as you define references to things help you see where your thinking has gone astray...

        TIG

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

          TIG thank you for your help. 😄

          So I changed my code like this:

          module ClickWindow3D_Trial_mm
          
            class << self
            
            
                  p path_to_components = File.join(File.dirname(__FILE__), 'Components')
                  >>> "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components"
                  p @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp')
                  "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Trial-mm.skp"
                  >>>
                  p @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm')
                  >>>
                  "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Trial-mm.skp\02-Sliding-Window-Trial-mm"
          
                  path_to_components = File.join(File.dirname(__FILE__), 'Components')
                  @@path_to_00 = File.join(path_to_components, '00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm.skp')
                  @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') 
          
          
              def add_00
                Sketchup.active_model.import(@@path_to_00)
              end
          
          if !file_loaded?(__FILE__)
          
          
                  tb = UI;;Toolbar.new(%Q(Click-Window3D-Trial-mm))
          
                  command1 = UI;;Command.new("add Resources"){ ClickWindow3D_Trial_mm.add_00 }
                  
                  command1.small_icon = File.join(@@path_to_resources,"add_00.png")
          
                  command1.large_icon = File.join(@@path_to_resources,"add_00.png")
          
                  command1.tooltip = %Q(add Resources)
          
                  command1.status_bar_text = %Q(add Resources)
          
                  tb.add_item(command1)
          
                  tb.restore
          
                  file_loaded(__FILE__)
          
                 end
          
             end
          
          end
          

          Unfortunately I obtien this error message:

          @unknownuser said:

          Error Loading File C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb
          Error: #<SyntaxError: C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:7: syntax error, unexpected >>, expecting keyword_end
          >>> "C:\Users\DAVID\AppData\Roa...
          ^
          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:7: Invalid escape character syntax
          ...ns\TNT_ClickWindow3D_Trial_mm\Components"

          ... ^
          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:9: Invalid escape character syntax
          ...ns\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Tr...
          ... ^
          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:10: syntax error, unexpected >>, expecting keyword_end
          >>>

                ^
          

          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:12: syntax error, unexpected >>, expecting keyword_end
          >>>

                ^
          

          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm/logic.rb:13: Invalid escape character syntax
          ...ns\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Tr...
          ... ^>
          C:/Program Files/SketchUp/SketchUp 2015/Tools/extensions.rb:197:in require' C:/Program Files/SketchUp/SketchUp 2015/Tools/extensions.rb:197:in load'
          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm.rb:28:in register_extension' C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm.rb:28:in module:ClickWindow3D_Trial_mm'
          C:/Users/DAVID/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/TNT_ClickWindow3D_Trial_mm.rb:18:in `<top (required)>'

          What was I doing wrong? 😲

          Thank you in advance for your help.

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

            It's all wrong !
            Where I wrote >>> ".... I was showing what the output of the set reference would be in the Ruby Console from the 'p ' command.

            Remove all of those early lines in the class's body
            Also you should probably set up the menu code in the module not within the class itself ??

            Obviously the loose >>> etc throws an error when it's read directly within the class's code !

            You have also not corrected the error in the path set up.
            @@path_to_00 = File.join(path_to_components, '00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm.skp')
            Will return:
            C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Trial-mm.skp\02-Sliding-Window-Trial-mm.skp
            which clearly will NOT exist !
            Which concatenate TWO skp file names in this way ?

            TIG

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

              Thank you for your prompt response.

              @tig said:

              It's all wrong !

              Sorry, I discovered the ruby so I am very bad. 😳

              @tig said:

              Where I wrote >>> ".... I was showing what the output of the set reference would be in the Ruby Console from the 'p ' command.

              Remove all of those early lines in the class's body

              Like this ?

              path_to_components = File.join(File.dirname(__FILE__), 'Components')
              "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components"
                      
              @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp')
              "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Trial-mm.skp"
                      
              @@path_to_00 = File.join(path_to_components,'02-Sliding-Window-Trial-mm.skp')
              "C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\02-Sliding-Window-Trial-mm.skp"
              
              path_to_components = File.join(File.dirname(__FILE__), 'Components')
              @@path_to_00 = File.join(path_to_components, '00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm.skp')
                      
              @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') 
              

              @tig said:

              Also you should probably set up the menu code in the module not within the class itself ??

              Can you show an example?

              @tig said:

              You have also not corrected the error in the path set up.
              @@path_to_00 = File.join(path_to_components, '00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm.skp')

              I have to write this?

              @@path_to_00 = File.join(C;\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components,'00-Control-Panel-Trial-mm.skp','02-Sliding-Window-Trial-mm.skp')
              

              @tig said:

              Will return:
              C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components\00-Control-Panel-Trial-mm.skp\02-Sliding-Window-Trial-mm.skp
              which clearly will NOT exist !
              Which concatenate TWO skp file names in this way ?

              Sorry, it also seemed impossible!

              I wanted to follow this example:

              @tig said:

              " The_user_path_to / Plugins / Your_Extension / Composants /Componant1.skp/Componant2.skp "

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

                NO.
                Do not add any raw text into the class's body.
                So it'll become

                path_to_components = File.join(File.dirname(__FILE__), 'Components')
                @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp')
                @@path_to_02 = File.join(path_to_components,'02-Sliding-Window-Trial-mm.skp')
                @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') 
                

                Now you have a reference to ' path_to_components' and using that, then the paths for the TWO SKP files...
                @@path_to_00
                and
                @@path_to_02

                Why do you think that [note how I added the '...']:
                @@path_to_00 = File.join('C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components', '00-Control-Panel-Trial-mm.skp', '02-Sliding-Window-Trial-mm.skp')
                would work ??
                It'll give the file-path:
                C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components/00-Control-Panel-Trial-mm.skp/02-Sliding-Window-Trial-mm.skp
                which clearly doesn't exist !!!
                Whereas the revised code [above] gives...
                @@path_to_00
                as C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components/00-Control-Panel-Trial-mm.skp
                and
                @@path_to_02
                as C:\Users\DAVID\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\TNT_ClickWindow3D_Trial_mm\Components/02-Sliding-Window-Trial-mm.skp
                which we might assume do exist ???

                PS: Note how the \ and / file-separators appear - best to fix on / ...
                perhaps fix those with path_string.tr!("\\","/") as you go...

                TIG

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

                  If I understand correctly, the code should look like this:

                  module ClickWindow3D_Trial_mm
                  
                    class << self
                  
                      path_to_components = File.join(File.dirname(__FILE__), 'Components')
                      @@path_to_00 = File.join(path_to_components,'00-Control-Panel-Trial-mm.skp')
                      @@path_to_02 = File.join(path_to_components,'02-Sliding-Window-Trial-mm.skp')
                      @@path_to_resources = File.join(File.dirname(__FILE__), 'Resources') 
                  
                      def add_00
                        Sketchup.active_model.import(@@path_to_00)
                        Sketchup.active_model.import(@@path_to_02)
                      end
                      
                  if !file_loaded?(__FILE__)
                  
                  
                          tb = UI;;Toolbar.new(%Q(Click-Window3D-Trial-mm))
                  
                          command1 = UI;;Command.new("add Resources"){ ClickWindow3D_Trial_mm.add_00 }
                  
                          command1.small_icon = File.join(@@path_to_resources,"add_00.png")
                  
                          command1.large_icon = File.join(@@path_to_resources,"add_00.png")
                  
                          command1.tooltip = %Q(add Resources)
                  
                          command1.status_bar_text = %Q(add Resources)
                  
                          tb.add_item(command1)
                  
                          tb.restore
                  
                          file_loaded(__FILE__)
                  
                         end
                  
                     end
                  

                  With this code, the only component of "@@ path_to_02" is imported by the icon. 😕

                  @tig said:

                  which we might assume do exist ???

                  Yes, the existing models.

                  @tig said:

                  S: Note how the \ and / file-separators appear - best to fix on / ...
                  perhaps fix those with path_string.tr!("\","/") as you go...

                  Thank you for this tip. 👍

                  Instead of importing 2 components with a icon.

                  Can we automatically import a component on boot up SketchUp with a "rb"?

                  Is it possible to make invisible to the user, with no way to display the component from SketchUp?

                  If possible, how the code should he be writing?

                  Thank you

                  David

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

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

                    I'm sorry but your coding is bonkers to me.
                    What are you smoking ?
                    command1 = UI::Command.new("add Resources"){ ClickWindow3D_Trial_mm.add_00 }should import both SKP files, BUT only if they exist...

                    So to test your code YOU need to add some simple steps within it...
                    For example some p or puts for the returned state as you set various paths,
                    also testing for File.exist?(some_file_path)

                    To be frank. for someone who is publishing extensions this is a surprisingly poor show...
                    I can't see what is so difficult in this process.
                    You seem to to be making things far more complicated than they need to be...

                    TIG

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

                      Rest assured, this code is crazy for me too! 💚

                      But as crazy as it is, it works :

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

                      @tig said:

                      What are you smoking ?

                      Smoking is bad for health, so I like to drink. 😛

                      @tig said:

                      So to test your code YOU need to add some simple steps within it...
                      For example some p or puts for the returned state as you set various paths,
                      also testing for File.exist?(some_file_path)

                      Can you show an example, I can test?

                      @tig said:

                      To be frank. for someone who is publishing extensions this is a surprisingly poor show...
                      I can't see what is so difficult in this process.

                      I am sad to disappoint you, but I started in ruby. 😞

                      My extensions work 99%, with "Dynamic Components", and 1% of ruby, to create a simple toolbar.

                      Thank you for your franchise.

                      @tig said:

                      You seem to to be making things far more complicated than they need to be...

                      You definitely right!

                      Can show me a simple example for the same result?

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

                        I already showed how to set up distinct references etc and you replied.
                        http://sketchucation.com/forums/viewtopic.php?p=604766#p604766

                        To check if the two paths are correct try:
                        puts "#{@@path_to_00} = #{File.exist?(@@path_to_00)}"
                        puts "#{@@path_to_02} = #{File.exist?(@@path_to_02)}"

                        Perhaps this would also be better to definitely avoid the prompt..
                        Sketchup.active_model.import(@@path_to_00, false) Sketchup.active_model.import(@@path_to_02, false)

                        TIG

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

                          Having thought this over...
                          Assuming both SKP files exist...
                          I think the issue is caused by your use of the model.import(path_to_skp) method.
                          The first run of the import forks off to another process, where you insert/move the instance of the imported file - thus the second import never starts as it's effectively cancelled by the first one.

                          There are other ways of doing this...
                          defn = model.definitions.load(path_to_skp)
                          adds the SKP to the model's definition,
                          then you can use other methods to insert it into the model.
                          entities.add_instance(defn, transformation)
                          Or use the alternative
                          model.place_component(defn)
                          You could also make your class a Tool and after adding the instance[s] use your tool to move the instance to a new location...
                          Another alternative might be to load the two and then make a group and add the two instances to its entities ?

                          I am not entirely sure what it is you are trying to achieve ?
                          A simpler way might even be to combine the two components into one new SKP and import than ?

                          TIG

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

                            Hello,

                            I am sorry for not being clear enough.

                            As it is possible to protect all a collection of "Dynamic Components", with a single "Parent Component," I want to import the "Component Parent" along with my dynamic models.

                            Import both components with a single icon sembait like a good idea, but I found much better now.

                            I allowed myself to open a new Topic with this new idea that is totally different.

                            If you still want to help me, I'd be delighted.

                            Sorry, for the time you have wasted on this topic.

                            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
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by

                              @tntdavid said:

                              As it is possible to protect all a collection of "Dynamic Components", with a single "Parent Component," I want to import the "Component Parent" along with my dynamic models.

                              Create a template model that already has your set of component definitions loaded, and then the user can use that template when they start a new model.

                              I'm not here much anymore.

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

                                @dan rathbun said:

                                Create a template model that already has your set of component definitions loaded, and then the user can use that template when they start a new model.

                                I understand your reasoning.

                                But I wish maximum ease of use of my dynamic components, and simultaneously protect them.

                                If we take the example of "Click-Window 3D", the windows are useless without the "Control Panel", which is the perfect example of a component "Parent" protector.

                                If the "Control Panel" is not on the SketchUp scene, you'll have problems with my dynamic components.

                                Instead of importing the control panel manually, I want it to be imported automatically.

                                This will prevent user error, because 80% of the time the first reflex of a user is importing the "3D Window" before the "Control Panel".

                                This can lead to a crash of SketchUp. 😒

                                It is therefore urgent for me to find a solution to import the "Control Panel" automatically on each new SketchUp scene.

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

                                  Now you have explained your reasoning perhaps we can come up with some ideas...

                                  When a user clicks on a 3d Window DC to import I assume it's through your code - perhaps a toolbar ?
                                  So instead of immediately importing that DC, you could first check if your special Control Panel component definition is loaded and if so if an instance of it is placed in the current view/scene...
                                  If the answer id no to either of those tests, then additional code could be run to do that step [or those steps] before moving on to import the DC.
                                  As explained before, rather than importing the Control Panel you can use
                                  cp = model.definitions.load(path_to_CP)
                                  Then say place an instance thus
                                  model.active_entities.add_instance(cp, ORIGIN)

                                  Then import the Window DC ?

                                  TIG

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

                                    I am currently developing a version of Click-Window 3D without "Control Panel".

                                    The 3D window will be changed manually with tools, "Scale", "Interact with Dynamic Components," and "Component Options".

                                    A perfect example is my plugin, Click-Change.

                                    However, i want to keep the protection of a "Parent" component, which will be a kind of invisible activation key of my "Dynamic Components".

                                    The method used in the code is not important, only those conditions is important:

                                    *** The "Parent" component, must be imported automatically.**

                                    *** It must be on the SketchUp scene before the first dynamic component.**

                                    *** It must be invisible or locked to prevent copy.**

                                    By fulfilling these conditions, we will have a good chance of protecting our dynamic components.

                                    @tig said:

                                    As explained before, rather than importing the Control Panel you can use
                                    cp = model.definitions.load(path_to_CP)
                                    Then say place an instance thus
                                    model.active_entities.add_instance(cp, ORIGIN)

                                    Then import the Window DC ?

                                    Your proposal meets the three conditions?

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

                                      @tig said:

                                      cp = model.definitions.load(path_to_CP)
                                      Then say place an instance thus
                                      model.active_entities.add_instance(cp, ORIGIN)

                                      The code should look like this ?

                                      module ClickWindow3D_Trial_mm
                                      
                                          module SomeSubModule
                                          
                                              def self.do_somethings()
                                      
                                                 path=Sketchup.find_support_file "cube.skp","Components"
                                                 model = Sketchup.active_model
                                                 definitions = model.definitions
                                                 componentdefinition = definitions.load path
                                                 point = Geom;;Point3d.new 10,20,30
                                                 transform = Geom;;Transformation.new point
                                                 definitions = model.definitions
                                                 instance = entities.add_instance componentdefinition, transform
                                                 end 
                                                 self.do_somethings() 
                                                 end
                                                 end
                                      

                                      If not, can you show me an example?

                                      Without explanation with code examples, I do not understand you.

                                      Thank you for your patience.

                                      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

                                        Please indent you code helpfully...
                                        However, even as it is, your code should 'almost' work... 😉
                                        Below, I've made a few minor adjustments, like -
                                        the () around methods' passed arguments, clearer naming etc...
                                        I have also added ### to the start of some unwanted code [that's like a ' rem' statement, as seen in some older coding conventions]

                                        module TNTDAVID
                                          module ClickWindow3D_Trial_mm
                                            def self.auto_run_code()
                                              path = Sketchup.find_support_file("cube.skp", "Components")
                                              ### let's assume that this SKP exists, 
                                              ### but it does limit the search to that specific SketchUp folder - 
                                              ### probably best to find it in your own subfolder of SKPs 
                                              ### and have it shipped within your extension's subfolder !
                                              model = Sketchup.active_model
                                              definitions = model.definitions
                                              component_definition = definitions.load(path)
                                              point = Geom;;Point3d.new(10, 20, 30) ### these offsets are in inches !
                                              transformation = Geom;;Transformation.new(point)
                                              ### definitions = model.definitions
                                              instance = entities.add_instance(component_definition, transformation)
                                            end
                                            self.auto_run_code() ### runs the code, loads the skp and places at instance...
                                          end
                                        end
                                        

                                        TIG

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

                                          Unfortunately even with your adjustment, the code does not work yet. 😢

                                          When I launch SketchUp, nothing happens.

                                          And the "Ruby console" shipments this error message :

                                          @unknownuser said:

                                          Error: # <TypeError: no implicit conversion of nil into String>

                                          Or is the error?

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

                                          Advertisement