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

    GMSH exporter

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 6 Posters 2.9k 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      (6) The Ruby += operator is very slow for strings.

      This is because the Ruby interpreter changes a += b to a = a + b, and causes Ruby to create temporary String instance objects.

      Example:
      str =+ "};" + newline
      Ruby first has to call (internally,) String.new() for the literal value "};" (the 1st,) so it can then access that new String object's +() method, which always creates a new String object (the 2nd, again internally calling String.new,) containing the value = "};\n"
      AT this point (internally,) the expression is now:
      str = str + "};\n"
      Now Ruby has to call the instance method +() for the str object, passing the internal ref for "};\n" as the argument. And as explained above, +() always creates a new String instance object, so this is the 3rd.
      Lastly, Ruby has to make a reference re-assignment, assigning str to point at the 3rd new string object's internal reference, which now becomes non-internal.

      Instead: use the String classes' <<() "append" method, which can be chained, as it always returns the reference to it's receiver (ie, the original object.)
      So:
      str =+ "};" + newline
      ... which forces the creation of 3 new String objects and a reference re-assignment for str, can become ...
      str << "};" << newline
      ... which only creates 1 new String object (for the literal quoted expression,) and NO reference re-assignment for str

      Speed optimization is especially important in loops.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • bomastudioB Offline
        bomastudio
        last edited by

        Hi Dan, thank you for all the suggestion!!! πŸ˜„ Very, very usefull!! I'll made all the corrections as soon as possibile.
        What about the loop? Any solution? πŸ˜„

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          I'm not sure which will be more helpful, but play around with Face.outer_loop and Face.loops.

          https://developers.google.com/sketchup/docs/ourdoc/face

          Outer look should return just the outer loop around a face. Loops should return an array of loops that bound the face, meaning if there are holes in the face, it will return the loop around those holes. It looked like gmsh didn't want faves with holes though. So you might triangulate your model first to get rid of holes in faces. Or I suppose you could just triangulate faces with holes in them?

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

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            Though I guess if you're using the quicker polygon mesh then the standard sketchup face loop might not help? I'm not too sure how that would all interact.

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

            1 Reply Last reply Reply Quote 0
            • bomastudioB Offline
              bomastudio
              last edited by

              Ok. Now I'm working with the mesh. But the problem of the ordering, as GMSH needs, the edges of the mesh is still pending..... can you suggest how to solve? 😳 😳

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

                Face.outer_loop.edges returns the edges in ccw order: edges have .start and .end vertices, .length and .line [start+vector] etc...
                Face.outer_loop.vertices is similar for vertices - pt=vertex.position gives a Point3d and apt=pt.to_a returns an [x,y,z] array.
                If your file format needs YZ flipping adjust the array into [x,-z,y] to solve this...
                Point coordinates are in always inches [irrespective of the model's units] BUT these can be converted to other unit formats - e.g. .to_m. To make the 'number' into a string use .to_s on it...

                TIG

                1 Reply Last reply Reply Quote 0
                • Chris FullmerC Offline
                  Chris Fullmer
                  last edited by

                  If he's already got his mesh put together, would it make sense to use that object to then write all the vertices? Something like this will display them to your console for testing. the mesh I use in the first line is your mesh object.

                  mesh.polygons.each_with_index do |e,index|
                   unless e==nil
                    puts ""
                    puts "Face #{(index+1).to_s}"
                    e.each_with_index do |pt, index2|
                     puts "Vert# #{pt.to_s} - " + mesh.polygon_points_at(index+1)[index2].to_s
                    end
                   end
                  
                  end
                  

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

                  1 Reply Last reply Reply Quote 0
                  • bomastudioB Offline
                    bomastudio
                    last edited by

                    Hi guys
                    I'm returning on this plugin. I added the license (GLP2), so it's open source 😍

                    Do you think it is a good idea to map the nodes with a Dictionary? As in IGES_EXPORT plugin http://sketchucation.com/forums/viewtopic.php?f=323&t=43307&hilit=iges?


                    su2gmsh.rb

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Djskippy
                      last edited by

                      Hi Bomastudio,

                      Some time ago I've written an export script from Sketchup to Gmsh.

                      Sketchup Groups are exported as Volumes in Gmsh
                      Sketchup Faces are exported as plane surfaces in Gmsh
                      Sketchup Edges are exported as lines in Gmsh
                      Sketchup Vertices are exported as points in Gmsh

                      The script handles nested groups and applies all transformations to the points in Gmsh
                      Inner faces are exported correctly.
                      It even exports text entered in Sketchup (not 3D text).

                      The only thing this script doesn't do is: Export circles and arc's as Gmsh circles, it now just exports them as lines and points (that's how Sketchup see's them).
                      To correct this you'll need to take a look a IGES_EXPORT and how it exports circles, cylinders and cones.


                      Gmsh Export script for Sketchup

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

                        Thanks for posting this! When opening the .geo file in gmsh, visually everything looks correct, but gmsh lists errors when reading the line loops.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Djskippy
                          last edited by

                          @jsgodwin said:

                          Thanks for posting this! When opening the .geo file in gmsh, visually everything looks correct, but gmsh lists errors when reading the line loops.

                          You could give my exporter a try, the line loops are exported correctly.

                          1 Reply Last reply Reply Quote 0
                          • bomastudioB Offline
                            bomastudio
                            last edited by

                            @djskippy said:

                            Hi Bomastudio,

                            Some time ago I've written an export script from Sketchup to Gmsh.

                            Sketchup Groups are exported as Volumes in Gmsh
                            Sketchup Faces are exported as plane surfaces in Gmsh
                            Sketchup Edges are exported as lines in Gmsh
                            Sketchup Vertices are exported as points in Gmsh

                            The script handles nested groups and applies all transformations to the points in Gmsh
                            Inner faces are exported correctly.
                            It even exports text entered in Sketchup (not 3D text).

                            The only thing this script doesn't do is: Export circles and arc's as Gmsh circles, it now just exports them as lines and points (that's how Sketchup see's them).
                            To correct this you'll need to take a look a IGES_EXPORT and how it exports circles, cylinders and cones.

                            😍 😍 Thanks!!!!! I was looking for this plugin for a long long time!!!!

                            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