• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

New API Object Diagram

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 8 Posters 655 Views 8 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
    scottlininger
    last edited by 22 Apr 2009, 15:11

    We're happy to announce a new feature on the Ruby Docs site, an object hierarchy diagram for the core parts of the API. Hopefully this will make it easier for SketchUp programmers to groc how things are related.

    Thanks to our QA master, Simone, for putting this together. You can read his blog post here .

    • Scott Lininger
      SketchUp Software Engineer
      Have you visited the Ruby API Docs?
    1 Reply Last reply Reply Quote 0
    • R Offline
      remus
      last edited by 22 Apr 2009, 15:58

      Thanks, thats really helped me understand a bit more about how ruby works in SU πŸ‘

      http://remusrendering.wordpress.com/

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 22 Apr 2009, 22:04

        Cool - a bit more comprehensive than mine .

        Something I'm curious about - why is a ComponentDefinition a DrawingElement? It's clear why an ComponentInstance is_a DrawingElement, but not sure about why the Definition needs to be.

        Hi

        1 Reply Last reply Reply Quote 0
        • S Offline
          scottlininger
          last edited by 22 Apr 2009, 22:20

          @jim said:

          Something I'm curious about - why is a ComponentDefinition a DrawingElement? It's clear why an ComponentInstance is_a DrawingElement, but not sure about why the Definition needs to be.

          The only reason that I'm aware of is so it inherits .bounds from Drawingelement. That's really the only Drawingelement method that makes sense in a definition context.

          Other than that? "Historical reasons." πŸ˜‰

          • Scott Lininger
            SketchUp Software Engineer
            Have you visited the Ruby API Docs?
          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by 22 Apr 2009, 23:52

            Thanks Simone!!!

            1 Reply Last reply Reply Quote 0
            • M Offline
              Matt666
              last edited by 23 Apr 2009, 07:23

              Great πŸ‘ πŸ‘
              Just two things, correct me if I'm wrong:

              • Groups also have component definitions
              • Curves and ArcCruves are edges
                πŸ˜‰

              Frenglish at its best !
              My scripts

              1 Reply Last reply Reply Quote 0
              • R Offline
                RickW
                last edited by 23 Apr 2009, 15:40

                @matt666 said:

                Great πŸ‘ πŸ‘
                Just two things, correct me if I'm wrong:

                • Groups also have component definitions
                • Curves and ArcCruves are edges
                  πŸ˜‰

                Groups are found in the ComponentDefinitions, but you can't (necessarily/natively) call group.definition. However, copies of a group will act like instances until they are made unique (meaning that if you change one via ruby, all will change). You can make them unique by manually editing them or by calling group.make_unique (ruby will yell at you that it's a deprecated method, but it's absolutely necessary until this bug is fixed).

                Curves and ArcCurves are not edges. They are comprised of edges, but a curve is not an edge. That's why you have curve.edges (to get the edges that comprise the curve) and edge.curve (to get the curve of which that edge is a part).

                Hope that clarifies things...

                RickW
                [www.smustard.com](http://www.smustard.com)

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Matt666
                  last edited by 24 Apr 2009, 06:12

                  Ok, thank you Rick!

                  Frenglish at its best !
                  My scripts

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 24 Apr 2009, 10:19

                    The new API Graph helps to clarify.

                    Curves and ArcCurves are not Drawingelements as Edges are. That means they are really defined by their methods (and properties) rather than the type of object they appear to be on the screen.

                    So an ArcCurve IS_A Curve IS_A Entity - so you can't work with them the same way you can with edges (or Drawingelements) because they do not share the same methods. You need to go back to the Entity class to find methods that are shared between Drawingelements and Curves/ArcCurves.

                    There is an idea in the Ruby community called "duck typing ". If something (object) walks like a duck and quacks like a duck, then it IS a duck. The practical result is that instead of checking what type (or class) an object is, you check the object's properties.

                    For a simple example, if we want to collect all the Vertices in a selection most of us would do the following:

                    
                    verts = []
                    Sketchup.active_model.selection.each { |e|
                      if( (e.is_a? Sketchup;;Face) or (e.is_a? Sketchup;;Edge) )
                        verts.concat(e.vertices)
                      end
                    }
                    
                    

                    Duck typing says it's better to write it this way:

                    
                    verts = []
                    Sketchup.active_model.selection.each { |e|
                      if( e.respond_to?("vertices") )
                        verts.concat(e.vertices)
                      end
                    }
                    
                    

                    We don't really care about what type of object 'e' is, only that it has vertices.

                    Sorry. I'm not sure how I got into that last topic, but there it is.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by 24 Apr 2009, 15:54

                      Thats a great example there Jim, and it makes much more sense. Its easy to write it the way you did in the first example because there are only edges and faces that that have vertices. But what if there were 30 different types of objects that did? That would be hard to be all inclusive. So I like the idea that there is no need to specifiy each class separately, since its really not the edge or face we care about. Its if the "e" in question has vertices attached. Interesting. I'll be thinking baout that as I keep working....

                      Chris

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

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by 28 Apr 2009, 16:46

                        πŸ‘ πŸ‘

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        1 / 1
                        • First post
                          1/11
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement