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

    Obtaining selected face vertices

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 653 Views 2 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.
    • D Offline
      Deanby7
      last edited by

      I know I'm missing something basic here but trying to get the vertices of a selected faced....

      @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?

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @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
        
        

        🤓

        I'm not here much anymore.

        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