SldwrksExporter/scripts/run.py

58 lines
1.9 KiB
Python
Raw Normal View History

2023-02-06 16:59:03 +00:00
# example: .\run.py path_to_folder\
2023-02-06 10:26:05 +00:00
import os
import sys
import pathlib
import subprocess
from rich.progress import track
# folder input
2023-02-06 16:59:03 +00:00
input = next(os.walk(sys.argv[1]))
files = input[2]
path = input[0]
2023-02-06 10:26:05 +00:00
2023-02-06 16:59:03 +00:00
currentPath = str(pathlib.Path().resolve())
2023-02-06 10:26:05 +00:00
2023-02-06 16:59:03 +00:00
# print("files: ", files)
# print("currentPath :", currentPath)
# print("path: ", path)
2023-02-06 10:26:05 +00:00
2023-02-06 16:59:03 +00:00
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("Parts: ", partFiles)
# print("Drawings: ", drwgFiles)
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")
2023-02-06 10:26:05 +00:00
2023-02-06 16:59:03 +00:00
outputFolder = str(path) + "\\export\\"
# print("Out folder: ", outputFolder)
# create export directory
if not os.path.exists(outputFolder):
os.makedirs(outputFolder)
print("Export folder created")
# part files
for i in track(partWithoutExention, description="Exporting step files..."):
2023-02-06 10:26:05 +00:00
input = str(i)
2023-02-06 18:09:29 +00:00
commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-step.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
2023-02-06 16:59:03 +00:00
# print(commandstep)
2023-02-06 10:26:05 +00:00
subprocess.run(commandstep, capture_output=True)
2023-02-06 16:59:03 +00:00
# drawings files
for i in track(drwgWithoutExtension, description="Exporting PDF and DXF..."):
input = str(i)
2023-02-06 18:09:29 +00:00
commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-pdf-dxf.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
2023-02-06 16:59:03 +00:00
# print(commandPdfDxf)
2023-02-06 10:26:05 +00:00
subprocess.run(commandPdfDxf, capture_output=True)