verhalten mit gegebenen directorys in create_assembly angepasst. save_stl neu.
This commit is contained in:
@@ -10,7 +10,7 @@ def start_solid_edge():
|
|||||||
print("Starting instance of SolidEdge...")
|
print("Starting instance of SolidEdge...")
|
||||||
se = win32com.client.Dispatch("SolidEdge.Application")
|
se = win32com.client.Dispatch("SolidEdge.Application")
|
||||||
se.Visible = True
|
se.Visible = True
|
||||||
print("done")
|
print("done\n")
|
||||||
return se.Documents
|
return se.Documents
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ def process_part(par_name, par_path, dummy_asm_path, placeholder_name, work_dir,
|
|||||||
ziel_path = os.path.join(output_dir, ziel_name)
|
ziel_path = os.path.join(output_dir, ziel_name)
|
||||||
|
|
||||||
asm_doc.SaveAs(ziel_path)
|
asm_doc.SaveAs(ziel_path)
|
||||||
print(f"Saved: {ziel_path}")
|
print(f"→ Saved: {ziel_path}")
|
||||||
|
|
||||||
asm_doc.Close(False)
|
asm_doc.Close(False)
|
||||||
|
|
||||||
@@ -83,9 +83,19 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Umgebungsvariablen & Ordner
|
# Umgebungsvariablen & Ordner
|
||||||
work_dir = os.environ.get("PROJECT_WORK", "../work")
|
work_dir = os.environ.get("PROJECT_WORK", "../work")
|
||||||
data_dir = os.environ.get("PROJECT_DATA", "./data")
|
data_dir = os.environ.get("PROJECT_DATA", "../data")
|
||||||
input_dir = args.input_dir if args.input_dir else os.environ.get("PROJECT_INPUT", "./input")
|
|
||||||
output_dir = args.output_dir if args.output_dir else work_dir
|
if args.input_dir:
|
||||||
|
input_dir = args.input_dir
|
||||||
|
print("Using provided input directory.")
|
||||||
|
else:
|
||||||
|
input_dir = os.environ.get("PROJECT_INPUT", "../input")
|
||||||
|
print("No input directory provided. Using standard input directory.")
|
||||||
|
|
||||||
|
if args.output_dir:
|
||||||
|
output_dir = args.output_dir
|
||||||
|
else:
|
||||||
|
output_dir = work_dir
|
||||||
|
|
||||||
os.makedirs(work_dir, exist_ok=True)
|
os.makedirs(work_dir, exist_ok=True)
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
@@ -108,4 +118,4 @@ if __name__ == "__main__":
|
|||||||
if output_dir == work_dir:
|
if output_dir == work_dir:
|
||||||
print("\nNo output folder (--out) specified. Files saved into 'work' folder.")
|
print("\nNo output folder (--out) specified. Files saved into 'work' folder.")
|
||||||
else:
|
else:
|
||||||
print("\nAll .par files processed and saved into target folder.")
|
print("\nAll .par files processed and saved into given target folder.")
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import win32com.client
|
||||||
|
import pythoncom
|
||||||
|
|
||||||
|
def export_assemblies_to_stl(input_dir, output_dir):
|
||||||
|
pythoncom.CoInitialize()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Solid Edge starten oder verbinden
|
||||||
|
se_app = win32com.client.Dispatch("SolidEdge.Application")
|
||||||
|
se_app.Visible = False
|
||||||
|
|
||||||
|
documents = se_app.Documents
|
||||||
|
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
for filename in os.listdir(input_dir):
|
||||||
|
if filename.lower().endswith(".asm"):
|
||||||
|
asm_path = os.path.join(input_dir, filename)
|
||||||
|
stl_filename = os.path.splitext(filename)[0] + ".stl"
|
||||||
|
stl_path = os.path.join(output_dir, stl_filename)
|
||||||
|
|
||||||
|
print(f"Processing: {asm_path}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Baugruppe öffnen
|
||||||
|
doc = documents.Open(asm_path)
|
||||||
|
# STL exportieren in den Unterordner
|
||||||
|
doc.SaveAs(stl_path)
|
||||||
|
print(f"→ Exported to: {stl_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error processing {filename}: {e}")
|
||||||
|
finally:
|
||||||
|
# Datei schließen
|
||||||
|
doc.Close(False)
|
||||||
|
|
||||||
|
# --- Aufräumen: .cfg und .log im Hauptordner ---
|
||||||
|
print("")
|
||||||
|
for file in os.listdir(input_dir):
|
||||||
|
if file.lower().endswith((".cfg", ".log")):
|
||||||
|
file_path = os.path.join(input_dir, file)
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
print(f"Deleted (input): {file}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting {file}: {e}")
|
||||||
|
|
||||||
|
# --- Aufräumen: .log im STL-Unterordner ---
|
||||||
|
for file in os.listdir(output_dir):
|
||||||
|
if file.lower().endswith(".log"):
|
||||||
|
file_path = os.path.join(output_dir, file)
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
print(f"Deleted (output): {file}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting {file}: {e}")
|
||||||
|
|
||||||
|
print("\nExport and cleanup completed.")
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
if 'doc' in locals():
|
||||||
|
doc.Close(False)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Exportiert alle .asm-Dateien in einem Ordner nach STL.")
|
||||||
|
parser.add_argument("--in", dest="input_dir", required=False, help="Ordner mit .asm-Dateien (Standard: WORK oder ../work)")
|
||||||
|
parser.add_argument("--out", dest="output_dir", required=False, help="Zielordner für STL-Dateien (Standard: work/STL_Export)")
|
||||||
|
|
||||||
|
if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"):
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
work_dir = os.environ.get("PROJECT_WORK", "../work")
|
||||||
|
|
||||||
|
if args.input_dir:
|
||||||
|
input_dir = args.input_dir
|
||||||
|
print("Using provided input directory.\n")
|
||||||
|
else:
|
||||||
|
input_dir = os.environ.get("PROJECT_WORK", "../work")
|
||||||
|
print("No input directory provided. Using 'work' directory as input.\n")
|
||||||
|
|
||||||
|
if args.output_dir:
|
||||||
|
output_dir = args.output_dir
|
||||||
|
print(f"Saving exported STL files to provided output directory.\n")
|
||||||
|
else:
|
||||||
|
output_dir = os.path.join(work_dir, "STL_Export")
|
||||||
|
print(f"No output directory provided. Exporting STL files to 'work'.\n")
|
||||||
|
|
||||||
|
|
||||||
|
if not os.path.exists(input_dir):
|
||||||
|
print(f"Input folder not found: {input_dir}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
export_assemblies_to_stl(input_dir, output_dir)
|
||||||
Reference in New Issue
Block a user