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

    How to subclass things?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 502 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.
    • S Offline
      skybum
      last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        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

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

        1 Reply Last reply Reply Quote 0
        • S Offline
          skybum
          last edited by

          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!

          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