sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Creating SketchUp scene from saved files using Ruby script

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 4 Posters 1.6k Views 4 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.
    • M Offline
      MeAd
      last edited by

      Dear All,

      I want to create a sketchup file by automatically populating with locally saved 3D sketchup models using ruby script executed from command line. I also want to apply a transformation (rotation + translation) on each of the imported models and finally save the sketchup file. For example, I created two files: 'sofa.skp' and 'table.skp'. I want to load these files onto a new file 'room.skp' after rotating and translating these objects in ruby script. Any ideas?

      I tried to use model.import command (using COLLADA object files as shown below) but it requires a mouse click on SketchUp GUI to place the individual objects that makes it tedious considering the fact that the number of individual models as well as the need for automation. Thank you for your help.

      model = Sketchup.active_model
      model.import "file1.dae"

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        <span class="syntaxdefault"><br />model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />definition </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">load</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> skp_file </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">rotation</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> point</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vector</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> angle </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> definition</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> tr </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"></span>
        

        DefinitionList#load

        Entities#add_instance

        Some general info on instances and definitions in SketchUp:
        http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/

        General info on SketchUp plugin development:
        http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • M Offline
          MeAd
          last edited by

          Thanks Thomthom. It works perfectly. One last question, can you save the new scene automatically (if possible without showing the SketchUp GUI)?

          I used the following command and I even could not locate the file.

          ` model=Sketchup.active_model
          definition=model.definitions.load('sofa.skp')
          tr= Geom::Transformation.translation [0, 0, 0]
          model.active_entities.add_instance(definition,tr)
          definition1=model.definitions.load('table.skp')
          tr1= Geom::Transformation.translation [0, 0, 0]
          model.active_entities.add_instance(definition1,tr1)

          Sketchup.active_model.save "c:/Desktop/room.skp"`

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @mead said:

            can you save the new scene automatically

            Do you actually mean Scene here - as in the saved views you have in SketchUp - or simply model (which is what your code indicate).

            @mead said:

            Sketchup.active_model.save "c:/Desktop/room.skp"

            Are you sure you have the correct path? 'C:/Desktop' - do you really have a folder of that name?

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • M Offline
              MeAd
              last edited by

              Hello Thomthom,

              Thanks for your prompt response. Just to clarify my previous question:

              @thomthom said:

              Do you actually mean Scene here - as in the saved views you have in SketchUp - or simply model (which is what your code indicate).
              I just meant simply model.

              @thomthom said:

              Are you sure you have the correct path? 'C:/Desktop' - do you really have a folder of that name?
              Yes, I have the folder. In fact,I tried to save it in many folders and I could not locate it in any of the folders.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                What is the return value of Model.save ?

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  No you cannot run SketchUp in "headless" mode (without the GUI.)

                  BUT you CAN write a C/C++ application (and compile it,) that uses the SketchUp C++ SDK. Your application (be it a command line utility,) can create and save model files with no GUI.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    ? Did he ask about that?

                    Sent from my LT25i using Tapatalk 2

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

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

                      @unknownuser said:

                      by MeAd » March 19th, 2013, 8:36 pm

                      Dear All,

                      I want to create a sketchup file by automatically populating with locally saved 3D sketchup models using ruby script executed from command line.

                      Here a ruby script executed from command line.
                      pic_0298.jpg
                      you can populate skp file with a drop down inputbox on a second moditor display then copy and paste to display one.
                      A good outline for drop down is my Plugins_loader_dj v1.6
                      I have a plugin that can helps you copy and paste to your presentation
                      2) Another_Sketchup_dj v1.6
                      3) Another_Sketchup_Plus_dj v1.6
                      that can be found here
                      http://sketchucation.com/forums/viewtopic.php?f=323&t=46688
                      projectEditor_dj 1.6
                      Copyright Feb 4, 2013
                      by DukeJazz: James Cochran

                      @unknownuser said:

                      I also want to apply a transformation (rotation + translation) on each of the imported models and finally save the sketchup file. For example, I created two files: 'sofa.skp' and 'table.skp'.

                      for (rotation + translation)
                      [Plugin] scaleGroupFloat_dj Ver 1.6.5 Feb 15, 2013by dukejazz » May 11th, 2012, 3:36 pm
                      http://sketchucation.com/forums/viewtopic.php?f=323&t=45254
                      scaleGroupFloat_dj Ver 1.6.5
                      Copyright Feb 15, 2013
                      DukeJazz: by James Cochran

                      @unknownuser said:

                      I want to load these files onto a new file 'room.skp' after rotating and translating these objects in ruby script. Any ideas?

                      1. Another_Sketchup_dj v1.6
                      2. Another_Sketchup_Plus_dj v1.6
                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        MeAd
                        last edited by

                        Thanks Thomas. As you suggested, I used the model.save status to see if it is saved correctly and I found out that it was not. Somehow I saw unintentional character in the command and removed it. Now, everything is working.

                        Now, whenever I run the ruby script from the command line, it automatically save it as .skp. However, every time I run the ruby script, it opens a new SketchUp GUI, which i am not fond of since I am creating many models. My very last question, is it possible to perform the task without opening any SketchUp GUI?

                        Thanks a bunch Thomas.

                        1 Reply Last reply Reply Quote 0
                        • M Offline
                          MeAd
                          last edited by

                          Thank you all for your help. 👍 👍

                          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