How to delete a model imported from *.dae file by ruby.  Topic is solved

General discussion related to SketchUp Pro and Make

How to delete a model imported from *.dae file by ruby.

Postby yuyuwhy » Thu Jan 15, 2015 3:19 pm

I have many *.dae files (about 10 thousand) that must be purged in SketchUp. So I write a plugin to deal with the *.dae files. How to delete a imported model in ruby?

Here is my ruby scripts, but the code doesn't have any effects.

model = Sketchup.active_model
entities = model.active_entities
entities.each { |singleEntity|
entities.erase_entities singleEntity
}
0

yuyuwhy 
 

Re: How to delete a model imported from *.dae file by ruby.  Topic is solved

Postby driven » Thu Jan 15, 2015 8:47 pm

what are you actually doing?

open new drawing...
import dae, purge, export purged dae...
Code: Select all
2.times{Sketchup.send_action('editUndo:')}

start again...
maybe you don't even need the 2.times....
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: How to delete a model imported from *.dae file by ruby.

Postby yuyuwhy » Fri Jan 16, 2015 1:10 am

driven wrote:what are you actually doing?

open new drawing...
import dae, purge, export purged dae...
Code: Select all
2.times{Sketchup.send_action('editUndo:')}

start again...
maybe you don't even need the 2.times....


yes, I just need to keep repeating the process: import a dae , purge, export purged dae, and deal with the next dae.

thank you very much...
:thumb:
0

yuyuwhy 
 

Re: How to delete a model imported from *.dae file by ruby.

Postby TIG » Fri Jan 16, 2015 2:47 pm

Start off by clearing everything, by using:
model = Sketchup.active_model
model.entities.clear!

then purge the model using:
model.definitions.purge_unused
model.active_layer=model.layers[0]; model.layers.purge_unused
model.materials.current=nil; model.materials.purge_unused
model.styles.purge_unused
ds = model.attribute_dictionaries; ds.to_a.each{|d| ds.delete(d) } if ds

Now you have an empty SKP.

Try doing the import AND export within a model.start_operation(...) block, BUT do not 'commit' it, rather you need to 'abort' it after each one.
That way the import happens, the export happens but the changes to the model are undone by each 'abort'. The exported file is NOT undone by the 'abort' !
1
TIG
User avatar
TIG 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to SketchUp Pro & Make Discussions

Who is online

Users browsing this forum: Google Bot, Google Feedfetcher and 14 guests

Visit our sponsors: