How to subclass things?
-
Greetings,
I am new to Ruby, so forgive me if this question is terribly ignorant. I'm trying to create a new class of objects which behave exactly like Sketchup::Group objects, with a few additions. Now, I can go ahead and extend the Sketchup::Group class, but that seems like bad form. What I ought to be able to do -- I think -- is simply subclass it. But I've spent all day trying to figure out how to do so, to no avail.
I can make a subclass of Sketchup::Group easily enough, but it's totally inert and useless unless it's placed in Sketchup.active_model.entities -- and I can't figure out how to get it there. As best as I can figure out, I could extend that class with an "add_foobar" method -- although I'm not sure what it would actually do -- and as long as I'm extending Sketchup classes directly, I might as well just do it to Sketchup::Group directly.
So, I've reached the point where I'm going in circles. Rather than spend another few hours documenting all the stupid things I've tried that haven't worked -- can anybody tell me how to subclass a native Sketchup object and put it into the scene?
Thanks a million!
-
you cannot subclass a SU object, you can just create another group and add entities to it.
what do you want exactly to do ? maybe there is another solution to your problem
-
Hm. Strange that you can extend a Sketchup object, but not subclass it! One of the things which put me onto this path was a post (http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=10299&p=69423) on best practice in coding for Sketchup, which recommends: "Don't arbitrarily extend SketchUp or Ruby base classes. Subclass them with your own class, and extend your class." Perhaps I am misunderstanding what this means?
Anyhow, what I'm trying to do is generate a bunch of objects automatically, based on user interaction with another object. The objects I'm generating would have a hierarchical structure -- just like a group hierarchy -- and would benefit from actually being groups which the user can modify at a later date. So, generally speaking, it would be ideal if they were groups. The reason I was wanting to subclass them is because they'll need a lot of associated metadata with various associated methods, and a subclass of a group would seem like an ideal way to accomplish that.
Is there a better way that I should be pursuing? Thanks for your help, by the way!
Advertisement