• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Setting the save path for files ???

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 2 Posters 493 Views 2 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.
  • A Offline
    artmusicstudio
    last edited by 6 Dec 2013, 22:01

    hi,
    here is a small one :

    retrieve file path works:

    
    model = Sketchup.active_model
    @local_user_path = model.path
    puts @local_user_path
    end
    
    

    but how can write back the path, when it was changed by save-operations from my ruby, so that
    autobackup writes its files to the original file directory and not to the plugin folder ??

    no "set_path" function in the model class found....

    thanx stan

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 7 Dec 2013, 02:52

      ` @old_path = model.path
      Sketchup.send_action("saveDocument:")

      make changes here

      model.save( @new_path )

      Sketchup.open_file( @old_path )`

      Note that on the Mac, there will now be 2 document windows open.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • A Offline
        artmusicstudio
        last edited by 7 Dec 2013, 14:03

        hi dan,
        yes, this is for saving sketchup models from the ruby, right?

        but skp seems to use the last use directory for saving ( in my case MY save function for my ruby parameters) of further files, like autobackup. they all appear now in the ruby directory.
        so can i define somewhere the system variable for the save directory, whithout saving a model file myself ?

        means, restoring the value of model path from 'old path' by setting a value only?

        stan

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 7 Dec 2013, 21:44

          You need to learn the standard Ruby classes File and Dir .


          Current Working System directory:
          Dir.getwd

          NEVER trust that it is pointing where you wish, because any script can change it.
          BE NICE .. so SAVE and RESTORE it if you change it, when your done.

          prevdir = Dir.getwd
          Dir.chdir( @new_path )
          #
          ### save files to new dir with only filespecs
          #
          ### Restore previous working directory;
          Dir.chdir( prevdir )
          
          

          It is initially set to the User's HOME directory (%USERPROFILE% on Windows.)
          On MAC: ENV["HOME"]
          On Win: ENV["USERPROFILE"]

          Under Ruby "~/" will only expand to the User's root dir, IF ENV["HOME"] is defined.
          so, on Windows...
          ENV["HOME"]=ENV["USERPROFILE"] unless ENV["HOME"]


          Other info:

          Current models full pathname:
          model.path

          Current models directory:
          File.dirname( model.path )

          Current model's filespec:
          File.basename( model.path )

          Current model's filename:
          model.title

          Current model's file extension:
          File.extname( model.path )

          Joining a new path with a old filespec:
          File.join( @new_path, File.basename( model.path ) )

          💭

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • A Offline
            artmusicstudio
            last edited by 7 Dec 2013, 23:10

            hi dan,
            that's exactly, what i ment.
            i want to restore the user file path after my ruby finished it's job.
            perfect!

            thank you very much, also for the other system variables, very useful for future development.
            stan

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

            Advertisement