How to retrieve array of faces that are inside a group?
-
<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) end
How 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) > 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 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) 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 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
.uniq
part 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!
Advertisement