Sketchup crashes when import,purge_unused,export dae files
-
Sketchup crashes when import,purge_unused,export hundreds of *.dae files.
I use api to do this.It works fine while handling few *.dae files.
anyone konws why?Here is my code
require 'sketchup.rb'
require 'fileutils'UI.menu("Plugins").add_item("purge_multi_daeE") {
@import_folder = selectImportDaefolder() break if @import_folder==nil @export_folder = selectExportDaefolder() break if @export_folder==nil @daeFiles = getDaeFiles(@import_folder,".dae") purgeDaeFile(@daeFiles,@import_folder,@export_folder) Sketchup.send_action("selectSelectionTool:")
}
def purgeDaeFile(daeFiles, import_folder,export_folder)
model = Sketchup.active_modelsubName = getDirName(import_folder) Dir.chdir(export_folder) FileUtils.rm_r subName if Dir.exist?(subName) i = 0 Dir.mkdir(subName) daeFiles.each{|singleDaeFile| Sketchup::set_status_text("purge " + File.basename(singleDaeFile)) status = Sketchup.active_model.definitions.purge_unused f.puts(singleDaeFile) importDaeFile(singleDaeFile) purgeModel() resultFileName = File.join(export_folder,subName,File.basename(singleDaeFile)) Sketchup.active_model.export(resultFileName, false) deleteLastModel() }
end#def
purge dae model
def purgeModel()
# 1. purge styles
styles = Sketchup.active_model.styles
status = styles.purge_unused# 2. purge materials materials = Sketchup.active_model.materials materials.purge_unused # 3. purge definitions definitions = Sketchup.active_model.definitions status = definitions.purge_unused # 4. purge layers layers = Sketchup.active_model.layers status = layers.purge_unused
end#def
导入dae file
def importDaeFile(singleDaeFile)
model = Sketchup.active_model
model.import(singleDaeFile,false)
entities = model.entities
definitions = model.definitions
definitions.each {|definition|
transformation = Geom::Transformation.new([0,0,0])
componentinstance = entities.add_instance(definition, transformation)
}Sketchup.send_action("selectSelectionTool:")
end#def
def deleteLastModel()
model = Sketchup.active_model
entities = model.active_entities
entities.erase_entities entities.to_aend#def
Advertisement