@deanby7 said:
I know I'm missing something basic here but trying to get the vertices of a selected face....
@mod = Sketchup.active_model
> sel = @mod.selection
> verts = sel.grep(Sketchup;;Face) {|f|f.vertices}
> v = verts.position
>
Doesn't give me an array of 3d point values as expected?
Interrogate the Ruby documentation for each method used.
The Sketchup::Selection class (as well as most other API collection classes,) mix in the Enumerable library module.
This is where grep() comes from.
Enumerable#grep()
http://ruby-doc.org/core-2.0.0/Enumerable.html#method-i-grep
The grep() method always returns an array, either of the collection members matching the pattern, or the results of the block (if given.) It is similar to using a combination of find_all(), followed by map().
Your pattern was all Sketchup::Face objects, and you used a block which passed each face into the block in turn. Your block then called Sketchup::Face#vertices() upon each, which always returns an Array of Sketchup::Vertex objects.
So at the very least, your verts reference could point to an empty array (if no faces were grep'ed, and therefore the block is never called.) If the collection does hold face references, there will be a nested array of vertices, for each face found.
Now, there is a difference between a vertex and a point.
Sketchup::Vertex objects are model entity objects (and subclass of Sketchup::Drawingelement, which is subclass of Sketchup::Entity.) Meaning they are entities that are saved within the model geometric database.
They, in turn have a position property. Accessing that, returns a Geom::Point3d object, which in a virtual geometry "helper" object.
Anyway, if you want points, then call position upon the vertices, within the block:
point_arys = sel.grep(Sketchup;;Face) {|f| f.vertices.map{|v| v.position } }
... which now gives you an array of nested arrays of points (for each face.)
Or, ... access the points in two steps:
vert_arys = sel.grep(Sketchup;;Face) {|f| f.vertices }
for face_verts in vert_arys
face_points = face_verts.map {|v| v.position }
# do something with the array of face_points
end
🤓