• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

3D Export capabilities with Ruby

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 4 Posters 511 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.
  • J Offline
    JClements
    last edited by JClements 22 Feb 2009, 03:05

    ❓

    Would it be possible to create a ruby which would export only the SELECTED geometry in a model to a KMZ file (or perhaps a selection of groups or components with each group or component placed their own separate KMZ using their component name or group name for the name of the KMZ)?

    It would be helpful for organizing content in Google Earth..

    John | Illustrator | Beaverton, Oregon

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 22 Feb 2009, 05:22

      Hi John, I thought it would be possible, but I am not having any luck actually getting it to work like I thought it should. So I have a questions for the Ruby folks:

      I thought that model = Sketchup.active_model sets "model" to be a reflection (for lack of the right word) of the current model. And I thought that if I was inside a group, that model was essentially everything within that group, but nothing above it in the heirarchy (so none of the parent entities). So I thought I could go into the component I wanted to export and then start the code with

      model = Sketchup.active_model
      
      model.export "mymodel.kmz", true
      

      And that in my mind was going to export everything within the component I was editing, but nothing outside it. But that doesn't work. So I'm guessing that Sketchup.active_model is not exactly what I think it is. Is that right? Is Sketchup.active_model always the entire model? Or is it something different altogether?

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 22 Feb 2009, 11:05

        Sketchup.active_model is always the whole model.
        Sketchup.active_model.active_entities is the entities in the currently open group/component.

        But I suspect that you won't have the export method available from active_entities.

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

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 22 Feb 2009, 18:10

          Oh, now I remember what I was thinking of. Sketchup.active_model.active_entities is all the entities inside the current group/component. It's the active_entities that narrows it down to current group/component only. Bummer.

          So is there a way to tell SKetchup.active_model to be anything less than the entire model?

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • J Offline
            JClements
            last edited by 22 Feb 2009, 18:39

            Perhaps this procedure could be scripted:

            1- User selects Group(S) and or Component(S) to export. Names of this entities are "remembered"/stored.

            2- Reverse the selection (I found this code in an old script)

            class Invert
             def Invert.toggle_all 
               mod = Sketchup.active_model
               ss = mod.selection 
               objects = mod.active_entities          # Everthing in the current edit level. 
               if (ss.empty?) then 
                 UI.beep 
                 return 
                 end 
               objects.each {|o| 
                 ss.toggle(o)                         # Flip current selection set. 
                 }
               end # Invert.toggle_all 
            end # Class
            

            3- Those entities in this inverted selection set are "remembered"/stored (I assume locked entities are automatically ignored)

            4- Names of all entities in inverted selection set are hidden.

            5- Then execute File > Export > 3D. The names collected at Step 1 are used as the model name (multiple names are separated my a comma or something similar >>> User given opportunity to override and type in a different name for the KMZ).

            6- Export completed.

            7- Using the names of the inverted selection set, an UnHide Last is executed.

            -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

            If it is possible to hack into the KML which is contained in the KMZ at this point, then rename the "model" folder contained within it to that of the KMZ file. See below.

            Screen Caputure.png

            Note, if a Colladae file could be made to store latitude, longitude, and elevation info, then that might be an even cleaner solution.

            John | Illustrator | Beaverton, Oregon

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 27 Feb 2009, 16:56

              JC I think your hidden ("not selected") things would still export.

              Perhaps it's more possible if you invert the selection.
              Unlock anything that's locked in that new selection.
              Erase all new selection.
              Exported the model (what's left is the original selection).
              THEN undo everything so nothing is selected, unlocked or deleted.

              The exported file won't be undone [I hope] ?

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 27 Feb 2009, 17:01

                @tig said:

                The exported file won't be undone [I hope] ?

                Exporting model doesn't seem to appear in the undo stack.

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

                1 Reply Last reply Reply Quote 0
                • J Offline
                  JClements
                  last edited by 27 Feb 2009, 17:05

                  Tig,
                  So far, from my testing, hidden objects are not being exported. Try it yourself. If you create KMZ file, change it to a ZIP extension and open it. Examine the diretory and file sturcture.

                  If you want to examine the embedded KML file (or KMZ file directly), try Northgate's free KML editor.

                  John | Illustrator | Beaverton, Oregon

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

                  Advertisement