Count instances in selection???
-
hi all,
i have a script where i am at one point helpless with a problem:its a script giving me a summary of weights.
i have components with dynamic attributes "gewicht" (weight).
i select a couple, then i get a dialog box with the following:number of selected items.
total weight.then:
number of item a - name of item a - single weight item a
number of itemb - name of item b - single weight item b
and so on...depending on how many things are in my selection.
one part doesnt work though, that which i put in bold above.
it doesnt show me the number of instances in my selection, as iwant, but
it rather shows me the number of instances in my model.
and i cant see the code for it.any body got some advice? thx alot
the problem is, where it says: "e.definition.count_instances"
so basically i want: "e.definitions.count_instances" for my selection.
here's the part of the code:name=[] ss.each{|e| if e.class==Sketchup;;ComponentInstance name=name+[e.definition.count_instances.to_s+ "x \t"+e.definition.name+ " \ta "+e.definition.get_attribute("dynamic_attributes","gewicht",0)+" kg"+"\n"] end } -
My initial thought would be:
numSelectedInstances = (e.definition.instances & ss.to_a).length # & intersects two arraysYou'll probably want to stick around and see what the others say.
-
You want to count the instances in a selection...
counts=[] ss.each{|e|counts<< e.definition if e.class==Sketchup;;ComponentInstance} countsuniq=counts.uniq compocount=[] countsuniq.each{|e| count=0 counts.each{|c|count+=1 if c==e} compocount<< [e.name, count] } ### compocount is an array, with each item as an array of the instance's definition.name [you could change it to just the definition itself 'e' ?] and then its number of instances as counted in the selection (ss)...
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