Sketchup.active_model.entities.is_a?????
-
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.
-
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.
-
I'd just call it a container. Yes, it's a magical container.
-
@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?
-
entities.to_a makes it one...
-
@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 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.
Advertisement