Removing duplicat Component Instances from an array
-
I am having a problem trying to eliminate duplicate Component Instances from an the selection array. If the user selects more than one instance of a component I want to eliminate that from the array before operating on the selection. Suggestions would be appreciated.
Thanks
Keith -
['a','a','b','c'].uniq ["a", "b", "c"]doesn't uniq work?
-
Because each instance has its own unique reference you'll need to use their actual definitions to get a reduced list.
So let's assumeiarrayis an array of your selected instances [up to you how you compile this...]
Then use something like this...
defns = [] iarray.each{|i| defns << i.definition unless defns.include?(i.definition) }
Now you have an array of all selected definitions nameddefns!
Process that... -
Or use
Enumerable#grep...defns = selection.grep(Sketchup::ComponentInstance){|i| i.definition }.uniqBut, if you've already got the instances filtered then:
defns = iarray.map{|i| i.definition }.uniq -
Thanks for the help I just got to part of the program where this is needed. I visulized 6 to10 lines of code knowing that unique would work directly.
Keith
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