Find the position of a specific vertex on a face.
-
Hello,
The method below shows the x, y,z positions of all vertices at the beginning of edges for a selected face.
Sketchup.active_model.selection.grep(Sketchup;;Face).each{|f|f.edges.each{|e|p e.start.position}}
I wish to know the position of the vertex down right side for a selected face?
The goal is to find this vertex even if the face is tilted or drawn in any direction.
It's been a while since I study the class "Edges" and "Faces" in the API without success.
Thanks for your help.
Manuel
-
You can directly access the vertices of faces
Sketchup.active_model.selection.grep(Sketchup;;Face).each do |face| face.vertices.each do |vx| puts "VX of face #{face.entityID} = #{vx.position}" end end
By using only
edge.start
, you may miss some vertices, because some vertices can be at the END of the their edges.NOW, there is no way to identify your specific vertex if the face is tilted, unless there is something particular to it (like an angle of its edges).
-
Work on a single face.
You can collect all of its vertices in a uniq array, using a method like Fredo's.
Then find the pointpt = face.bounds.min
Start with a test length that's ridiculously big say 1000.m ?, and initially setvert = nil
.
Then consider the distance from 'pt
' to the position of each vertex in turn.
Use a test along the lines of:
if distance <= length; vert = vertex; length = distance; end
After processing all vertices 'vert
' will be the one nearest 'pt
' 'bottom-left'...
To find 'top-right' useface.bounds.max
, and to find other permutations combine the various xyz values of the two min/max and project the combo-point perpendicularly onto theface.plane
too ? -
Hello,
Try this:
mod = Sketchup.active_model sel = mod.selection sommet = [] sel.grep(Sketchup;;Face).each do |f| @pt = f.bounds.min f.edges.each do |e| e.vertices.each do |v| sommet << v.position end end end p "VERTICES POSITIONS = #{vertices_posy}" p "POINT POSITION = #{@pt}"
Then follow the instructions of TIG.
Advertisement