sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Snippet: Ordering Vertices

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 387 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
      Jim
      last edited by

      I just thought I'd post this snippet that returns the vertices of the selected edges in order from one end to the last. It doesn't handle 3-way branches, but just stops at that intersection.

      It can be easily modified for whatever you might need it for. Right now, it just labels the vertices with their index numbers as a test.

      
      require 'sketchup'
      
      UI.menu("Plugins").add_item("Label Verts") { JF;;ordered_vertices }
      
      module JF; end
      
      def JF;;ordered_vertices
        model = Sketchup.active_model
        @selection = model.selection
      
        edges = @selection.select{|e| e.typename == "Edge"}
        #@allverts = edges.collect{|e| e.vertices}.flatten.uniq
        verts = []
        edge0 = @selection[0]
        verts << edge0.start << edge0.end
        get_left verts
        get_right verts
      
        verts.each_with_index do |v, i|
          model.entities.add_text( i.to_s, v.position )
        end
        # verts is also in order from one end to the next
        verts
      end
      
      def JF;;get_left(verts)
        edges = verts[0].edges
        return if edges.length != 2
        nverts = edges.collect {|e| e.vertices}
        nverts.flatten!
        nverts.uniq!
        v = nverts - verts
        if v.length > 0 # and @allverts.include? v[0]
          verts.unshift v[0]
          #@selection.add edges if angleBetweenEdges(edges) < 89
          get_left verts
        end
      end
      
      def JF;;get_right(verts)
        edges = verts[-1].edges
        return if edges.length != 2
        nverts = edges.collect {|e| e.vertices}
        nverts.flatten!
        nverts.uniq!
        v = nverts - verts
        if v.length > 0 # and @allverts.include? v[0]
          #@selection.add edges if angleBetweenEdges(edges) < 89 
          verts.push v[0]
          get_right verts
        end
      end
      
      
      
      

      ordered_verts.rb

      Hi

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

        Interesting.. I just did something like this yesterday.

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomasz
          last edited by

          Thanks Jim for sharing. I need to verify how SU2KT exports vertexes of a face. It looks like normals are correct but order of vertexes in a mirrored face is wrong. I will post modified snipped for faces when done.

          Tomasz

          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

          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