Post work/project script - mass savesmall

–>select folder , it will scan all other subfolders as well,
–>for purge it will ask you select options which will be applied to all others too.

import rhinoscriptsyntax as rs
import os
import glob

# Open a dialog to choose a folder
folder = rs.BrowseForFolder(message="Select a folder")

# Open a log file
with open(os.path.join(folder, "log.txt"), "w") as log_file:
    # Check if a folder was selected
    if folder:
        # Get a list of all Rhino files in the folder and subfolders
        files = [os.path.join(dirpath, file) for dirpath, dirnames, files in os.walk(folder) for file in files if file.endswith(".3dm")]
        
        # Sort the files by modified date in descending order
        files.sort(key=os.path.getmtime, reverse=True)
        
        # Loop through each file
        for file in files:
            # Open the file
            rs.Command("_-Open " + '"' + file + '"' + " _Enter", True)
            
            # Get the current file path
            current_path = rs.DocumentPath()
            
            # Check if the document has a path
            if current_path:
                # Get all viewports
                viewports = rs.ViewNames()
                
                # Set all viewports to wireframe
                for viewport in viewports:
                    rs.ViewDisplayMode(viewport, mode="Wireframe")
                
                # Purge unused items
                rs.Command("_-Purge _Enter", True)
                
                # Save the document using the "Save Small" command
                rs.Command("_-SaveSmall " + '"' + current_path + '"' + " _Enter _Enter", True)
                
                # Write to the log file
                log_file.write("Saved file: " + current_path + "\n")
            
            # Open a new document
            rs.Command("_-New _None _Enter", True)

posting more scripts soon.

1 Like