Skip to main content
changed the script slightly
Source Link
Lala_Ghost
  • 489
  • 4
  • 20

Based on Jakemoyo's answer. Changed a bit to work for Windows and getting username and Blender version by itself:

import bpy
from pathlib import Path
import getpass

blenderVersionFolderName = '3.3'
blenderVersion = bpy.app.version_string
if blenderVersion[-1] == '0':
    blenderVersionFolderName = blenderVersion[:-1]
if blenderVersionFolderName[-1] == '.':
    blenderVersionFolderName = blenderVersionFolderName[:-1]

recent_files = 'C:\\Users\\' + getpass.getuser() + '\\AppData\\Roaming\\Blender Foundation\\Blender\\' + blenderVersionFolderName + '\\config\\recent-files.txt'

save_path = Path('C:\Desktop\my_blend.blend')
bpy.ops.wm.save_mainfile(filepath=save_path)

# add the blendfile path to the recent-files.txt
with open(recent_files, 'r+') as f:
    contents = f.read()
    f.seek(0,0) # go to beginning of file
    if save_path.is_file():
        newfile = str(save_path.resolve()) + '\n' + contents
        f.write(newfile)
    else:
        print("File did not save correctly.")

# reread file history    
bpy.ops.wm.read_history()

Based on Jakemoyo's answer. Changed a bit to work for Windows and getting username and Blender version by itself:

import bpy
from pathlib import Path
import getpass

blenderVersion = bpy.app.version_string
if blenderVersion[-1] == '0':
    blenderVersionFolderName = blenderVersion[:-1]
if blenderVersionFolderName[-1] == '.':
    blenderVersionFolderName = blenderVersionFolderName[:-1]

recent_files = 'C:\\Users\\' + getpass.getuser() + '\\AppData\\Roaming\\Blender Foundation\\Blender\\' + blenderVersionFolderName + '\\config\\recent-files.txt'

save_path = Path('C:\Desktop\my_blend.blend')
bpy.ops.wm.save_mainfile(filepath=save_path)

# add the blendfile path to the recent-files.txt
with open(recent_files, 'r+') as f:
    contents = f.read()
    f.seek(0,0) # go to beginning of file
    if save_path.is_file():
        newfile = str(save_path.resolve()) + '\n' + contents
        f.write(newfile)
    else:
        print("File did not save correctly.")

# reread file history    
bpy.ops.wm.read_history()

Based on Jakemoyo's answer. Changed a bit to work for Windows and getting username and Blender version by itself:

import bpy
from pathlib import Path
import getpass

blenderVersionFolderName = '3.3'
blenderVersion = bpy.app.version_string
if blenderVersion[-1] == '0':
    blenderVersionFolderName = blenderVersion[:-1]
if blenderVersionFolderName[-1] == '.':
    blenderVersionFolderName = blenderVersionFolderName[:-1]

recent_files = 'C:\\Users\\' + getpass.getuser() + '\\AppData\\Roaming\\Blender Foundation\\Blender\\' + blenderVersionFolderName + '\\config\\recent-files.txt'

save_path = Path('C:\Desktop\my_blend.blend')
bpy.ops.wm.save_mainfile(filepath=save_path)

# add the blendfile path to the recent-files.txt
with open(recent_files, 'r+') as f:
    contents = f.read()
    f.seek(0,0) # go to beginning of file
    if save_path.is_file():
        newfile = str(save_path.resolve()) + '\n' + contents
        f.write(newfile)
    else:
        print("File did not save correctly.")

# reread file history    
bpy.ops.wm.read_history()
Source Link
Lala_Ghost
  • 489
  • 4
  • 20

Based on Jakemoyo's answer. Changed a bit to work for Windows and getting username and Blender version by itself:

import bpy
from pathlib import Path
import getpass

blenderVersion = bpy.app.version_string
if blenderVersion[-1] == '0':
    blenderVersionFolderName = blenderVersion[:-1]
if blenderVersionFolderName[-1] == '.':
    blenderVersionFolderName = blenderVersionFolderName[:-1]

recent_files = 'C:\\Users\\' + getpass.getuser() + '\\AppData\\Roaming\\Blender Foundation\\Blender\\' + blenderVersionFolderName + '\\config\\recent-files.txt'

save_path = Path('C:\Desktop\my_blend.blend')
bpy.ops.wm.save_mainfile(filepath=save_path)

# add the blendfile path to the recent-files.txt
with open(recent_files, 'r+') as f:
    contents = f.read()
    f.seek(0,0) # go to beginning of file
    if save_path.is_file():
        newfile = str(save_path.resolve()) + '\n' + contents
        f.write(newfile)
    else:
        print("File did not save correctly.")

# reread file history    
bpy.ops.wm.read_history()