Saving and importing file

I create a model in c++ and then I save it using:

SUModelSaveToFile(model, "C://Users//userMe//model.skp");

Then I use on openFile methond in ruby to import the model.

def self.openFile

    model = Sketchup.active_model
    status = model.import 'C://Users//userMe//model.skp'

  end

When I create a new model I am replacing/overwriting “model.skp”. However my openFile opens the old model. I created a function in C++ to remove the file after its been imported. But it still finds the old model everytime. When I go to the folder and open up the model.skp file its the new model! Any thoughts?

VALUE removeFile(){
	
	if (remove("C://Users//userMe//model.skp") != 0){
		perror("Error deleting file");
		return Qfalse;
	}
	else
		return Qtrue;

}

You may need to “difference” the active model from the state it was when last saved.
(Whenever the active model is saved, the “modified” flag gets reset to false, and the engine sees the call to reload the same file as unnecessary.)

You might also clear the active model’s entities before the import ?

Sketchup.active_model.entities.clear!

Or create a temporary cpoint at the ORIGIN:

cpt = Sketchup.active_model.entities.add_cpoint(ORIGIN)

… do the import, then delete cpt.

Thanks for the help. I ended up changing model.skp to #.skp where # = the number of faces in each model. This way each time I went through it created a unique file.

If you need a unique number then try using the number of seconds since the beginning of the current epic.

secs = Time.now.to_i.to_s

For more info on Ruby’s standard Time class, see:
http://ruby-doc.org/core-2.0.0/Time.html