Explode 1 level component
-
Hi,
I have components containing components(nestled components? sub components?)
I would like to explode only the first level of components, to keep the information contained in the sub components
i tried this code
ent = mod.entities for e in ent if e.is_a? Sketchup;;ComponentInstance e.explode end end
but instead on exploding only the initial components once, it seems that sketchup explodes completely the first component, then the sub components of the first initial component, ...
is there a way to explode only once the initial components?
-
Use
ents.to_a
- that freezes the list; if you use 'ents
' it keeps looking into what's available in the 'entities' and it will find some things that have just been added from the one you've just exploded ! -
@tig said:
Use
ents.to_a
- that freezes the list; if you use 'ents
' it keeps looking into what's available in the 'entities' and it will find some things that have just been added from the one you've just exploded !Yes, this is exactly what was happening
i made the correction
ents = mod.entities ents.to_a for e in ents.to_a if e.is_a? Sketchup;;ComponentInstance e.explode end end
and now it works perfectly
Thank you very much; it took you a few seconds, while i had been looking for a solution the whole day...
-
@unknownuser said:
it took you a few seconds, while i had been looking for a solution the whole day...
I know the feeling
Does this give the same result for you? I've heard iterators are a good bet.
I'm just a hack, just something I picked up..
Acctually looking for the contrary of what you are, exploding everything that's nested.
So I will try the opposite of what TIG recommended for you. Good thread!ents.to_a.each{|e| next if not e.valid? e.explode if e.class==Sketchup;;ComponentInstance } end
-
@jolran said:
@unknownuser said:
it took you a few seconds, while i had been looking for a solution the whole day...
I know the feeling
Does this give the same result for you? I've heard iterators are a good bet.
I'm just a hack, just something I picked up..
Acctually looking for the contrary of what you are, exploding everything that's nested.
So I will try the opposite of what TIG recommended for you. Good thread!ents.to_a.each{|e| > next if not e.valid? > e.explode if e.class==Sketchup;;ComponentInstance > } > end > >
No, what i get is:
Error: #<SyntaxError: (eval):8:in `initialize': compile error
(eval):8: syntax error, unexpected kEND, expecting $end
endTo explode nestled components, maybe you could try this
http://www.smustard.com/script/Bomb -
oh sorry typo. You need to incoperate it with the rest of your script and put "end".
Never mind.. I probably to green to give any advice.
Will have a look at that bomb, thanks! -
You have a superfluous 'end' after the '}'.
The 'for...end' is similar to the '..each{...}'
The block is '{...}' so the 'end' is not needed [unless of course it's part of a longer piece of text - e.g. it's needed to close a method 'def', an 'if' test etc] -
So I was wrong in everything I said
Yes it was part of some longer piece, I copy and pasted it wrong, sorry.
Advertisement