sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Removing duplicat Component Instances from an array

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 934 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      ktkoh
      last edited by

      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

      1 Reply Last reply
      Reply Quote 0
      • D
        driven
        last edited by

        ['a','a','b','c'].uniq
        ["a", "b", "c"]
        

        doesn't uniq work?

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply
        Reply Quote 0
        • TIGT
          TIG Moderator
          last edited by

          Because each instance has its own unique reference you'll need to use their actual definitions to get a reduced list.
          So let's assume iarray is 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 named defns !
          Process that...

          TIG

          1 Reply Last reply
          Reply Quote 0
          • Dan RathbunD
            Dan Rathbun
            last edited by

            Or use Enumerable#grep ...

            defns = selection.grep(Sketchup::ComponentInstance){|i| i.definition }.uniq

            But, if you've already got the instances filtered then:

            defns = iarray.map{|i| i.definition }.uniq

            I'm not here much anymore.

            1 Reply Last reply
            Reply Quote 0
            • K
              ktkoh
              last edited by

              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

              1 Reply Last reply
              Reply Quote 0

              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 Login
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement