sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Reload component script - anyone have one

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    21 貼文 13 Posters 3.3k 瀏覽 13 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Z 離線
      zzm
      最後由 編輯

      Hi,

      I was wondering if any one had a script that would:

      1. open a sketchup file
      2. replace a component with a different component.

      I have 300 skp files that I want to open and replace a tree with a different tree.

      1 條回覆 最後回覆 回覆 引用 0
      • GaieusG 離線
        Gaieus
        最後由 編輯

        Hi Zack,

        I wonder if TIG's X-ref manager could do this:
        http://forums.sketchucation.com/viewtopic.php?f=57&t=7289
        Note that there's a 5.1 version, too (but no discussion):
        http://forums.sketchucation.com/viewtopic.php?f=323&t=7329


        @TIG: any ideas about the plugin being the best for the job?

        Gai...

        1 條回覆 最後回覆 回覆 引用 0
        • TIGT 離線
          TIG Moderator
          最後由 編輯

          No existing tool but - you could write a simple script that opens all files in a selected folder [pick one skp it a folder to run] and imports a pre-specified tree-component and then changes all instances of another component [found by its name] with that new component...
          Can you be more specific and I'll outline a tool for it...

          TIG

          1 條回覆 最後回覆 回覆 引用 0
          • Z 離線
            zzm
            最後由 編輯

            Thanks for the ideas. I really wish I knew ruby a little better so I could write it. Here is more detail.

            1. Select a folder that has 300 skp files
            2. Find all components named "tree1.skp" (for example) would be nice to be able to change the name, but I could always tweak the code
            3. Replaces all "tree1.skp" with "tree2.skp" in all files. Open, save, and closes files.

            Basically what happen is that I used a tree for 300 files and realize now that I would like it to have a taller trunk. So running a ruby would be faster than opening all the files.

            1 條回覆 最後回覆 回覆 引用 0
            • jim smithJ 離線
              jim smith
              最後由 編輯

              Zack,

              Maybe I am misunderstanding your problem but if you right click a component, pick reload and pick another component, all instances are replaced.

              Jim

              "Out of clutter find simplicity,
              from discord find harmony,
              In the middle of difficulty lies opportunity"
              Albert Einstein

              1 條回覆 最後回覆 回覆 引用 0
              • GaieusG 離線
                Gaieus
                最後由 編輯

                He wants to do this in hundreds of skp files and too lazy to open them one-by-one (no wonder) 😲

                Gai...

                1 條回覆 最後回覆 回覆 引用 0
                • M 離線
                  MartinRinehart
                  最後由 編輯

                  @zzm said:

                  I have 300 skp files that I want to open and replace a tree with a different tree.

                  I've written a plugin-like Ruby, DOStalk.rb. It lets you issue MSDOS-type commands in the Ruby Console window. For instance,

                  dir '*.skp'

                  lists all the models in the current directory.

                  I bring this up because there is also a change command:

                  change '*.skp'

                  This calls process() for each file in the specified list. The default process() reports that it is processing each file in the Ruby Console.

                  Now we need a process() that swaps components. TIG?

                  Here's my DOStalk, very early version. Do not bury it in Plugins. Put it in some convenient directory where you can load it in the Ruby Console. load '/convenient/dir/DOStalk.rb'. (Choose something easier to type than "/convenient/dir".)

                  Edit: Ooops! Forgot to add:

                  
                  # DOStalk.rb - emulates a few MSDOS commands'
                  # Copyright 2010, Martin Rinehart
                  
                  $dos_talk_pmode = false 
                  
                  =begin
                  In program mode, the dir function returns a list of file names. Otherwise, it displays the list in the Ruby Console.
                  =end
                  
                  def dir( *args )
                  
                      if args.length() == 0
                          return Dir;;pwd()
                      end
                      
                      list = Dir;;glob( args[0] )
                      list.sort!()
                      
                      if $dos_talk_pmode 
                          return list
                      else
                          for f in list do puts f end
                          puts
                      end # if pmode
                      
                  end # dir()
                  
                  def cd( path )
                      Dir;;chdir( path )
                  end
                  
                  def change( path )
                      list = Dir;;glob( path )
                      for f in list do process( f ) end
                  end
                  
                  def del( path )
                      delete( path )
                  end
                  
                  def delete( path )
                      list = Dir;;glob( path )
                      for f in list do File;;delete( f ) end
                  end
                  
                  def ldt()
                      load __FILE__
                  end
                  
                  def md( path )
                      mkdir( path )
                  end
                  
                  def mkdir( path )
                      Dir;;mkdir( path )
                  end
                  
                  def process( pathname )
                      puts 'processing(  "' + pathname + '" )'
                  end
                  
                  def rd( path )
                      rmdir( path )
                  end
                  
                  def rmdir( path )
                      Dir;;rmdir( path )
                  end
                  
                  # end of DOStalk.rb
                  
                  

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  1 條回覆 最後回覆 回覆 引用 0
                  • Chris FullmerC 離線
                    Chris Fullmer
                    最後由 編輯

                    Yeah, but does that let him open all 300, replace a component, and then close them. And do it all automated? The point is that its tiresome to do that over 300 models if you have to do an action manually for each model.

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 條回覆 最後回覆 回覆 引用 0
                    • M 離線
                      MartinRinehart
                      最後由 編輯

                      Here's a start.

                      I don't know how to find the component to delete. Do you have to cruise through entities looking for Component and then check name. Any less tedious way? I also don't know how to import a component. Looked at Model.import() but that doesn't seem quite right. I was looking for something that let me position the component. Having to position 300 new components would be a big improvement for zzm, but hardly optimal.

                      zzm: by proceeding with this discussion you certify that your files are fully backed up and that you know, understand and will abide by all the terms and conditions of Murphy's Law.

                      
                      def zzm( )
                      
                          list = Dir;;glob( '*.skp' )
                          
                          if list.length == 0
                              UI.messagebox( 'Found no SketchUp models (*.skp).' )
                              return
                          end
                          
                          ret = UI.messagebox( 'There are ' + list.length().to_s() + 
                              ' files. Proceed?', MB_OKCANCEL )
                          return if ret == 2 # CANCEL
                          
                          prompts = ['Name of component to delete; ',
                              'Name of component to import; ']
                          defaults = ['deleteme', 'importme']
                          UI.inputbox( prompts, defaults, 'Delete/Import Box' )
                      
                          for fn in list do
                              file = Sketchup.open_file( fn )
                              UI.messagebox( fn + ' opened.' )
                      
                              # do the work here
                      
                              
                          end
                          
                      end
                      
                      

                      I'm gone for the day.

                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                      1 條回覆 最後回覆 回覆 引用 0
                      • thomthomT 離線
                        thomthom
                        最後由 編輯

                        Importing an external component: model.definitions.load http://code.google.com/apis/sketchup/docs/ourdoc/definitionlist.html#load
                        Position the component: Entities.add_instance(definition, transform) - just copy the transformation of the instance you replace.

                        @martinrinehart said:

                        I don't know how to find the component to delete. Do you have to cruise through entities looking for Component and then check name. Any less tedious way?

                        If you have it's name, then it's easy: model.definitions['definitionName']

                        I think the code would be something like this:

                        
                        newDef = model.definitions.load(path_to_new_component)
                        oldDef = model.definitions['definitionName']
                        oldDef.instances.each { |old_inst|
                          t = old_inst.transformation
                          ents = old_inst.parent.entities
                          ents.add_instance(newDef, t)
                          old_inst.erase!
                        }
                        
                        

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 條回覆 最後回覆 回覆 引用 0
                        • honoluludesktopH 離線
                          honoluludesktop
                          最後由 編輯

                          This is a great plugin, especially for landscape visulization.

                          1 條回覆 最後回覆 回覆 引用 0
                          • thomthomT 離線
                            thomthom
                            最後由 編輯

                            Moved this topic to the Developer section of the forum.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 條回覆 最後回覆 回覆 引用 0
                            • S 離線
                              sahi
                              最後由 編輯

                              It is my experiment.
                              Prompt me if that not so.

                              1. we choose a file (this will be a folder )
                              2. We enter the name of component
                              3. we choose a component in which and will replace

                              Attention!!!! Attention!!!! Attention!!!! before the use backup folder
                              menu "Plugins >> reload_component"
                              reload_component2.rb

                              1 條回覆 最後回覆 回覆 引用 0
                              • S 離線
                                SLOf1Fan
                                最後由 編輯

                                For some reason I have recently found that right-clicking a residence model in my site model to update the revised component does not work. I get the usual pop-up stating the component has been added and asks if I'd like to replace, however when I click yes, nothing happens. It used to open the file folder so I can select the replacement folder. Please help.

                                1 條回覆 最後回覆 回覆 引用 0
                                • T 離線
                                  Technical Ben
                                  最後由 編輯

                                  Sorry to post in an old thread. But I'm looking for something similar to this.
                                  Just a hobby project, but I would really like a tool that checked for updates to components for me.

                                  So, I have a large file separated into separate components, these are save in a folder (such as Floor 1, Floor 2, Floor 3 etc). These are constructed into one big model (Such as "House"). I would like a script that automatically loaded up the components from file, when I opened the main project. I thought Sketchup did this automatically, but I have to click "reload" and each component separately. 😞

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • honoluludesktopH 離線
                                    honoluludesktop
                                    最後由 編輯

                                    Select Window > components, right click the component you want to change in the component's window, then "select instances", again right click the component in the component's window, and "reload", "yes", and find the .skp you want.

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • TIGT 離線
                                      TIG Moderator
                                      最後由 編輯

                                      My old XrefManager does do this BUT you need to have added the items as an 'Xref'... It is long overdue an update, but does list components that have changed externally and then allows you to reload them...

                                      TIG

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • T 離線
                                        Technical Ben
                                        最後由 編輯

                                        Thanks honoluludesktop.
                                        I'll have to do that, and force myself not to amend objects in the wrong file.

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • B 離線
                                          BigAl
                                          最後由 編輯

                                          I'm using Thom Thom's lines of code below to batch replace a series of proxy components with hi-res versions.
                                          newDef = model.definitions.load(path_to_new_component)
                                          oldDef = model.definitions['definitionName']
                                          oldDef.instances.each { |old_inst|
                                          t = old_inst.transformation
                                          ents = old_inst.parent.entities
                                          ents.add_instance(newDef, t)
                                          old_inst.erase!
                                          }
                                          To speed this process up I'd like to add a conditional test before this code such that the code to replace Component A with Component B only runs if Component A already exists within the model. Otherwise skip to the next component in the list.
                                          Does such code or similar already exist somewhere?
                                          Any help greatly appreciated.

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • Dan RathbunD 離線
                                            Dan Rathbun
                                            最後由 編輯

                                            It looks like it already does that.

                                            Meaning ComponentA's defintion's instances collection is iterated, and the statements within the curly delimited block are run if the collection has any references pointing at instances that have been placed within the model.

                                            IF the instances collection is empty, then the iteration loop is exited without running the block.

                                            ❓

                                            I'm not here much anymore.

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement