SketchUcation Plugin Store

 

 

erase_entitiies crashing SU 8

Welcome! Ask and get answered - or just introduce yourself.

erase_entitiies crashing SU 8

Postby timwarner » Sun May 13, 2012 11:26 pm

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
 
Posts: 20
Joined: Wed Dec 09, 2009 2:08 am
Name: Tim Warner

Re: erase_entitiies crashing SU 8

Postby sdmitch » Mon May 14, 2012 3:04 am

timwarner wrote: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
Code: Select all
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.
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch
 
Posts: 617
Joined: Wed Mar 02, 2011 9:21 pm
Name: Sam
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: hobby
Level of SketchUp: Beginner

Re: erase_entitiies crashing SU 8

Postby TIG » Mon May 14, 2012 12:35 pm

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)
TIG
User avatar
TIG
Global Moderator
 
Posts: 13903
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: erase_entitiies crashing SU 8

Postby timwarner » Mon May 14, 2012 2:44 pm

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
timwarner
 
Posts: 20
Joined: Wed Dec 09, 2009 2:08 am
Name: Tim Warner

Re: erase_entitiies crashing SU 8

Postby TIG » Mon May 14, 2012 5:12 pm

You can only erase a Drawingelement.
Although a vertex is treated as an 'entity' for bulk changes with code like ents.transformation_entities(vertices) etc it cannot be erased in code.
However you can do something like vertices.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.
TIG
User avatar
TIG
Global Moderator
 
Posts: 13903
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: erase_entitiies crashing SU 8

Postby timwarner » Mon May 14, 2012 11:25 pm

Thx ..my carelessness in thinking a vertex was a drawing element! .../T
timwarner
 
Posts: 20
Joined: Wed Dec 09, 2009 2:08 am
Name: Tim Warner

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.

Ad Machine
Robot
 
Posts: 2012



 

Return to Newbie Forum

Who is online

Users browsing this forum: gumppy and 2 guests