Count instances correctly
-
hi all, I would like to know how to count the number of instances of a definition, the "Entity Info" window appears correctly butdefinition.count_instances
do not, is there anything in the API or somewhere to get this information? attached skp file with which I am doing testsinstances.skp
thank you very much in advance for the help
(google translator) -
See how I did it in this plugin I wrote for Ash Scott:
[Plugin] Multiple Component Edit Warning -
Thanks Dan, this can give me a hint, I'm testing with the definition given there, but in my testing model (instances.skp) gives me a wrong number of instances, sometimes less or sometimes more, I do not know if I'm misapplying the definition count_instances ()
# you must have a selected instance def count_instances() num = 0 if @editpath.size == 1 i = @editpath.last else revpath = @editpath.reverse i = revpath.shift end if i.is_a?(Sketchup;;ComponentInstance) num = i.definition.instances.size elsif i.is_a?(Sketchup;;Group) num = i.entities.parent.instances.size end if @editpath.size > 1 revpath.each {|i| if i.is_a?(Sketchup;;ComponentInstance) num = num * i.definition.instances.size elsif i.is_a?(Sketchup;;Group) num = num * i.entities.parent.instances.size end } end return num end mod = Sketchup.active_model sel = mod.selection ruta = mod.active_path (ruta) ? (ruta[ruta.size] = sel[0]) ; (ruta = []; ruta[0] = sel[0]) @editpath = ruta count_instances()
Advertisement