Identify groups by its attributevalue and delete them
-
I'm looking for a way to delete groups which have certain values in the attributes of an AttributeDictionary.
So I want to identify the group by its attributevalue and than I want to delete those groups.
Is that possible??? -
Yes. How are you getting the references to the groups? All in model ? Selected?
You want to check against attribute value, attribute key, attribute section?
What is your SU Ruby API experience?
-
It can be one or more groups of all groups in Modell.
I want to check against attribute value.
My SU Ruby API experience is a little bit more than rookie .
-
<span class="syntaxdefault"><br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next unless d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /> if </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">) == </span><span class="syntaxstring">'value'<br /> </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">! }<br /> </span><span class="syntaxdefault">end<br /></span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault"></span>
-
If the instance has the attribute rather than its definition... then it'll be
<span class="syntaxdefault"><br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next unless d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /> </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">|<br /> if </span><span class="syntaxdefault">i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">) == </span><span class="syntaxstring">'value'<br /> </span><span class="syntaxdefault">i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!<br /> </span><span class="syntaxdefault">end<br /> </span><span class="syntaxkeyword">}<br /> }<br /> </span><span class="syntaxdefault"></span>
-
@tig said:
If the instance has the attribute rather than its definition... then it'll be
<span class="syntaxdefault"><br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> next unless d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> if i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'<br /></span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> end<br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>
Thank you, that works fine!!!
-
@thomthom said:
<span class="syntaxdefault"><br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> next unless d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> if d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'<br /></span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> end<br /></span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>
Thank you, but that does not work.
-
@tig said:
If the instance has the attribute rather than its definition... then it'll be
<span class="syntaxdefault"><br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> next unless d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> if i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'<br /></span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> end<br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>
That works fine for all groups!
How must the code be changed, if only will be referencing to the selected groups? -
<span class="syntaxdefault"><br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next unless e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</span><span class="syntaxkeyword">?( </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Group </span><span class="syntaxkeyword">)<br /> if </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">) == </span><span class="syntaxstring">'value'<br /> </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!<br /> </span><span class="syntaxdefault">end<br /></span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault"></span>
-
@thomthom said:
<span class="syntaxdefault"><br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> next unless e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</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"> if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'<br /></span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> end<br /></span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>
Thank you!
That works fine!I want to use it also to another job.
Textures should be assigned to the groups:Sketchup.active_model.selection.each { |e| next unless e.is_a?( Sketchup;;Group ) if e.get_attribute('section', 'key') == 0 e.material = "oak_trans" elsif e.get_attribute('section', 'key') == 1 e.material = "oak_long" end }
That works with the selected groups.
But the groups one or more level lower will not be edit.
What have to be changed to use it for the groups into the groups? -
Make a recursing method - something like this:
<span class="syntaxdefault"><br />def assign_group_materials</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">)<br /> if </span><span class="syntaxdefault">group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">) == </span><span class="syntaxdefault">0<br /> group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"oak_trans"<br /> </span><span class="syntaxdefault">elsif e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">) == </span><span class="syntaxdefault">1<br /> group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">material </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"oak_long"<br /> </span><span class="syntaxdefault">end<br /> group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next unless e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</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">assign_group_materials</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">)<br /> }<br /></span><span class="syntaxdefault">end<br /><br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next unless e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_a</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">assign_group_materials</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">)<br />}<br /> </span><span class="syntaxdefault"></span>
-
Thank you!!!
But there is an error:
<span class="syntaxdefault"><br /> elsif e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 1<br /></span>
[/quote]
It must be:
<span class="syntaxdefault"><br /> elsif group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_attribute</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'section'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'key'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 1<br /> </span>
I see, you want to test me
Thank you!!!!!!
-
yea sure... it was a test.
Advertisement