support multiple files input from GUI
This commit is contained in:
parent
fbc1e82651
commit
0d966f0556
@ -8,10 +8,9 @@ from rich.progress import track
|
|||||||
from rich import print
|
from rich import print
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
def run(cmdinput):
|
def dirToFileList(folder):
|
||||||
|
|
||||||
# folder input
|
# folder input
|
||||||
input = next(os.walk(cmdinput))
|
input = next(os.walk(folder))
|
||||||
files = input[2]
|
files = input[2]
|
||||||
path = input[0]
|
path = input[0]
|
||||||
|
|
||||||
@ -24,6 +23,17 @@ def run(cmdinput):
|
|||||||
path = path.replace('/', '\\')
|
path = path.replace('/', '\\')
|
||||||
# print("New path: ", path)
|
# print("New path: ", path)
|
||||||
|
|
||||||
|
filesList = []
|
||||||
|
for f in files:
|
||||||
|
f = f.replace('/', '\\')
|
||||||
|
filesList.append(str(path) + '\\' + str(f))
|
||||||
|
|
||||||
|
runFiles(filesList)
|
||||||
|
|
||||||
|
|
||||||
|
def runFiles(files):
|
||||||
|
currentPath = str(pathlib.Path().resolve())
|
||||||
|
|
||||||
partFiles = [s for s in files if ".SLDPRT" in s] # get only parts files
|
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
|
drwgFiles = [s for s in files if ".SLDDRW" in s] # get only drawings files
|
||||||
|
|
||||||
@ -37,53 +47,55 @@ def run(cmdinput):
|
|||||||
# Check if each part has drawings and print
|
# Check if each part has drawings and print
|
||||||
for p in partWithoutExention:
|
for p in partWithoutExention:
|
||||||
if str(p) not in str(drwgFiles):
|
if str(p) not in str(drwgFiles):
|
||||||
print(p, " doesn't have drawing file")
|
print(p, " doesn't have drawing file\n")
|
||||||
|
|
||||||
|
for p in files: # create export directory
|
||||||
|
outputFolder = os.path.split(p)[0] + "\\export\\"
|
||||||
outputFolder = str(path) + "\\export\\"
|
|
||||||
# print("Out folder: ", outputFolder)
|
# print("Out folder: ", outputFolder)
|
||||||
|
|
||||||
# create export directory
|
|
||||||
if not os.path.exists(outputFolder):
|
if not os.path.exists(outputFolder):
|
||||||
os.makedirs(outputFolder)
|
os.makedirs(outputFolder)
|
||||||
# print("\nExport folder created\n")
|
# print("\nExport folder created\n")
|
||||||
|
|
||||||
# part files
|
# part files
|
||||||
for i in track(partWithoutExention, description="Exporting step files...", total=len(partWithoutExention)):
|
for i in track(partWithoutExention, description="Exporting step files...", total=len(partWithoutExention)):
|
||||||
input = str(i)
|
path, input = os.path.split(i)
|
||||||
commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\export-step.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
|
i = i.replace('/', '\\')
|
||||||
|
path = path.replace('/', '\\')
|
||||||
|
outputFolder = path + "\\export\\"
|
||||||
|
|
||||||
|
commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-step.ps1 "' + i + '" "' + outputFolder + input + '"'
|
||||||
# print(commandstep)
|
# print(commandstep)
|
||||||
subprocess.run(commandstep, capture_output=True)
|
subprocess.run(commandstep, capture_output=True)
|
||||||
|
|
||||||
# drawings files
|
# drawings files
|
||||||
for i in track(drwgWithoutExtension, description="Exporting PDF and DXF...", total = len(drwgWithoutExtension)):
|
for i in track(drwgWithoutExtension, description="Exporting PDF and DXF...", total = len(drwgWithoutExtension)):
|
||||||
input = str(i)
|
path, input = os.path.split(i)
|
||||||
commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\export-pdf-dxf.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
|
i = i.replace('/', '\\')
|
||||||
|
path = path.replace('/', '\\')
|
||||||
|
outputFolder = path + "\\export\\"
|
||||||
|
commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-pdf-dxf.ps1 "' + i + '" "' + outputFolder + input + '"'
|
||||||
# print(commandPdfDxf)
|
# print(commandPdfDxf)
|
||||||
subprocess.run(commandPdfDxf, capture_output=True)
|
subprocess.run(commandPdfDxf, capture_output=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
cmd = str(sys.argv[1] )
|
cmd = str(sys.argv[1] )
|
||||||
run(cmd)
|
dirToFileList(cmd)
|
||||||
else:
|
else:
|
||||||
fname = sg.Window('Files exporter',
|
fname = sg.Window('Exporter',
|
||||||
[[sg.Text('Folder to export')],
|
[[sg.Text('Folder to export')],
|
||||||
[sg.In(), sg.FolderBrowse()],
|
[sg.In(), sg.FilesBrowse(button_text="Open files"), sg.FolderBrowse(button_text="Open folder")],
|
||||||
[sg.Open(), sg.Cancel()]]).read(close=True)[1][0]
|
[sg.Open(), sg.Cancel()]]).read(close=True)[1][0]
|
||||||
|
|
||||||
if not fname:
|
if not fname:
|
||||||
sg.popup("Cancel", "No filename supplied")
|
sg.popup("Cancel", "No filename supplied")
|
||||||
raise SystemExit("Cancelling: no filename supplied")
|
raise SystemExit("Cancelling: no filename supplied")
|
||||||
else:
|
else:
|
||||||
# sg.popup('The filename you chose was', fname)
|
if os.path.isdir(fname):
|
||||||
print(fname)
|
dirToFileList(str(fname))
|
||||||
cmd = str(fname)
|
else:
|
||||||
run(cmd)
|
runFiles(str(fname).split(';'))
|
||||||
|
|
||||||
# a = input()
|
print("Done")
|
||||||
# print(a)
|
|
||||||
print("Done")
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user