SldwrksExporter/scripts/run.py

59 lines
2.0 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
2023-02-06 18:18:30 +00:00
from rich import print
2023-02-06 10:26:05 +00:00
# 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
2023-02-06 18:18:30 +00:00
print("\nParts: \n", partFiles)
print("\nDrawings: \n", drwgFiles, "\n")
2023-02-06 16:59:03 +00:00
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)
2023-02-06 18:18:30 +00:00
print("\nExport folder created\n")
2023-02-06 16:59:03 +00:00
# part files
2023-02-06 18:18:30 +00:00
for i in track(partWithoutExention, description="Exporting step files...", total=len(partWithoutExention)):
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
2023-02-06 18:18:30 +00:00
for i in track(drwgWithoutExtension, description="Exporting PDF and DXF...", total = len(drwgWithoutExtension)):
2023-02-06 16:59:03 +00:00
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)