• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Need help : Code to reload mutiple component

Scheduled Pinned Locked Moved SketchUp Discussions
5 Posts 2 Posters 1 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.
  • Q Offline
    QUOCANH ELNINO
    last edited by 16 Nov 2023, 08:55

    Hello, can anyone help me resolve this isssue :

    • I have many simple component in with name : com1, com2, com3...in a file original.
    • I have save all component to file com1.skp, com2.skp, com3.skp... in folder A
    • Then i edit file component com1.skp, com2.skp, com3.skp....in folder A, Now i want to reload all component from folder A (have edited) to file original.
    • It's same action with reload component in sketchup but with mutiple block in one time.
      Thanks for any help guy!
    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 16 Nov 2023, 11:02

      Look at this...
      https://sketchucation.com/forums/viewtopic.php?p=331966#p331966

      TIG

      1 Reply Last reply Reply Quote 0
      • Q Offline
        QUOCANH ELNINO
        last edited by 17 Nov 2023, 02:36

        @tig said:

        Look at this...
        https://sketchucation.com/forums/viewtopic.php?p=331966#p331966

        @tig said:

        Look at this...
        https://sketchucation.com/forums/viewtopic.php?p=331966#p331966

        Thanks TIG, But when I import all component in folder A to file, all new component imported turn to Com1#1, Com 2#,...And old component in file not change 😕

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 17 Nov 2023, 16:13

          So what you need is to load Com1, then if Com1 exists take Com1#1 and add an instance of it into the model using Com1 instance's transformation. Then remove the original Com1 definition, then rename Com1#1 as Com1...

          This is doable but somewhat convoluted !

          I'll look at a snippet...

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 17 Nov 2023, 17:20

            Try this...

            module TIG
              module DefinitionReplacer
                def self.run()
                  model=Sketchup.active_model
                  defns=model.definitions
                  model.start_operation("DefinitionReplacer", true)
                  counter=0
                  defns.to_a.each{|defn|
                    name=defn.name
                    next if name=~/[#]/
                    defns.to_a.each{|d|
                      n=d.name
                      next unless n=~/[#]/
                      next unless d.instances[0]
                      next unless n.split("#")[0]==name
                      defn.name=name+rand.to_s
                      d.name=name
                      ins=d.instances
                      defn.instances.each{|i|
                        i.definition=d
                      }
                      ins.each{|i|
                        i.erase!
                      }
                      counter+=1
                    }
                    defns.remove(defn)
                  }
                  model.commit_operation
                  puts "Processed #{counter} definitions"
                end#def
              end #module
            end #module
            TIG;;DefinitionReplacer.run()
            #to use, it assumes you have a number of component definitions [Com1, Com2, etc],
            #and you have already imported a similar set of edited ones into the model [Com1#1, Com2#1 etc].
            #to run it, paste all of this into the Ruby Console, it should auto-run.
            #all instances of the original Com1 become Com1#1, renamed as Com1, 
            #any instances of the previous Com1#1 are erased and its definition removed.
            #it's one step undo-able
            

            TIG

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

            Advertisement