sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    How to retrieve array of faces that are inside a group?

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 499 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      try something like
      faces = group.entities.grep(Sketchup::Face)

      TIG

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Hi,

        I can't seem to iterate though all the groups to get all faces. Only can retrive faces if I use [0] or [1] in faces = group[0].entities.grep(Sketchup::Face) for only one group.

        Is there a way to have something like group.each kinda thing?

        model = Sketchup.active_model 
        ents = model.entities 
        
        group = ents.grep(Sketchup;;Group)
        faces = group[0].entities.grep(Sketchup;;Face)
        
        UI.messagebox faces
        

        Again thanks TIG!

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          <span class="syntaxdefault">model&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />ents&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /><br />groups&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Group</span><span class="syntaxkeyword">)<br />for&nbsp;</span><span class="syntaxdefault">group&nbsp;in&nbsp;groups<br />&nbsp;&nbsp;faces&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end</span>
          

          groups.each {} also works off course.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • renderizaR Offline
            renderiza
            last edited by

            Thanks you Thomthom and TIG you both have been really kind in helping me out!

            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

            1 Reply Last reply Reply Quote 0
            • renderizaR Offline
              renderiza
              last edited by

              Hi,

              Can I include both faces inside groups and faces out of groups in the same 'face=' variable?

              model = Sketchup.active_model ;
              ents = model.active_entities ;	
              
              groups = ents.grep(Sketchup;;Group) ;
              for group in groups
                faces = group.entities.grep(Sketchup;;Face)
              end
              

              How can I add this to the faces value above without overwriting it?

              faces = ents.grep(Sketchup;;Face) ; 
              

              Thanks!

              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                model = Sketchup.active_model
                ents = model.active_entities
                
                faces = ents.grep(Sketchup;;Face)
                
                groups = ents.grep(Sketchup;;Group)
                for group in groups
                  faces << group.entities.grep(Sketchup;;Face)
                end
                
                faces.flatten! ### combine []'s
                faces.compact! ### remove 'nils'
                
                ### now you have an array of 'faces' in the model's active_entities AND inside all groups in the model's active_entities...
                

                TIG

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  @unknownuser said:

                  model = Sketchup.active_model ;
                  > ents = model.active_entities ;   
                  > 
                  > groups = ents.grep(Sketchup;;Group) ;
                  > for group in groups
                  >   faces = group.entities.grep(Sketchup;;Face)
                  > end
                  

                  Thomthom the code above I though retrieved all faces from all groups but only does it for one. It acts like when I used [0], any ideas?

                  Note:: Posted this before seeying TIG post... 😳
                  Let me test your suggestion TIG

                  Thanks!
                  See my post just before it uses array<< NOT array= and then a flatten! & compact! πŸ˜’

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • renderizaR Offline
                    renderiza
                    last edited by

                    model = Sketchup.active_model ;
                    ents = model.active_entities ;   
                    
                    groups = ents.grep(Sketchup;;Group) ;
                    for group in groups
                      faces = group.entities.grep(Sketchup;;Face)
                    end
                    

                    Thomthom the code above I though retrieved all faces from all groups but only does it for one. It acts like when I used [0], any ideas?

                    Note:: Posted this before seeying TIG post... 😳
                    Let me test your suggestion TIG

                    Thanks!

                    [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                    1 Reply Last reply Reply Quote 0
                    • renderizaR Offline
                      renderiza
                      last edited by

                      Thank you so much yet again!

                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Another variation on how to get all faces from multiple groups:

                        <span class="syntaxdefault"><br />model&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />ents&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /><br />groups&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Group</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">faces&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">groups</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map&nbsp;</span><span class="syntaxkeyword">{&nbsp;|</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">)&nbsp;}.</span><span class="syntaxdefault">uniq<br /></span>
                        

                        The .uniq part is there just in case you have two groups that are copies of each other.

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          In my version you ought to add a closing
                          faces.uniq! ### to remove 'duplicates' if the groups have multiple copies πŸ˜’

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • renderizaR Offline
                            renderiza
                            last edited by

                            Very grateful indeed!

                            [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                            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