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

    Vertex Counting plugin?

    Scheduled Pinned Locked Moved Plugins
    14 Posts 7 Posters 2.4k Views 7 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.
    • sdmitchS Offline
      sdmitch
      last edited by

      @dsarchs said:

      Does anyone know if a plugin exists that can give you a quick count of how many vertices are in a given selection? If not, would that be an easy script to write?

      Here is one that will. It looks at whole model if nothing is selected.

      
      require 'sketchup'
      
      module SDM_PtCnt
      
        def self.point_counter
          mod=Sketchup.active_model
          ent=mod.active_entities
          sel=mod.selection
          sel=ent if sel.empty?
          @f_cnt=0;@e_cnt=0;@verts=[]
          recurse(sel)
          @verts.flatten!.uniq!
          UI.messagebox "This model contains\n\n#{@f_cnt} faces\n#{@e_cnt} edges\nand #{@verts.length-1} vertices"
        end
        
        def self.recurse(ents)
          ents.each do |e|
            if e.is_a? Sketchup;;Group
              recurse(e.entities)
            elsif e.is_a? Sketchup;;ComponentInstance
              recurse(e.definition.entities)
            elsif e.is_a? Sketchup;;Face
              @f_cnt += 1;@verts<<e.vertices
            elsif e.is_a? Sketchup;;Edge
              @e_cnt += 1;@verts<<e.vertices
            end
          end
        end
        
      end
      
      if not file_loaded?(File.basename(__FILE__))
        UI.menu("Plugins").add_item("Point Counter") { SDM_PtCnt.point_counter }
        file_loaded(File.basename(__FILE__))
      end
      
      

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

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

        @verts.flatten!.uniq!

        Beware of the bang methods. .flatten! and .uniq! - while faster and preferred, will return nil upon no change.
        One has to use them on separate lines to avoid potential, and likely, errors.

        @verts.flatten! @verts.uniq!

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

        1 Reply Last reply Reply Quote 0
        • D Offline
          dsarchs
          last edited by

          Thanks for the responses. I'll have to try this out when I get home tonight.

          Knowledge is a polite word for dead but not buried imagination.

          -e.e.cummings

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @thomthom said:

            @verts.flatten!.uniq!

            Beware of the bang methods. .flatten! and .uniq! - while faster and preferred, will return nil upon no change.
            One has to use them on separate lines to avoid potential, and likely, errors.

            @verts.flatten! @verts.uniq!

            But combined as @verts.flatten.uniq! so there's only an end 'bang!' it will work.
            Without the ! it returns the changed array, with it it returns either the changed array OR nil if there's no change !!

            TIG

            1 Reply Last reply Reply Quote 0
            • D Offline
              dsarchs
              last edited by

              I finally had a chance to try this out and it works (almost) perfectly!

              Almost because for some reason it always returns 1 less vertex than is actually present. For example, a square plane shows 3, a cube shows 7, etc.
              This is a complete non-issue, though, since I'm just trying to make sure the number is less than (I think) 25,000.

              Thanks again!

              Knowledge is a polite word for dead but not buried imagination.

              -e.e.cummings

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                In my code you compile an array of arrays of vertices from faces... [vs]
                The vs.flatten! explodes the arrays into one giant array.
                The vs.uniq! ensures that there are no duplicates [two abutting faces share 2 vertices].
                The vs.length returns the total number of vertices - it should not be 'short' πŸ˜•

                TIG

                1 Reply Last reply Reply Quote 0
                • D Offline
                  dsarchs
                  last edited by

                  I actually used the code offered by sdmitch (after having separated the command as thomthom suggested), and saved it as a plugin rather than having to cut+paste whenever I wanted to check.

                  Knowledge is a polite word for dead but not buried imagination.

                  -e.e.cummings

                  1 Reply Last reply Reply Quote 0
                  • Rich O BrienR Online
                    Rich O Brien Moderator
                    last edited by

                    Fredo has vertex marking tools and count sides tool maybe ask to report the vert numbers?

                    A small donation goes along way πŸ‘

                    Download the free D'oh Book for SketchUp πŸ“–

                    1 Reply Last reply Reply Quote 0
                    • sdmitchS Offline
                      sdmitch
                      last edited by

                      @dsarchs said:

                      I actually used the code offered by sdmitch (after having separated the command as thomthom suggested), and saved it as a plugin rather than having to cut+paste whenever I wanted to check.

                      You are correct. The count was one less than it should be. Out of habit, because Ruby array index always starts at 0, subtracting 1 from the array length is so common that it is a reflex action. The correct message statement would be

                      UI.messagebox "This model contains\n\n#{@f_cnt} faces\n#{@e_cnt} edges\nand #{@verts.length} vertices"
                      
                      

                      Nothing is worthless, it can always be used as a bad example.

                      http://sdmitch.blogspot.com/

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        dsarchs
                        last edited by

                        Thanks, although I'm not really worried that it lists 1 less than actual. I just checked and the limit is 64,000 vertices -- so being off by 1 is irrelevant. I mostly wanted a tool to see how many object groups I could combine for single export.
                        If I think about it I'll change the code when I get home tonight -- but either way it's working for what I need it to do.

                        Knowledge is a polite word for dead but not buried imagination.

                        -e.e.cummings

                        1 Reply Last reply Reply Quote 0
                        • fredo6F Offline
                          fredo6
                          last edited by

                          @unknownuser said:

                          Fredo has vertex marking tools and count sides tool maybe ask to report the vert numbers?

                          The new version of CountFacesBySides, part of FredoTools, now provide the count of vertices in the selection or the whole model.

                          Fredo

                          1 Reply Last reply Reply Quote 0
                          • bac9-flclB Offline
                            bac9-flcl
                            last edited by

                            Hey, I've just wanted to say thanks for all your answers here!
                            I'm working with CE3 too, and your code is really helpful to me. πŸ˜„

                            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