@ssunderland said:
` n=0
i=0
Sketchup.active_model.selection[n].set_attribute("Bubble","id",i); n+=1; i+=1`
You are missing some basic knowledge of Ruby.
Most of the API collection classes have the library module Enumerable mixed into them.
http://ruby-doc.org/core-2.0.0/Enumerable.html
It is usually safer (to avoid fencepost errors, etc.) to use the built-in block form iterator methods.
Sketchup.active_model.selection.each_with_index {|ent,idx|
ent.set_attribute("SSU_Bubble","id",idx)
}
If you want to process in reverse order, make an array copy of the selection, using to_a
and the Array#reverse method:
Sketchup.active_model.selection.to_a.reverse.each_with_index {|ent,idx|
ent.set_attribute("SSU_Bubble","id",idx)
}
However, there is one major rule. Do not delete collection members while iterating the collection. The loop will lose it's place, and strange results occur. In that case, always iterate an array copy of the collection, if your loop must remove or add collection members. This is most often seen while modifying Entities collections.