sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Model.save does not save

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 3 Posters 1.6k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      @hpw said:

      @unknownuser said:

      Have you searched for the file name. Seeing that you give the method a relative filename, do you know where it's saved?

      Yes it is there. When I press the File/Save it gets written with it's new size.

      ? Aren't we talking about saving from Ruby?

      @hpw said:

      It gives a invalid filename-error.

      Can you give an example of a filename with the path that doesn't work? Maybe you got some non-ASCII characters that causes problems.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • H Offline
        HPW
        last edited by

        @unknownuser said:

        ? Aren't we talking about saving from Ruby?

        Yes, I copy a empty SKP to my work-directory and start SU with the filename in the commandline-parameter.
        So I stand in my SKP-file yet.
        Now the startup-ruby does import my autocad-file and does some processing on it.
        Now I want to save and leave SU.
        The ruby save does not work. But when I choose File/save or CTRL-S then it gets saved.

        @unknownuser said:

        Can you give an example of a filename with the path that doesn't work? Maybe you got some non-ASCII characters that causes problems.

        No. My filesnames are as following:

        20090708_080921161_samplecust@sampleurl_com_{E62CA959-8615-40C9-926E-4883168F8FEC}.skp

        Date_time_email_GUID.skp

        I also tried Hello.skp with no luck.

        And why does the command only take a filename without path?

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @hpw said:

          Yes, I copy a empty SKP to my work-directory and start SU with the filename in the commandline-parameter.
          So I stand in my SKP-file yet.
          Now the startup-ruby does import my autocad-file and does some processing on it.
          Now I want to save and leave SU.
          The ruby save does not work. But when I choose File/save or CTRL-S then it gets saved.

          I'm not sure if SU will use the path that you opened the file from. It could be saved to a completely different location. Which is why I suggest you search your harddrive for it.

          Not sure what the deal with full path is though. Have to look into that.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            I did a quick test myself.

            File.dirname('test.skp')
            This saved a file in my Sketchup folder. I'm guessing it's where your files are saved as well.

            And I had no problems saving files using full path. But I wonder if you haven't used forward slashes (/) as Ruby require due to it's cross-platform nature.

            'C:\test.skp' fails, but 'C:/test.skp' works.

            You can use File.expand_path to convert relative paths to full paths and also sort out your slashes.
            ` File.expand_path('.')

            C:/Programfiler/Google/Google SketchUp 7`

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • H Offline
              HPW
              last edited by

              Thanks for the hint with the forward-slashes.
              And I find some test-files in my 'Google Sketchup 7\Plugins' folder.

              But there remains a problem.
              I can not save to the filename of my currently open file.
              That does not work.
              When I modify the filename and save to a new file then it works.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                That's probably because SU has that file open and the Ruby script isn't allowed access to it.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • H Offline
                  HPW
                  last edited by

                  @unknownuser said:

                  That's probably because SU has that file open and the Ruby script isn't allowed access to it.

                  But then it shouldn't return 'true' for success.
                  I would call it a bug.
                  Also the doc could be more improved with a sample with path and a hint to the forward-slash problem.

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    It return true when you save over the currently open file?
                    And if you reopen that file - what do you get?

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      HPW
                      last edited by

                      @unknownuser said:

                      It return true when you save over the currently open file?
                      And if you reopen that file - what do you get?

                      It return true when I try to save to the currently open file!
                      But it stays the same size and when I reopen it I get the same as before.

                      1 Reply Last reply Reply Quote 0
                      • Al HartA Offline
                        Al Hart
                        last edited by

                        After wrestling with this problem for an hour or two for a routine I am writing to load a .SKP file, change it and resave it, I came up with this solution:

                        1. Replace \ with / in the file name (save does not seem to like )
                        2. Save the current model with a temporary name (in the same folder as the desired final name)
                        3. Close the current model (You have to close the model so you can modify the .skp file already on disk)
                        4. Remove the current .skp file (if it exists)
                        5. Move the temporary file to the desired file (rename())
                        
                        	# 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 resave_file(sfile)
                        		# save() does not seem to like back slashes
                        		# replace them withforward slashes
                        		sfile.gsub!(Regexp.new("\\\\"), '/')
                        		printf("sfile; %s\n", sfile)
                        		
                        		# save to a temporary location first
                        		# this assumes the file name ends with .skp (or .SKP)
                        		sfile2 = sfile[0, sfile.length - 3] + 'TMP'
                        		printf("sfile2; %s\n", sfile2)
                        		bret = Sketchup.active_model.save(sfile2)
                        		printf("Save file; bret; %s\n", bret)
                        		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#if
                        		
                        		bret2 = File.rename(sfile2, sfile)
                        		printf("Returning bret2; %s2\n", bret2)
                        		return(bret2)
                        		
                        	end#def
                        
                        

                        If you need to file to still be open after the save, you could open it again.

                        Let me know if it works for you

                        Al Hart

                        http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                        IRender nXt from Render Plus

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement