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

    Trying to improve the speed of a simple script

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 344 Views 4 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.
    • J Offline
      Jackjack123
      last edited by

      Hi. I have a very basic ruby script I have been playing with in sketchup. I read a text file with four values separated by spaces. They represent an x, y, z coordinate followed by a forth number (which represents a height). This text file can have many of these points/height values (all on separate lines). At each point I draw a shape by calculating out 3 other corners as P2, P3 and P4 then doing the following:

      face = entities.add_face pt1, pt2, pt3, pt4
      face.pushpull (height), true

      It is a very simple script. I am finding that as I add more lines to the file it takes a much longer time for each file to process (so the relationship appears not to be linearly related to the length of the file).

      I believe this is because every time I use pushpull, sketchup is checking to see if the new shape intersects existing geometry (which increases each time the loop runs through the file).

      If there was a way of either stopping this geometry check (or delaying it until all of the boxes have been built...) I bet that would do it. I’m a fairly novice programmer so Ruby is a bit out of my league but I am managing.

      Can anyone think of a way I could speed this up?

      1 Reply Last reply Reply Quote 0
      • chrisglasierC Offline
        chrisglasier
        last edited by

        Yes I too would be interested in the answers to that, as I am also into generating geometry.

        I understand that to stop geometry intersecting (sticking) you make each a group. So this might stop the checking process. But I don't know for sure.

        Chris

        With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

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

          Thanks for the reply and the interesting idea. Like I said I am a novice at this so I'm not sure how, but maybe someone can think of a simple line or two I could add before the loop repeats that would add the newest geometry into an existing group. Than each time the loop goes through it will continuously add that ever is new into that same group.

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Haven't used the class myself; but the manual indicate it's a faster method to build geometry.
            http://code.google.com/apis/sketchup/docs/ourdoc/polygonmesh.html

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • chrisglasierC Offline
              chrisglasier
              last edited by

              @jackjack123 said:

              Thanks for the reply and the interesting idea. Like I said I am a novice at this so I'm not sure how, but maybe someone can think of a simple line or two I could add before the loop repeats that would add the newest geometry into an existing group. Than each time the loop goes through it will continuously add that ever is new into that same group.

              Here is some code Jim helped me with. It generates boxes from data from an html file in a web dialog.

              
              @dlg.add_action_callback("drawer") {|d, p|
              
              model = Sketchup.active_model
              entities = model.entities
              
              group = entities.add_group
              entities = group.entities
              
              a= p.split(",")
              	
              	
              theX = Integer(a[0]).mm
              theY = Integer(a[1]).mm
              theZ = Integer(a[2]).mm
              	
              point = Geom;;Point3d.new theX, theY, theZ
              t = Geom;;Transformation.new point
              		
              #for faces
              theW	= Integer(a[3]).mm
              theD =  Integer(a[4]).mm
              theH = Integer(a[5]).mm
              	
              pts = []
              pts[0] = [0, 0, 0]
              pts[1] = [theW, 0, 0]
              pts[2] = [theW, theD, 0]
              pts[3] = [0, theD, 0]
              	
              base = entities.add_face pts
              	
              height = -theH
              	
              base.pushpull height
              
              group = group.move! t   }
              
              
              

              Chris

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • C Offline
                cjthompson
                last edited by

                I found that creating geometry inside of a group, and then exploding it handle at least a little bit faster than creating it by itself.

                hopefully this is kind of what you had in mind:

                
                def constructRectangle(x,y,z,height)
                  model = Sketchup.active_model
                  entities = model.entities
                  group = entities.add_group
                  face = group.entities.add_face([0,0,0],[x,0,0],[x,y,0],[0,y,0])
                  face.pushpull(height)
                  group.explode
                end
                
                
                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  Did you try to use PolygonMesh?

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  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