Trying to improve the speed of a simple script
-
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), trueIt 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?
-
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
-
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.
-
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 -
@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
-
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
-
Did you try to use PolygonMesh?
Advertisement