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

    [New scripter] Will need help on my project (now and then)

    Scheduled Pinned Locked Moved Developers' Forum
    21 Posts 6 Posters 1.6k Views 6 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
      slbaumgartner
      last edited by

      @ruts said:

      But I just want to know why I can use the Matrix class in powershell and not in SketchUp. I'm think it has someting to do with my older version of SketchUp (8)?

      That is highly likely, as the Ruby interpreter is complaining about incorrect syntax in the matrix.rb file. SketchUp 8 uses an obsolete version of Ruby (1.8) and does not include the standard Ruby libraries. Depending on where you copied the matrix.rb file from, that could lead to incompatibilities. This begs the question: why not upgrade to the latest SketchUp Make 2015, which uses Ruby 2.0 and includes standard libraries such as matrix?

      1 Reply Last reply Reply Quote 0
      • R Offline
        Ruts
        last edited by

        When I create shapes in Sketchup and start rotating and moving them my code is perfectly able to calculate the new position of the shape. The calulations are made by using the dimensions of the original bounding box and the transformation matrix.

        Everything goes fine, until I start scaling the shape. In order to understand what goes wrong when I scale an object I did some scaling on easy shapes. The matching transformation matrices with the shapes gave results that did not make any sense for me. Here's one of the tests I did:

        First I did create a box with begin coordinates (0,0,0) and width(X)/length(Y)/height(Z) (20,20,20). Next I scaled the box with value 2 in negative x-direction. This gave me a box with begin coordinates (-20,0,0) and W/L/H (40,20,20). This is the matching transformation matrix

        [2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -20, 0.0, 0.0, 1.0]
        

        The matrix makes perfect sense for this example.

        For my next example I did create a box with begin coordinates (40,40,40) and W/L/H (20,20,20). Once again I scaled the shape with value 2 in negative x-direction. This gives a box with begin coordinates (20,40,40) and W/L/H (40,20,20). This is the matching transformation matrix

        [2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -60, 0.0, 0.0, 1.0]
        

        I can't find any reasonable explanation for the -60. I think it would be -20 as the other box.

        Can someone explain me how this is possible?

        1 Reply Last reply Reply Quote 0
        • R Offline
          Ruts
          last edited by

          @slbaumgartner said:

          This begs the question: why not upgrade to the latest SketchUp Make 2015, which uses Ruby 2.0 and includes standard libraries such as matrix?

          I use the software provided by the company I work for. I can ask if they don't have any keys for a more recent version, but I doubt it.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            You are scaling from the ORIGIN in both cases?

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • R Offline
              Ruts
              last edited by

              @sdmitch said:

              You are scaling from the ORIGIN in both cases?

              My excuses if it's a common thing to know, but I don't know exactly what you mean by 'scaling from the origin'.

              I did create both boxes which are created as groups. Next I scaled them 'Red Scale about Opposite Point' with the Scale tool in negative x-direction (scaling factor 2).

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

                There are several potential arguments to a scaling transformation.
                http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation#scaling
                If you simply give the 'scale-factor[s]' it assumes the ORIGIN.
                The first argument is taken as a point if 2 or 4 arguments are passed.
                t = Geom::Transformation.scaling(scale) t = Geom::Transformation.scaling(xscale, yscale, zscale) t = Geom::Transformation.scaling(point, scale) t = Geom::Transformation.scaling(point, xscale, yscale, zscale)

                TIG

                1 Reply Last reply Reply Quote 0
                • R Offline
                  Ruts
                  last edited by

                  How do I avoid rounding when using the Point3d.[] or Point3d.x/y/z methods?

                  Here's an example where I experience the problem. I have 3 Point3d's that are part of a line:

                  • edge_start = (-29,389263mm, 0mm, -40,45085mm)* edge_end = (-40,45085mm, 0mm, -29,389263mm) * intersection = (-40,458747mm, 0mm, -29,381365mm)

                  I want to run a piece of code if the intersection is on the edge. I have an if-statement that should work, but it fails when two points are close by because of the rounding of the Point3d.[] and Point3d.x/y/z methods.

                  edge_end.x should be greater then intersection.x, but it rounds edge_end.x to ~-40.5mm and also intersection.x to ~-40.5mm. This makes the variables equal to eachother.

                  How do I compare the x values of a Point3d without losing the precision?

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    Sketchup uses an internal precision of 0.001 or so. So any time you create a Point3d object values gets rounded to that.

                    So Ive seen some workarounds:

                    An idea is to use arrays instead of Point3d objects and do the bulk calculation in Ruby or C/C++.

                    Should you need Point3d objects for display, create them lastly before adding entities to the model. You can still get the x values from Point3D by pt[0] for ex. So no need to rewrite arguments.

                    Obviously you can't use Sketchup API methods that need Point3d objects during the calculations then, but it sounds like you are using your own intersection algorithm(?).

                    If not then an alternative is to scale up the whole piece you are working with. And when done scale down to original size.

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      Ruts
                      last edited by

                      @unknownuser said:

                      It sounds like you are using your own intersection algorithm(?)

                      The intersection of the lines is calculated with the Geom.intersect_line_line method. Next I use my own calculations to see if the edges on these lines also intersect.

                      The problem is solved by using arrays, thanks for your help.

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

                        @ruts said:

                        In my calculations ... I want to use the base ruby class Matrix which is made for such operations. I found out that it's not just adding require 'matrix' to your code.

                        Because SketchUp was not distributed with the Ruby Standard Library until version 2014.

                        @ruts said:

                        I did copy the matrix.rb and e2mmap.rb (which is required by matrix.rb) from the ruby2.2.2 folder ...

                        This will not work, as you need to use the library compiled and distributed with the Ruby version that SketchUp uses. The constants RUBY_VERSION and RUBY_PATCHLEVEL typed at the console tell you what SketchUp embedded Ruby is.

                        @ruts said:

                        ... I believe this is the right way to require 'matrix'.

                        Nope (when the standard library is properly installed,) just a simple require 'matrix' will do (because it will load it's own dependencies as it is evaluated.)

                        @ruts said:

                        I think I already have a solution for my problem.

                        NO you don't, because you "don't have time to read the book," all this basic Ruby 101 knowledge is escaping you.

                        So just go to my GitHub repo and get the Standard Ruby 1.8.6-p287 Library packaged for SketchUp 2013 and earlier on Windows ONLY.
                        https://github.com/DanRathbun/sketchup-ruby186-stdlib-extension/releases/tag/2

                        With SketchUp closed:
                        (1) Put the RBZ archive someplace where you can navigate easily to it.
                        (2) Delete any manually copied library files (such as those you mentioned copying above.)
                        (3) Then start SketchUp 8 and use the manual "Install Extension ..." button from
                        Window > Preferences > Extensions
                        (3a) Navigate to where you saved the RBZ archive, and select it, click OK.

                        (4) Open the console and test that the paths are correctly set in $LOAD_PATH (aka $:) by typing:
                        puts $: and ENTER
                        You should see a listing similar to:
                        puts $:%(green)[C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins C:/Program Files (x86)/SketchUp/SketchUp 8/Tools C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/1.8 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/1.8/i386-mswin32 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/site_ruby/1.8 C:/Program Files (x86)/SketchUp/SketchUp 8/Plugins/Ruby186/lib/ruby/site_ruby/1.8/i386-msvcrt]nil

                        The actual program files path might also look like:
                        %(green)[C:/Program Files (x86)/Google/Google SketchUp 8/...]

                        (5) Then further test the loading of "matrix.rb" via:
                        require "matrix"
                        You should see true returned.

                        I'm not here much anymore.

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

                        Advertisement