sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    GMSH exporter

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 6 Posters 3.0k 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

      OK...

      (1) It is a no-no to change the Ruby base classes! (Yes we know that the round method was added in later versions of Ruby, but every author cannot be changing base classes. Either users should use ONE Ruby backport extension, ... or you should be using a custom Float subclass WITHIN your OWN namespace.)

      (2) Your code is not wrapped within your OWN namespace modules(s). (The instance variables in your code belong to Object so are really global instance variables, and is also not nice.)

      • Choose a toplevel namespace such as: module Boma* Choose a sub-namespace such as: module Boma::Gmsh

      (3) You are creating an undo operation, BUT:

      • You are not making any changes to the model, so there will be nothing to actually "Undo."* File write operations cannot be undone with SketchUp's undo command. You would need to write a command that erases the file using Ruby's File.delete() method.

      (4) I did a search through your code.. and did not find " Geom::PolygonMesh" nor " .mesh", which means you are not leveraging the power and speed of a virtual memory mesh. Read up on the Geom::PolygonMesh and the Face.mesh() method.

      Example... you have a mesh object in memory exmesh that will be the mesh to export. You have a face in the model, whose mesh you wish to add to exmesh:
      exmesh = Geom::PolygonMesh.new()
      .. and later (probably with in loop, iterated an Array of Sketchup::Face objects.):
      exmesh.add_polygon( face.mesh.polygons )

      (5) Ruby is an English programming language, it is easier to help with your code, if you publish using English var and method names. (A search and replace macro run in your editor.)

      Just a few ideas.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • 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