sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Using .uniq! in a plugin

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    4 Posts 2 Posters 161 Views 2 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.
    • sdmitchS Offline
      sdmitch
      last edited by

      In the Ruby console, if I create a series of 3d points and save them in an pts array then enter pts.uniq!, the duplicates are removed. But if I do the same thing in a plugin and execute the plugin nothing is removed. There is no indication of an error.

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

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

        If the points are the same Point3d these are uniq'd; they are the same point.
        If the points are different Point3ds they are not uniq'd.
        If the points are as arrays then they will be seen as different and uniq'd...........

        TIG

        1 Reply Last reply Reply Quote 0
        • sdmitchS Offline
          sdmitch
          last edited by

          The statements that created the points are exactly the same in the plugin as was used to create the points in the Ruby Console.

             pts=[]
          pts.push Geom::Point3d.new(1,1,1)
          pts.push Geom::Point3d.new(2,2,2)
          pts.push Geom::Point3d.new(1,1,1)
          pts.push Geom::Point3d.new(3,3,3)
          pts.push Geom::Point3d.new(2,2,2)
          pts.push Geom::Point3d.new(1,1,1)
             pts.uniq!
          

          In the plugin nothing is removed as pts.length is 6 before and after the uniq! statement.
          In the Ruby Console the 3 duplicates are removed.

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

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

            The API result is correct... even if two points are identical in their x/y/z they are different Point3d's.
            Either compare them as arrays to find it they ARE 'equivalent'... or use the 'set' functions...

            TIG

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement