-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocad_batch_scr.py
105 lines (89 loc) · 2.46 KB
/
autocad_batch_scr.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 22 00:38:48 2013
@author: Dawid Huczyński
"""
import os
'''
This is just info for acad.exe functions:
/b Script name (b stands for batch process)
/c Configuration folder
/ld ARX or DBX application
/nohardware Disables hardware acceleration
/nolisp Disables AutoLISP execution (2013 SP1.1)
/nologo No product logo screen
/nossm No Sheet Set Manager window
/p User-defined registry profile for starting the program
/pl Background plotting/publishing prints off the drawings listed in a DSD file created with Publish
/r Default system pointing device
/s Support folders
/set Sheet set
/t Template file name
/v View name
/w Default workspace
/automation – used with programming automation
/layout – loads a layout with the specified drawing
'''
# SCRIPT = '''FILEDIA
# 0
# PURGE
# A
# *
# N
# AUDIT
# Y
# SAVEAS
# 2004
# C:\test.dwg
# Y
# QUIT
#
# '''
ACAD_EXE_PATH = False
WDIR = '\\\\R2srv\\projekty\\DĄBKI\\PROJEKT\\PB\\WYDANIA\\170607-BUD HOTELOWE DLA PPOŻ'
SCRIPT = '''FILEDIA
0
-LAYER
OFF
A-WYBURZENIA
FIND
SAVEAS
2007
Y
QUIT
'''
def findACAD():
for p, d, f in os.walk('c:\\'):
if 'acad.exe' in f:
print(p + '\\acad.exe')
return (p + '\\acad.exe')
if 'acadlt.exe' in f:
print(p + '\\acadlt.exe')
return (p + '\\acadlt.exe')
def createScript(SCRIPT, FILE_DWG):
tmpDWG = open('SCRIPT.scr', 'w')
tmpDWG.write(SCRIPT)
tmpDWG.close()
def runDWG(FILE_DWG, ACAD_EXE_PATH, WDIR):
path, cad = ACAD_EXE_PATH.rsplit('\\', 1)
os.chdir(path)
print(FILE_DWG)
# print(cad + ' "' +
# os.path.join(WDIR, FILE_DWG) +
# '" /nologo /nossm /b "' +
# os.path.join(WDIR, 'SCRIPT.scr') + '"')
os.system(cad + ' "' +
os.path.join(WDIR, FILE_DWG) +
'" /nologo /nossm /b "' +
os.path.join(WDIR, 'SCRIPT.scr') + '"')
os.chdir(WDIR)
os.remove('SCRIPT.scr')
if __name__ == '__main__':
if ACAD_EXE_PATH is False:
ACAD_EXE_PATH = findACAD()
os.chdir(WDIR)
for f in os.listdir(WDIR):
if f.endswith('.dwg') and not f.endswith('-P.dwg'):
# print(f)
createScript(SCRIPT, os.path.join(WDIR, f))
runDWG(f, ACAD_EXE_PATH, WDIR)