sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Script to bring all components from library into SU model

    Scheduled Pinned Locked Moved Plugins
    6 Posts 3 Posters 211 Views 3 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,
      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

      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

        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):2537

        Apologies 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

        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 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 "\\" ๐Ÿค“

          TIG

          1 Reply Last reply Reply Quote 0
          • dukejazzD Offline
            dukejazz
            last edited by

            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

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

              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.

              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

                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 ๐Ÿ‘

                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