sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Sketchup.active_model.entities.is_a?????

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

      So my understanding is that an entities object is not actually array. So what is it? I am thinking I remember being told it is a collection maybe? What does that mean.

      Think of it like this. I'm writing a tutorial on beginning ruby, and I really just want to call the entities object an array of entities in the model. But that isn't quite right and I feel like I should explain what it really is. So any thoughts how to explain that in about 5 words or less? 😆

      Chris

      PS I know I'm a horrible candidate to be writing a tutorial on Ruby. I know! After all, I still need to ask questions like the one above! But, there aren't many tutorials out there, so I thought I'd try to help.

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

      1 Reply Last reply Reply Quote 0
      • Al HartA Offline
        Al Hart
        last edited by

        All of the SketchUp classes - like Sketchup.active_model.selection (which is a group of entities) in a SketchUp class, rather than a Ruby class - such as an array.

        So Entities has similar functions - such as each and count (length for an array) - but it not a Ruby Array. (If it were then you could use Ruby change the Array, but it would be harder for SketchUp to know you had changed it.

        However, if you want to use Array functions on the Entities array, you can convert it to an Array with to_a. Then you have an array of the entities which you can use other Ruby Arrray functions on (I have a sample where I create an array of selected entities, process some and then subtract the array of entities processed from the original entity array). The entities int the new array are the same entities, but changes you make to the entity array do not effect the original SketchUp Entities class instance). For instance if you converted Sketchup.active_model.selection to a Ruby Array, and the removed an element from it, it would not effect the number of elements in the Sketchup.active_model.selection class.

        Al Hart

        http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
        IRender nXt from Render Plus

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

          I'd just call it a container. Yes, it's a magical container.

          Hi

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

            @jim said:

            Yes, it's a magical container.

            Hey, and you even met my 5 words or less requirement 🤣

            Thanks for the responses. Al, that makes a lot of sense to me now that I read it. I don't know how to recapitulate it quickly. So I probably won't. But if anyone asks in the future, I'll know where to point them 😄

            Chris

            And seriously, Jim. I'm undecided if you wake up rediculously early in the morning? or if you just don't sleep at all. Is it like just after 3:00am where you are?

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

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

              entities.to_a makes it one...

              TIG

              1 Reply Last reply Reply Quote 0
              • Al HartA Offline
                Al Hart
                last edited by

                @chris fullmer said:

                @jim said:

                Yes, it's a magical container.

                Thanks for the responses. Al, that makes a lot of sense to me now that I read it. I don't know how to recapitulate it quickly. So I probably won't. But if anyone asks in the future, I'll know where to point them 😄

                Try this: (24 words)

                @unknownuser said:

                Entities is a Class internal to SketchUp which acts like an array. You can convert it to an actual array with the .to_a operator.

                Al Hart

                http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                IRender nXt from Render Plus

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

                  @al hart said:

                  Entities is a Class internal to SketchUp which acts like an array. You can convert it to an actual array with the .to_a operator.

                  But it is a lot more than that. The Array behavior is secondary to its primary purpose of adding and containing a Model's visual elements.

                  Hi

                  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