• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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

Scheduled Pinned Locked Moved Developers' Forum
14 Posts 3 Posters 350 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.
  • R Offline
    renderiza
    last edited by 16 May 2013, 06:27

    Hi,

    I want to fix my Animatex plugin to animate faces with textures even within a group but I can't manage to retrieve index of faces inside groups. Here is the Animatex forum just in case... http://sketchucation.com/forums/viewtopic.php?f=323&t=52238

    Any help will be appreciated!

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

    1 Reply Last reply Reply Quote 0
    • R Offline
      renderiza
      last edited by 16 May 2013, 07:40

      The only thing that comes to my mind is raytest but I hope there is an easier way. πŸ˜’

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

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 16 May 2013, 08:22

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

        TIG

        1 Reply Last reply Reply Quote 0
        • R Offline
          renderiza
          last edited by 16 May 2013, 09:23

          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
          • T Offline
            thomthom
            last edited by 16 May 2013, 09:28

            <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
            • R Offline
              renderiza
              last edited by 16 May 2013, 09:31

              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
              • R Offline
                renderiza
                last edited by 16 May 2013, 09:55

                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
                • T Offline
                  TIG Moderator
                  last edited by 16 May 2013, 10:10

                  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
                  • T Offline
                    TIG Moderator
                    last edited by 16 May 2013, 10:15

                    @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
                    • R Offline
                      renderiza
                      last edited by 16 May 2013, 10:18

                      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
                      • R Offline
                        renderiza
                        last edited by 16 May 2013, 10:19

                        Thank you so much yet again!

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

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 16 May 2013, 10:26

                          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
                          • T Offline
                            TIG Moderator
                            last edited by 16 May 2013, 10:31

                            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
                            • R Offline
                              renderiza
                              last edited by 16 May 2013, 10:37

                              Very grateful indeed!

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

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              1 / 1
                              • First post
                                1/14
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement