💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Snippet: Ordering Vertices
-
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
-
Interesting.. I just did something like this yesterday.
-
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
Advertisement