Need help : Code to reload mutiple component
-
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!
-
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@tig said:
Look at this...
https://sketchucation.com/forums/viewtopic.php?p=331966#p331966Thanks 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

-
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...
-
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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement