As my jorney through SketchUp API continues, i encountered a new problem. I try to create script in Ruby Console, which will allow me to import many dxf files at once. But when I try to execute teh script, after every model.import execution new view is created - which results with program crash after circa 30 imports. Is there any way to force SketchUp NOT to create new virew after importing dxf ?
We first have to identify what the problem is, before we decide for solutions.
The problem is that the DXF file can contain “views” which are imported as SketchUp scenes. The graphical (GUI) import contains an options dialog for DXF but doesn’t allow to skip scenes. Whether you invoke the same (Sketchup::Model#import) via the Ruby API or as Ruby C extension makes no difference.
The SketchUp SDK is for writing your own importer, from scratch. That means you can control everything it does, but you also have to implement all the basics on your own (importing faces etc.).
In case you just went here to ask this question because you want to avoid the scene creation, then maybe we should look for a more appropriate solution.
Via the Ruby API you could identify the added scenes and delete them again:
module Pawelelele
def self.import_without_scenes(model, filepath)
scenes_before = model.pages.to_a
model.import(filepath)
added_scenes = model.pages.to_a - scenes_before
added_scenes.each{ |scene|
model.pages.erase(scene)
}
end
unless file_loaded?(__FILE__)
command = UI::Command.new("Import DXF without scenes") {
model = Sketchup.active_model
filepath = UI.openpanel
if filepath && File.exists?(filepath)
model.start_operation("Import DXF without scenes")
self.import_without_scenes(model, filepath)
model.commit_operation
end
}
UI.menu("File").add_item(command)
file_loaded(__FILE__)
end
end # module Pawelelele
If you post your code and explain your objectives, then advice would be easier…
e.g.
do you want them all in one model or do you want each as a separate skp or component?