# example: .\run.py path_to_folder\ import os import sys import pathlib import subprocess from rich.progress import track from rich import print import PySimpleGUI as sg def dirToFileList(folder): # folder input input = next(os.walk(folder)) files = input[2] path = input[0] path = path.replace('/', '\\') filesList = [] for f in files: f = f.replace('/', '\\') filesList.append(str(path) + '\\' + str(f)) runFiles(filesList) def runFiles(files): currentPath = os.path.dirname(os.path.realpath(__file__)) # print("Current path script" + currentPath) partFiles = [s for s in files if ".SLDPRT" in s] # get only parts files drwgFiles = [s for s in files if ".SLDDRW" in s] # get only drawings files print("\nParts: \n", partFiles) print("\nDrawings: \n", drwgFiles, "\n") partWithoutExention = [os.path.splitext(x)[0] for x in partFiles] # remove extension drwgWithoutExtension = [os.path.splitext(x)[0] for x in drwgFiles] # remove extension # print("Parts without extension: ", partWithoutExention) # Check if each part has drawings and print for p in partWithoutExention: if str(p) not in str(drwgFiles): print(p, " doesn't have drawing file\n") for p in files: # create export directory outputFolder = os.path.split(p)[0] + "\\export\\" # print("Out folder: ", outputFolder) if not os.path.exists(outputFolder): os.makedirs(outputFolder) # print("\nExport folder created\n") # part files for i in track(partWithoutExention, description="Exporting step files...", total=len(partWithoutExention)): path, input = os.path.split(i) i = i.replace('/', '\\') path = path.replace('/', '\\') outputFolder = path + "\\export\\" commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\export-step.ps1 "' + i + '" "' + outputFolder + input + '"' # print(commandstep) subprocess.run(commandstep, capture_output=True) # drawings files for i in track(drwgWithoutExtension, description="Exporting PDF and DXF...", total = len(drwgWithoutExtension)): path, input = os.path.split(i) i = i.replace('/', '\\') path = path.replace('/', '\\') outputFolder = path + "\\export\\" commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\export-pdf-dxf.ps1 "' + i + '" "' + outputFolder + input + '"' # print(commandPdfDxf) subprocess.run(commandPdfDxf, capture_output=True) if __name__ == '__main__': if len(sys.argv) > 1: cmd = str(sys.argv[1] ) dirToFileList(cmd) else: fname = sg.Window('Exporter', [[sg.Text('Folder to export')], [sg.In(), sg.FilesBrowse(button_text="Open files"), sg.FolderBrowse(button_text="Open folder")], [sg.Open(), sg.Cancel()]]).read(close=True)[1][0] if not fname: sg.popup("Cancel", "No filename supplied") raise SystemExit("Cancelling: no filename supplied") else: if os.path.isdir(fname): dirToFileList(str(fname)) else: runFiles(str(fname).split(';')) input("\nDone\n\n Press enter to quit\n")