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

    Reading the SU API

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 5 Posters 601 Views 5 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      OK, is this the correct way to find all components (including nested ones) in the model?

      
      model = Sketchup.active_model
      
      model.definitions.each do |c|
        puts "Component; #{c.name}"
      end
      
      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        That is showing all the component definitions, in the model. Including nested definitions.

        Is that what you are trying to do? Or do you want a list that includes every isntance of each definition too? For that do:

        model = Sketchup.active_model
        
        model.definitions.each do |c|
          c.instances.each do |ins|
            puts "Component; #{ins}"
          end
        end
        

        Chris

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

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          OK, is this right?

          
          model = Sketchup.active_model
          
          model.definitions.each do |c|
            c.instances.each do |s|
              puts "Component; #{c.name} #{s.transformation.origin.to_s}"
            end
          end
          

          My output (Box03 inside Box01):
          %(#BF0000)[Component: Box02 (106.466771", -5.289104", 0")
          Component: Box03 (11.477469", 39.803972", 6.9375")
          Component: Box01 (0", 0", 0")]

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            Understood:-)
            %(#BF0000)[106.466771389033
            -5.28910358007033
            6.57113252700015e-015
            11.4774687529651
            39.8039723918033
            6.93750000000001
            0.0
            0.0
            0.0]

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

              The [to_s](http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#to_s) method is appropriate for printing a Point3d. You can't just print an Array and have it come out reasonably.

              Hi

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                ....s.transformation.origin.to_a....
                

                origin is a 3D-point - alternatively would return an array like [0,0,0] which you can use as a point or take xyz values

                TIG

                1 Reply Last reply Reply Quote 0
                • honoluludesktopH Offline
                  honoluludesktop
                  last edited by

                  Understood:-) Can you mix strings, and numbers in a array without having to change them (to_s or to_f) later? If so is it efficient?

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    Things like a 3d-point can be made into an array using to_a - these are then all floats [0.0,1.2,3.4]
                    An array can be made thus
                    array=[]
                    array[0]=1
                    array[1]=2.3
                    array[2]="Cat"
                    array[3]=nil
                    array.push([1,2,3,4])
                    array<<true
                    my_variable=123456789
                    array=array+[my_variable]
                    so array >>> [1,2.3,"Cat",nil,[1,2,3,4],true,myvaraible]
                    i.e. an integer, a float, a string, nil, an array, a boolean and a variable's value.
                    Individual items can be changed thus array[5]=false changes the boolean value
                    arrays can be sorted, added, subtracted, reversed, compacted, flattened, made_unique etc etc - they are very useful!

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • honoluludesktopH Offline
                      honoluludesktop
                      last edited by

                      Thanks!-) Think, I learned a lot of "stuff" in the past few days. Think I'll go back a couple of weeks, and see if I can better comprehend those posts:-)

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

                        @honoluludesktop said:

                        ... If so is it efficient?

                        Twentieth century issue.

                        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                        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