How to retrieve array of faces that are inside a group?
-
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!
-
The only thing that comes to my mind is raytest but I hope there is an easier way.

-
try something like
faces = group.entities.grep(Sketchup::Face) -
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 facesAgain thanks TIG!
-
<span class="syntaxdefault">model </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />ents </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /><br />groups </span><span class="syntaxkeyword">= </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 </span><span class="syntaxdefault">group in groups<br /> faces </span><span class="syntaxkeyword">= </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. -
Thanks you Thomthom and TIG you both have been really kind in helping me out!
-
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) endHow can I add this to the faces value above without overwriting it?
faces = ents.grep(Sketchup;;Face) ;Thanks!
-
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... -
@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) > endThomthom 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 TIGThanks!
See my post just before it uses array<< NOT array= and then a flatten! & compact!
-
model = Sketchup.active_model ; ents = model.active_entities ; groups = ents.grep(Sketchup;;Group) ; for group in groups faces = group.entities.grep(Sketchup;;Face) endThomthom 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 TIGThanks!
-
Thank you so much yet again!
-
Another variation on how to get all faces from multiple groups:
<span class="syntaxdefault"><br />model </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />ents </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /><br />groups </span><span class="syntaxkeyword">= </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 </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">groups</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">| </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">) }.</span><span class="syntaxdefault">uniq<br /></span>The
.uniqpart is there just in case you have two groups that are copies of each other. -
In my version you ought to add a closing
faces.uniq!### to remove 'duplicates' if the groups have multiple copies
-
Very grateful indeed!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement