Add_edges with a LOT of edges
-
Hey at all!
I'm coding a plugin, which can import GCode from a textfile, means simple x / y / z coordinates.
Now, I would like to display the path of the milling tool. So, I collected all points in an array and wrotepoints << [xOld.to_f.mm, yOld.to_f.mm, zOld.to_f.mm] entities = Sketchup.active_model.entities curve = entities.add_edges points
The result is very strange...
So, it seams, that a lot of edges are missing.
When I use add_curve, it takes a looooong time to show the result and there are some other strange mistakes, but especialy in this region, the "path" of the milling tool looks good. So I don't think, it is a problem of my textfile.
Do you have an idea, what happens here?
Thank you very much for your help!
-
It may be that the points are so close together that a very tiny edge would result.
There is a known limitation of tiny edge/facet creation [~0.1mm ?] smaller lines will fail to form.
If you test for the equivalent of the points as you add them to the array this might avoid the error... Make the array as a Point3d...
Assuming this happens in an iteration block{}
etc...point = Geom;;Point3d.new(xOld.to_f.mm, yOld.to_f.mm, zOld.to_f.mm) points << point if not point==points[-1]
This ensures that the distance between the two points is sufficient for SketchUp to consider them as not being the same point and thereby greatly improves the chances of a small line actually getting made!
-
@tig said:
There is a known limitation of tiny edge/facet creation [~0.1mm ?] smaller lines will fail to form.
Oh shit, you are right! That's exactly the problem... all missing lines are smaller than 0.1 mm. The problem is, I have to display these small edges, because I need this "smooth" curvature.
Puh, is there a possibility to change this limitation of about 0.1 mm?
Thanks TIG for your fast answer!!!
-
Okay, I found a solution:
http://productforums.google.com/forum/#!category-topic/sketchup/sketchup-pro/2516_Hg65VU
They said: I have to enlarge the model to 1000x... insert all the points and scale them back after that... What do you think?
-
I tried to scale this points at first...
` points << [(xOld.to_f10000).mm, (yOld.to_f10000).mm, (zOld.to_f*10000).mm]
group = Sketchup.active_model.entities.add_group
group.entities.add_edges pointsnew_transform = Geom::Transformation.scaling 0.0001
group.transformation = new_transform`And, oh my goodness, it works!
Thanks TIG again for your hints!!!
-
I very glad you solved your own problem - and shared a solution, so that others might benefit - that's what SCF is about.
Scaling everything up as you make the points/lines, then scaling down at the end... was going to be my next suggestion - but you got there by yourself!
-
I have to push this topic again to the top...
I would like to present my current code, to import some gCode...
` points = Array.new;
while (...)
points << [(xOld.to_f1000).mm, (yOld.to_f1000).mm, (zOld.to_f*1000).mm]
endgroup = entity.entities.add_group
group.entities.add_edges pointsnew_transform = Geom::Transformation.scaling 0.001
group.transformation = new_transform`I'm not realy happy with this method. Sometimes, I have to import 80.000 points and more. So, it takes a loooooooong time, to import this... I tried, to scale just the small points, but it takes exacly the same time...
Do you have an idea, how I can accelerate this gCode importing?
Thanks again for all your help!
-
You could at least try to read data and process in one go ? ...
points=[] IO.readlines(pathtoxyztextfile).each{|line| xyz=line.chomp.split(",") ### assuming file is comma separated data next unless xyz.length==3 ### i.e. [x, y, z] points<<Geom::Point3d.new((xyz[0].to_f*1000).mm, (xyz[1].to_f*1000).mm, (xyz[2].to_f*1000).mm) }
then add edges into a new group, from the points, much as your code...
group=model.active_entities.add_group() group.entities.add_edges(points)
then rescale the group's geometry, NOT the group itself...
tr=Geom::Transformation.scaling(0.001) group.entities.transform_entities(tr, group.entities.to_a)
-
Thanks TIG for your ideas! I tried it several times, to get a statistical result... but there is no time difference between group transforming and entities transforming.
However, I think, there is no chance to decrease the calculation time...
Thanks a again! I could not improve the code, but I learned again a lot...
-
@tig said:
then rescale the group's geometry, NOT the group itself...
tr=Geom::Transformation.scaling(0.001) group.entities.transform_entities(tr, group.entities.to_a)
Then you make the edges smaller than 1mm - if you try to work with that geometry you might summon critters of dark dimensions.
-
Yes.... but...
Small edges can exist quite happily, it's just using them that is problematical.
So if he has completed all changes/processing, then I believe that rescaling the geometry is best, but if further changes are wanted then any [re]scaling needs to be avoided until all processing is done anyway...
Advertisement