-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACCORE.py
More file actions
63 lines (54 loc) · 1.96 KB
/
ACCORE.py
File metadata and controls
63 lines (54 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8
# Python 3.11.3
'''
ACCORE 1.0
Launch accoreconsole.exe
- No install
- Only for Windows
- Tested with Windows 10 and Autocad 2015
:No copyright: (!) 2023 by Frédéric Coulon.
:No license: Do with it what you want.
'''
from tkinter import Tk, filedialog
from subprocess import Popen
from os import path, listdir, devnull, getcwd
def accore():
bat = getcwd() + "/temp.bat"
# Files explorer
root = Tk()
# Hides the root window.
root.withdraw()
# Select DWG directory.
dwg_path = filedialog.askdirectory(initialdir = 'c:/',
title = 'Select DWG directory')
if dwg_path:
# Select SCR file.
scr = filedialog.askopenfilenames(initialdir = 'c:/',
title = 'Select SCR file',
filetypes = [('SCR files', '*.scr')])[0]
# Number of dwgs in the directory
nbdwg = len([f for f in listdir(dwg_path)
if path.isfile(path.join(dwg_path, f))
and f.endswith('.dwg')])
if scr and nbdwg > 0:
try:
# Write the .bat.
with open(bat, "w") as f:
f.write(f'\
@echo off\nchcp 1252\ncd {dwg_path}\
\nfor /f "delims=" %%f IN (\'dir /b "*.dwg"\') \
do accoreconsole.exe /i "%%f" /s {scr}')
try:
# Launch the .bat.
with open(devnull,'w') as null:
process = Popen(bat)
process.communicate(input='x'.encode())[0]
print(f"\nSuccessful processing for {nbdwg} files.")
except:
print("\nProcessing Failure. Check your script.")
except:
print("\nWriting Failure. Check your permissions.")
else:
print("\n->Abort, no dwg or Unknown Error.<-")
accore()
# pyinstaller --noconsole --onefile ACCORE.py