Save Model using Ruby API on Windows
-
I'm having some problems saving a model using the ruby api on windows, but the code seems to work on mac. When I call model.save and then check if it's modified it says it isn't, as if the model was saved. But when I restart sketchup and open the model the changes aren't there.
Has anyone run into this?
-
What are the errors being output to the ruby console?
-
there aren't any errors. I've had it throw errors on invalid paths in the past but it isn't doing that anymore. I also don't think that it's saving to a completely different path because it works on the mac version.
-
The following code I found here... https://groups.google.com/forum/#!msg/sketchupruby/ymKyqD_nxBU/AczVTLjFld4J
# Description; # sketchup's "model.save" does not work. # routine to save a .skp file with the same name as the current model # need to save file with a temporary name, (close model ?), # then move the temporary name to the real name def model_save(sfile) sfile2 = sfile + '.tmp' bret = Sketchup.active_model.save(sfile2) return(bret) if !bret # now move sfile2 to sfile # remove existing file # need to close existing model first Sketchup.file_new if File.exists?(sfile) begin File.unlink(sfile) rescue warn "Could not delete file; " + sfile return(false) end end bret2 = File.rename(sfile2, sfile) printf("INFO; Saved to \"%s\"\n", sfile) end -
From that same thread, Dan mentions you can use this command to simulate the actual File > Save:
Sketchup.send_action( 57603 )
Then you could use the regular Model.save for Mac and the send_action for PC's. I've not tried it, but it might be a solution.
-
@chris fullmer said:
From that same thread, Dan mentions you can use this command to simulate the actual File > Save:
Sketchup.send_action( 57603 )
Then you could use the regular Model.save for Mac and the send_action for PC's. I've not tried it, but it might be a solution.
That worked great, thanks.
-
@conchords said:
@chris fullmer said:
From that same thread, Dan mentions you can use this command to simulate the actual File > Save:
Sketchup.send_action( 57603 )
Then you could use the regular Model.save for Mac and the send_action for PC's. I've not tried it, but it might be a solution.
That worked great, thanks.
Actually at that time I did not know of the cross-platform send action string,
"saveDocument:"...... so you can just use
Sketchup.send_action( "saveDocument:" )
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement