Hi. I am reading lines from a simple file. That works ok, as i created messages to Sketchup.set_status_text to be sure what`s going on. But, when i actually create the lines from the array, the program freezes. It freeze only above 30k lines more or less.
This is the loop in which the problem occurs:
for c in 1…$edges_count
this_edge = edges_array[c - 1]
new_model.active_layer = this_edge
First of all. Generally in SketchUp, all geometric primitives (faces, edges, arcs, polygons) should be associated with “Layer0”. Only group and component instance containers should be associated with other layers. (ie, layers are not geometric containers in SketchUp. Only groups and component instances separate geometry.)
2.) Coding questions go in the forum’s Developers > Ruby API subcategory.
(Admins have reassigned to correct category.)
Thats exactly the way it is written. But still will freeze. In fact, it appears the rotating wheel of death, but i discovered that, for example, for 200.000 lines, it took half and hour and finally made it, so it was not freezed, it was working and being extremely slow. (1 second for 20k lines, 30 minutes for 200k lines). After reading the posts related to my issue i see that ruby gets slow for this kind of issues. I would like to know if this is normal, the time used, and if i should redirect my efforts into trying the program not to show the wheel (which reading also is difficult), or if there is something im missing. I`m surprised because this is a super basic task, (adding edges). Any other ideas? thank you so much for your responses.
Don’t be surprised. The more edges you add into a geometry context, the more work SketchUp must do to check if there are any edge or face intersections. With each edge added, the entities collection gets bigger, making the intersection check longer and longer.
SketchUp is unique from CAD in that it has “sticky” geometry, so each time you add a face or edges, SketchUp must check if they will intersect any current geometry.
You might try creating a group or component, and adding edges to that instead of the model’s main entities collection.
Create Geom::Point3d objects instead of arrays with numeric values for your vertices used for making the edges.
Or use the Geom::PolygonMesh helper class.
Also, I did not notice before but do not use $var as they are global and can clash.
ALL of your code should be wrapped within your own namespace module. So use either a module var @@var or a instance @var for persistent references.
You can simplify the loop somewhat …
(to eliminate the unneeded Range object and assignment using a math expression) …
for this_edge in edges_array