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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Find the ObjectID for an array?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 8.4k 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      I am working with some arrays and I was wondering how to find the objectID of each array? I am imagining doing something like:

      puts my_array.object_id

      Anything like that possible? I'm probably just overlooking the obvious...

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        Oh! I found it. my_array.id gives an object id. That works. I was having problems with duplicate arrays and I was able to track them down with this. This is what the problem was.

        I was creating an array full of empty arrays with this:

        needed_arrays = 100 my_array = Array.new(needed_arrays, Array.new)

        Apparently that makes an array with 100 identical arrays. So if you push something to my_array[0] or my_arra[99], it is all going into the same ayyar apparently....

        Instead I used

        my_array = [] needed_arrays = 100 needed_arrays.times { my_array << [] }

        and that is working much better.

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          Actually, the method is .object_id

          @chris fullmer said:

          Apparently that makes an array with 100 identical arrays.

          100 references to the same Array, but not 100 arrays. I know, I'm being pedantic.

          Create them as needed:

          my_array = []
          my_array[index] ||= [] 
          my_array[index].push(value)
          

          Hi

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            @jim said:

            100 references to the same Array, but not 100 arrays. I know, I'm being pedantic.

            Its ok, its good for me. And is there a difference between .object_id and .id and .id ? And I saw a hint at :name - what is that? I couldn't get it to work.

            And in your example, what does ||= do? I'm guessing it creates an empty array at [index] if there is not an array there already?

            Thanks Jim.

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            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