verhalten mit gegebenen directorys in create_assembly angepasst. save_stl neu.
This commit is contained in:
@@ -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