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

    New API Object Diagram

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 8 Posters 657 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.
    • scottliningerS Offline
      scottlininger
      last edited by

      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

        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

          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
          • scottliningerS Offline
            scottlininger
            last edited by

            @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

              Thanks Simone!!!

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by

                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

                  @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

                    Ok, thank you Rick!

                    Frenglish at its best !
                    My scripts

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

                      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

                        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

                          πŸ‘ πŸ‘

                          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
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement