59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
# example: .\run.py path_to_folder\
|
|
|
|
import os
|
|
import sys
|
|
import pathlib
|
|
import subprocess
|
|
from rich.progress import track
|
|
from rich import print
|
|
|
|
# folder input
|
|
input = next(os.walk(sys.argv[1]))
|
|
files = input[2]
|
|
path = input[0]
|
|
|
|
currentPath = str(pathlib.Path().resolve())
|
|
|
|
# print("files: ", files)
|
|
# print("currentPath :", currentPath)
|
|
# print("path: ", path)
|
|
|
|
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")
|
|
|
|
|
|
|
|
outputFolder = str(path) + "\\export\\"
|
|
# print("Out folder: ", outputFolder)
|
|
|
|
# create export directory
|
|
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)):
|
|
input = str(i)
|
|
commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-step.ps1 "' + path + "\\" + input + '" "' + 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)):
|
|
input = str(i)
|
|
commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-pdf-dxf.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
|
|
# print(commandPdfDxf)
|
|
subprocess.run(commandPdfDxf, capture_output=True)
|