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

    Get list of faces with associated corners

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 200 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.
    • J Offline
      Jodles
      last edited by

      Hello,

      I'm very new to scripting for SkechUp, and was wondering whether anybody could help point me in the right direction.

      I need to create a script that exports all faces and their associated corner coordinates to a text file. This must be such a simple task, and I've looked a bit through the documentation, but can't figure out how I would ask SketchUp for that information... (edit: I.e. any functions I should check out..?)

      Any pointers in the right direction would be greatly appreciated!

      J

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

        To learn to write files, you need to learn Standard Ruby.

        Begin with my newbies guide, that will lead you to more info ...

        I'm not here much anymore.

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

          What have you tried? And where are you stuck?

          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
            Jodles
            last edited by

            Thanks guys, I'll go through that tutorial and come back with some more specific questions. I realize my original post was a bit vague! I think I was hoping for a "oh it's only two lines of easy code"..

            I've used Python a lot, so I reckon picking up Ruby should be fairly quick (I hope).

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

              Well, when you say "all faces" - do you mean even those contained nested inside groups and components? Also, what output format would it be?

              In order to traverse entities in SketchUp you look at the Entities collection class. This is an Enumerable.

              To traverse the root context:

              <span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each&nbsp;</span><span class="syntaxkeyword">{&nbsp;|</span><span class="syntaxdefault">entity</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;...<br /></span><span class="syntaxkeyword">}&nbsp;</span><span class="syntaxdefault"></span>
              

              To traverse the active context (open group or component)

              <span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each&nbsp;</span><span class="syntaxkeyword">{&nbsp;|</span><span class="syntaxdefault">entity</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;...<br /></span><span class="syntaxkeyword">}&nbsp;</span><span class="syntaxdefault"></span>
              

              To traverse a collection of a specific type of entity:

              <span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)&nbsp;{&nbsp;|</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;Traverses&nbsp;all&nbsp;faces...<br /></span><span class="syntaxkeyword">}&nbsp;</span><span class="syntaxdefault"></span>
              

              Note that if you want to process nested groups and components you need to look for Sketchup::Group and Sketchup::ComponentInstance entities and recursively dig into them. Beware that the coordinates you get from a vertex is local to it's parent context - so if you need the global position you need to take into account the total transformation of all the parent nodes.

              More info on SketchUp's instances and definitions:
              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/

              It is an easy task - but you need to be familiar with the API to know what classes and methods to use. Which is why it'd help if you mentioned what you've tried so far as it'd be easier to point you in the correct direction instead of just general all-covering answers.

              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

                @jodles said:

                I've used Python a lot, so I reckon picking up Ruby should be fairly quick (I hope).

                Yes.. you have a major advantage if your brain has already reached the "object oriented programming epiphany."

                However.. two major differences to remember.

                (1) Ruby uses block delimiters (or keywords,) rather than the fixed indentation of Python. (Also Ruby uses 2 space indentation by tradition, not 4 space; and never odd space indents, and please avoid outdenting.. it sucks!)
                IE:

                { ... }
                begin ... end
                do ... end
                def ... end
                module ... end
                class ... end

                (2) Namespaces in Ruby are explicitly declared (more specifically opened for edit,) using the module or class blocks, not source file boundaries (as in Python.)

                The code for a module or class, may span any number of source files. Or in other words, any source file can open any module or class namespace(s) and modify them dynamically during runtime (unless they are frozen.)

                Lastly.. be very aware that include, extend, require, load and using ... work different in Ruby, than in Python.

                πŸ’­

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jodles
                  last edited by

                  Dan and thomthom, thank you so much! This is incredibly useful information on Ruby and where to start in the documentation. I'll have a go and report back if I get stuck!

                  thomthom: Yup, literally every face also nested within components and groups. Output is a simple text file.

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

                    Another thing to beware of: SketchUp stores ALL units in inches - internal. Always. It is only right when a unit is displayed in the UI that it is converted into the model units. So all coordinate data you get from SketchUp is in the Length class - which is a subclass of Float with extra methods to convert into model units for presentation. Something to beware of when you output the data.

                    More info on units in SketchUp: http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/

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

                    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