Model.import creates new view

Hello again !

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 ?

My code:

model = Sketchup.active_model
model.import "C:\\HExportSketchup\\Cs\\C-L1-Z10.dxf", false
model.import "C:\\HExportSketchup\\Cs\\C-L1-Z3.dxf", false
model.import "C:\\HExportSketchup\\Cs\\C-L2-Z1.dxf", false

and so on.

Is it possible to import dxf file using C SDK?

Many Thanks,
Paweł

you are, the dxf import plugin is written in C, but you could write your own version of it…

john

Can you explain this a bit more, and how is it a problem, or how is it the cause for the crash? You mean a Sketchup::View object?

Yeah, but how can i invoke importing DXF file using SDK?

What I mean by new views are being created is:

Afrer every model.import new “3D” view is being created. When it creates more than 40 of them, program crashes.

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

Avoiding scene creation does not help. New scenes are not being created anymore, but program still crashes. Any ideas?

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?

how many are you attempting to ‘batch’ convert?

john