sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Replace multiple components from library

    Scheduled Pinned Locked Moved SketchUp Discussions
    sketchup
    11 Posts 2 Posters 355 Views 2 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.
    • S Offline
      samyell77
      last edited by

      Hi all,
      Just wondering if anyone can help me. Im looking for a way to update multiple components in a file. Ive a library file saved on a network drive with several folders of components - probably around 500 components in total. I want to make some adjustments to all of these components (adding a layer and several 2d elements for drafting in Layout) and wonder if there is a way to update ALL of the components in a SU model without having to individually select each component and reload it (in the edit tab in components window).
      Any help with this would be (very) much appreciated!
      Thanks
      Sam

      SU Pro 2016
      Dell Precision M4800
      PC Windows 10
      Intel Core i7-4900MQ @ 2.80ghz
      Nvidia Quadro K2100M
      16gb RAM

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

        IF the SKP files of the saved_as components are in the same location as they were either 'loaded-from' or were 'saved_as-to'... and you do not have any 'not-saved_as' but previously 'made-unique' [and then edited] component definitions [these will still have their 'paths' set as the same as the original base definitions' paths and that you don't want to update 1]...
        Then it is possible to use a one-liner thus

        m=Sketchup.active_model;m.start_operation('!');s=m.definitions;s.to_a.each{|d|next if !d.valid?;next if !d.path;next if !File.exist?(d.path);d.name=d.name+(rand.to_s);c=s.load(d.path.tr("\\","/"));d.instances.each{|i|i.definition=c};s.purge_unused};m.commit_operation
        

        copy/paste the whole line of code into the main SKP's Ruby Console + <enter> and the definitions should all update where they can. It's multi-step undo-able [4/defn]...
        πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • S Offline
          samyell77
          last edited by

          Gotcha - nice one TIG. Will create a dummy library and give this a go (just so I dont mess my existing library up)

          Thanks!

          SU Pro 2016
          Dell Precision M4800
          PC Windows 10
          Intel Core i7-4900MQ @ 2.80ghz
          Nvidia Quadro K2100M
          16gb RAM

          1 Reply Last reply Reply Quote 0
          • S Offline
            samyell77
            last edited by

            Hi TIG, just tried the code and I don't seem to get a result? Sorry but wonder if you can see where Im going wrong.

            Created test file and made some dummy components in this file
            Went to in file in components pallet and saved as local collection
            Closed test file
            Opened each component file and changed colours / sizes - then saved (in same location with same name)
            Re-opened test file (still displaying old un coloured components)
            Pasted script into console
            Components dont update to new coloured ones and got the following in console after hitting enter . . .

            m=Sketchup.active_model;m.start_operation('!');s=m.definitions;s.each{|d|next if !d.path;next if !File.exist?(d.path);d=s.load(d.path)};m.commit_operation
            true

            Tried restarting SU after saving files but no dice!

            Thanks in advance

            SU Pro 2016
            Dell Precision M4800
            PC Windows 10
            Intel Core i7-4900MQ @ 2.80ghz
            Nvidia Quadro K2100M
            16gb RAM

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

              😳 Stupid error in my code meant it failed or 'did nothing much', also I hadn't spotted an anomaly - where a definition's path uses '' as file separators [PC?] but 'defs.load' requires '/' [might not be an issue on MAC? as it's always '/'] ! So I had to 'tr' them to get it to work; I'm sure it didn't used to be like that! πŸ˜•
              You can get the corrected code from my original post that I've edited...
              I have retested it and it works for me...
              πŸ€“

              TIG

              1 Reply Last reply Reply Quote 0
              • S Offline
                samyell77
                last edited by

                TIG - truly you are a leg-end! Thanks so much!!

                This has saved me hours of really boring and laborious work, thank you, thank you, thank you,

                πŸ‘

                SU Pro 2016
                Dell Precision M4800
                PC Windows 10
                Intel Core i7-4900MQ @ 2.80ghz
                Nvidia Quadro K2100M
                16gb RAM

                1 Reply Last reply Reply Quote 0
                • S Offline
                  samyell77
                  last edited by

                  Hi TIG,
                  I just tried this script out on a live job and its brought back an unexpected result. I ran the script and all the components updated BUT all the updated ones now have a long string of numbers after their name?

                  For example one component that used to be called
                  FURN Gilato Freezer
                  is now called
                  FURN Gilato Freezer0.2997187799735820.3522457440064450.555740003636928

                  If the names are going to change then unfortunately I will have to go back to the drawing board and rebuild jobs manually because all of our component names are linked to a stock file database which is name and case sensitive.
                  Do you know why this would have happened and if its possible to keep the names the same as the original?
                  Thanks

                  SU Pro 2016
                  Dell Precision M4800
                  PC Windows 10
                  Intel Core i7-4900MQ @ 2.80ghz
                  Nvidia Quadro K2100M
                  16gb RAM

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

                    This shouldn't be happening [obviously!]. 😲
                    Something is adrift...
                    What it should do is go through the components to be reloaded, and renames each of them with a random number at the end.
                    Then it loads the external SKP [updated] - that one then gets the original name. It then swaps the originals' definition for the new definition and purges the now unused one - which should be the one with the numerical suffix...
                    I'll write this up properly as a script rather than a one liner as it's easier to debug etc...
                    Watch this space...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      samyell77
                      last edited by

                      Thank you TIG - very much appreciate your help with this!
                      Sam

                      SU Pro 2016
                      Dell Precision M4800
                      PC Windows 10
                      Intel Core i7-4900MQ @ 2.80ghz
                      Nvidia Quadro K2100M
                      16gb RAM

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

                        Try this - put the .rb file into Plugins and restart... read the instructions !

                        Copyright 2012 (c) TIG.
                        Permission to use, copy, modify, and distribute this software for
                        any purpose and without fee is hereby granted, provided that the above
                        copyright notice appear in all copies.
                        THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
                        IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

                        TIG-reloadcomps.rb

                        Reloads all component definitions that have an existing external SKP
                        matching their remebered 'path'.
                        To run type [or copy/paste] in the Ruby Console...
                        TIG.reloadcomps
                        With the Ruby Console is open it gives a report of the progress...
                        Components 'made unique' but still referring the same external file would be
                        merged on the reload, so they are excluded from the processing - there's a
                        beep and report lists them [if any]. Re-running the tools will merge a
                        duplicated definitions in steps; alternatively you might well wish to do a
                        save_as on the reported components if they differ in geometry etc, so they
                        then refer to their own separate external file...
                        It returns 'false' if duplicates, or 'true' if all processed.
                        It is NOT one-step undoable [multi-stepped].

                        Donations:
                        By PayPal.com to info @ revitrev.org

                        Version:
                        1.0 20120306 First issue.


                        TIG-reloadcomps.rb

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          samyell77
                          last edited by

                          Thanks TIG - yet to test this out properly (other projects on at the moment) but hope to try it out shortly.
                          Cheers

                          SU Pro 2016
                          Dell Precision M4800
                          PC Windows 10
                          Intel Core i7-4900MQ @ 2.80ghz
                          Nvidia Quadro K2100M
                          16gb RAM

                          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