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_instancesdo 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()
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement