π‘ LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Quickly finding groups/comps in an Entity Collection?
-
this thread reminds me of this:
http://refactormycode.com/codes/2-ruby-simple-loop
with each consecutive code sample improving on the lastalthough the only improvement I could possibly add might be:
def miner(ents) for e in ents if e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance miner(e.explode) end end end
-
Or to compact it as much as I can see, into a one-liner
def xis(a);a.each{|e|xis(e.explode)if e.class==(Sketchup;;Group||Sketchup;;ComponentInstance)};end
"xis" == e
X
plodeI
nstanceS
Usage:xis(entities)
PS: a shorter way to do their puts 1 to 10 is this
n=0;p n+=1while n<10
-
I take a few extra lines for readability any day.
-
@thomthom said:
I take a few extra lines for readability any day.
True, but "squish-the-code" is a fun exercise and I often learn something new.
def xis(a);a.map{|e|xis(e.explode)if e.respond_to?('move!')};end
(assuming no one has added move! to any of the built-in classes!)
Advertisement