Erase_entitiies crashing SU 8
-
I have a piece of code that crashes SU 8 (on a Mac).
Basically the idea is to create an instance of a component, find the positions of its vertices and then erase the instance. The instance is created correctly; the vertices are correctly printed, but then SU dies. Here's the code fragment, where ents is model entities.
brace_template = ents.add_instance(brace.definition,brace_transformation) bte = brace_template.explode vertices = bte.select{|e| e.typename == "Vertex"} puts "Brace coordinates" vertices.each{|v| puts v.position} ents.erase_entities(bte)
Any ideas why this is happening?
-
@timwarner said:
I have a piece of code that crashes SU 8 (on a Mac).
Basically the idea is to create an instance of a component, find the positions of its vertices and then erase the instance. The instance is created correctly; the vertices are correctly printed, but then SU dies. Here's the code fragment, where ents is model entities.
brace_template = ents.add_instance(brace.definition,brace_transformation) bte = brace_template.explode vertices = bte.select{|e| e.typename == "Vertex"} puts "Brace coordinates" vertices.each{|v| puts v.position} ents.erase_entities(bte)
Any ideas why this is happening?
There are things in bte other than valid drawing elements. The same thing happens if you try to delete a curve rather than the edges that make up the curve.
Replace ents.erase_entities(bte) with
bte.each{|e| e.erase! if e.valid? && e.is_a?(Sketchup;;Drawingelement)}
This worked for me in Windows and hopefully will work on a Mac also.
-
The
...erase! if...
method will work, but it can be slow if there are many entities after the explode - this might be quicker to have this at the end
bte.each{|e|bte.delete(e) unless e.is_a?(Sketchup::Drawingelement)} ents.erase_entities(bte)
-
Thank you, people. This works. I'm still a bit confused about the issue of drawing elements, because when I tried deleting the vertices entity collection (which would have the effect of removing the whole component instance) SU still crashed. But the vertices object only contains vertices.
Tim
-
You can only erase a Drawingelement.
Although a vertex is treated as an 'entity' for bulk changes with code likeents.transformation_entities(vertices)
etc it cannot be erased in code.
However you can do something likevertices.each{|v|ents.erase_entities(v.edges) if v.valid?}
which has the same outcome, because if you could erase a vertex then its edges would vanish, as would those edges' faces etc...Presumably you understand that when you get an array returned with an explode, that array is not just Drawingelements, but includes vertices/loops/etc which cannot be 'erased', and thereby this caused you crash issues, so parsing that array to be just Drawingelements ensures such problems are avoided.
-
Thx ..my carelessness in thinking a vertex was a drawing element! .../T
Advertisement