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

    Full ruby installer

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 3 Posters 1.4k Views 3 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.
    • R Offline
      ruggiero.guida
      last edited by

      Hi.

      I am using SketchUp 2014. I would like to test YAML and JSON. I have tried to add require at the beginning of the program, but that doesn't seem to work. Maybe I am missing something?

      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        Can you elaborate on "doesn't work"? Error messages?
        Also are you using the M0 release or M1?
        In M0 there was a bug where parts of the Ruby lib wasn't loaded if SketchUp was launched by an SKP file or shortcut that wasn't on the same drive as where SketchUp was installed.

        2014-07-16_16h10_36.png

        1 Reply Last reply Reply Quote 0
        • R Offline
          ruggiero.guida
          last edited by

          Hi there. Apologies for wasting your time. I just realized that I had commented all the requires because of a previous problem.

          Too many late nights and weekends trying to finish this project on time!

          The 'doesn't work' meant that I received the error

          Error: #<NoMethodError: undefined method `to_yaml' for #Array:0xe3023f8>

          Now I am trying to figure out how to dump an array of objects recursively. JSON only saves references to the objects, but YAML seems to work.

          Thanks again

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            Sketchup API classes themselves are not extended with to_yaml or to_json methods !

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • R Offline
              ruggiero.guida
              last edited by

              Thanks. That explains it.

              This is an extract of the json I have produced by using .to_yaml on the array of Point_SVF objects.

              ` !ruby/object:Point_SVF
              grid_node: !ruby/object:Geom::Point3d {}
              svf_array:

              • !ruby/object:Ray
                vector: !ruby/object:Geom::Vector3d {}
                shaded: false
                solid_angle: 0.022817320094517073
              • !ruby/object:Ray
                vector: !ruby/object:Geom::Vector3d {}
                shaded: false
                solid_angle: 0.022817320094517073`

              Because this is just a string, it doesn't make sense to try to parse it back so it is of no use

              I have then tried to redefine the to_yaml method in my object, but it doesn't make any difference in the output.

              This is my object

              ` class Point_SVF
              attr_accessor :grid_node # This is the node on the grid - Point3D
              attr_accessor :svf_array # This is a Ray object
              def to_yaml
              "Coords: "+ self.grid_node.x.to_s + "," + self.grid_node.y.to_s + "," + self.grid_node.x.to_s
              end

              end`

              Calculations take even an hour and I am trying several shading options. I would like to be able to save my shading file (array of Point_SVF) and then just re-use it

              It would be great if you could point me in the right direction.

              Cheers

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @ruggiero.guida said:

                With my ruby script I am starting to create very big objects that require several minutes to be created.

                How are you creating these objects? Entities.add_face (very slow) or Entities.fill_from_mesh (fastest)

                Also, can you provide examples of what you are generating? Or even a code snippet?

                1 Reply Last reply Reply Quote 0
                • R Offline
                  ruggiero.guida
                  last edited by

                  Hi,

                  I'll give you a bit of background.

                  I am working on a outdoor comfort analysis for a new development.

                  I do not use Sketchup for visualization. I am using SketchUp to calculate the solar radiation for each point of a computational grid. The grid is fixed as it is imported from the CFD wind analysis. The surroundings are the 3D models of the buildings provided by the architects.

                  SketchUp is great because it has lots of geometry operations embedded and easily accessible. And they are so fast! I use especially the raytest to check if a point is shaded or not.

                  Now, for each point of the grid (ca 3000) I cast several rays to cover the sky. For each one of this ray I need to know if it is shaded, if not, how much radiation receives and which surface, if any, it intersects.

                  I have an object that represent the node of the grid.

                  class Point_SVF attr_accessor :grid_node # This is the node on the grid - Point3D attr_accessor :svf_array # This is an array of Rays objects def to_yaml "Coords: "+ self.grid_node.to_s#x.to_s + "," + self.grid_node.y.to_s + "," + self.grid_node.x.to_s end end

                  The Ray object is used to store some info on the particular direction for that specific node.

                  class Ray attr_accessor :vector #Vector3D object attr_accessor :shaded attr_accessor :solid_angle attr_accessor :transparency #Transparency of the FIRST intercepted surface attr_accessor :temperature #temperature of the FIRST intercepted surface end

                  You can imagine that it can take a while to perform the analysis and the objects get quite big (SU sometime crashes).

                  Also I need to test various shading scenario that will affect only some of the rays and I don't want to re-rerun the whole simulation all the time.

                  That is where the serialization comes in. I would like to be able to serialize the array of Point_SVF objects. This array practically describes the whole geometry and it changes only partially when I test local shading.

                  This is where I am stuck.

                  Hope this gives a bit more context. πŸ˜„

                  1 Reply Last reply Reply Quote 0
                  • tt_suT Offline
                    tt_su
                    last edited by

                    Ah, it's the calculation actually being slow?
                    In which case I would suggest using a Ruby C++ Extension to do that. You would call the Ruby API to get data from the SketchUp model - but you can compute and manage your data in more efficient C++. We have a GitHub repo with a Hello World example to get people started: https://github.com/SketchUp/ruby-c-extension-examples

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      ruggiero.guida
                      last edited by

                      eh that would be good!

                      The speed is not an issue. I know that C++ would be better, but I don't know it and I really can't learn it in a week!! πŸ˜„ Maybe for the next project.

                      Just one question. Is it possible in principle to serialize an object that contains various SketchUp specific classes? Like the object I have? This would solve all my problems.

                      Thanks for your help. It's cool that the SketchUp developers get involved in this forum to help people.

                      We are doing lots of stuff in my company with SketchUp from Openstudio to Daysim and various other simulations. In my team I am using SketchUp as the main modelling tool. A kind of repository for the geometries and then we export to the various simulation tools we use.

                      1 Reply Last reply Reply Quote 0
                      • tt_suT Offline
                        tt_su
                        last edited by

                        You cannot serialize Entity derived objects. I cannot recall what the case about Point3d and Vector3d is right now. I'd have to check.

                        You might find it easier to convert Point3d and Vector3d objects into arrays. SketchUp add's a few utility methods to the Array class which allow you to treat Array's as Point3d or Vector3d.

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          ruggiero.guida
                          last edited by

                          Thanks a lot for the advice! I will try it out today.

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            ruggiero.guida
                            last edited by

                            It worked beatifully.

                            The only thing I had to change was a line of code where I use 'angle_between'. I just created a temporary Vector3D and solved the issue.

                            I had to switch to Marshal because files were getting too big (180MB) and it was taking 15 minutes just to save.

                            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