Script to bring all components from library into SU model
- 
 Hi, 
 I started this post in the Sketchup forum but wonder now whether it might be better in here.
 Wonder if anyone can help me to find or write a script that will allow me to bring all of the components from a component library into an SU file. Ideally I'd like to be able to place them next to each other in a line or on a grid (say 1000mm grid).
 Is this possible to do? Currently Im having to manually load components and would like to find a quicker way to do it.
 Thanks
 Sam
- 
 Ive been having another trawl around to see if I can find away to do this and found this post which seems like the perfect starting point. http://sketchupapi.blogspot.com/2008/03/inserting-external-sketchup-component.html This is the script I have been trying to get to run pants_def = Sketchup.active_model.definitions.load("C:\pants.skp") 
 Sketchup.active_model.place_component(pants_def)I have changed the file path to match where I have saved the file on my computer but I keep getting the following error message if I run the script. (eval):2537 
 pants_def = Sketchup.active_model.definitions.load("C:\Users\sam.morris\Desktop\pants.skp")
 Error: #<IOError: (eval):2537:in `load': Invalid component file>
 (eval):2537
 (eval):2537Apologies for the probably being a complete noobie error on my part but Im trying to work out how to do this. 
 I have downloaded the two components from the post and have changed the name of the skpfile to pants to match the script. I know this post is very old (2008) and I wonder if it may be that the way ruby works has changed since then but Im stumped. It seems like a very simple code and I feel like a simpleton for not being able to get it to work.
 Any advice much appreciated.
 Sam
- 
 If you use \ as the file separators in filepaths you must either enclose the path inside '...' OR 'escape' the \ if it's inside "...", alternatively use /, inside either '...' or "...' 
 So - assuming the file does indeed exist - these are valid...
 pants_def = Sketchup.active_model.definitions.load("C:\\Users\\sam.morris\\Desktop\\pants.skp") pants_def = Sketchup.active_model.definitions.load('C:\Users\sam.morris\Desktop\pants.skp') pants_def = Sketchup.active_model.definitions.load("C:/Users/sam.morris/Desktop/pants.skp") pants_def = Sketchup.active_model.definitions.load('C:/Users/sam.morris/Desktop/pants.skp')
 BUT this is NOT valid...
 pants_def = Sketchup.active_model.definitions.load("C:\Users\sam.morris\Desktop\pants.skp")
 because of the non-escaped '' inside "..." subtly changes the meaning and it's therefore no longer a valid path when Ruby reads it !
 If you are copying filepaths from 'Windows' folders etc use them inside '...' or if used inside "..." then remember to edit the text to double up every \ as a \ ...
 Inside "..." a single \ is a special character that gives the character that follows it a different meaning.
 So"\n"is a new-line and"\t"is a tab etc.
 So to make Ruby see a \ that is inside "..." as not this special character, but as a real , you must double it up thus"\\" 
- 
 Open two shetchup: Copy and paste to another shetchup and lay them out so you can see your object: if you see what want then copy back 
- 
 Thanks dukejazz - but it still means I have to load all of the component from the component browser in the first place. I have hundreds (around 700 at last count) of components to load so am trying to find a way to load them all 'automatically' with the use of a script. I don't currently have them all in one file to copy from, they are all saved as individual components in a component library folder. 
- 
 TIG - thanks for the thorough explanation. Still coming up against some problems with the next part of the scrip but will do some further reading when I get time to see where Im going wrong. Totally new to scripting so need to try to get my head round this a bit better. 
 Cheers 
Advertisement


 
                             
                             
                             
                             
                             
                             
                            