-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautolisp.bat
146 lines (125 loc) · 3.97 KB
/
autolisp.bat
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
::'@cscript //nologo //e:vbscript "%~f0" %* & @goto :eof
' This file is a batch and vbscript hybrid.
' To function properly it must contain SUB character (0x1A)
' right after the ::' characters in the first line.
' Loads LISP file to an executed AutoCAD/BricsCAD/IntelliCAD application.
' Usage: autolisp [opions] filename
Const ha_AutoCAD = 1
Const ha_BricsCAD = 2
Const ha_IntelliCAD = 3
Dim happ
happ = ha_AutoCAD
Class AutoLisp
Private App, VLApp
Private HostApp
Public Default Function Init(happ)
HostApp = happ
Dim progID
Select Case HostApp
Case ha_AutoCAD
progID = "AutoCAD.Application"
Case ha_BricsCAD
progID = "BricscadApp.AcadApplication"
Case ha_IntelliCAD
progID = "ICAD.Application"
Case Else
Die "Init: Unsupported CAD application."
End Select
On Error Resume Next
' Set App = WScript.GetObject(, progID, "AcadApp_") ' Should allow event handling
Set App = GetObject(, progID)
If App Is Nothing Then
Die "Cannot connect to CAD application."
End If
If HostApp = ha_AutoCAD Then
Set VLApp = App.GetInterfaceObject("VL.Application.16")
If VLApp Is Nothing Then
Die "Cannot connect to VisualLISP module."
End If
End If
On Error Goto 0
Set Init = Me
End Function
' Private Sub Class_Initialize
' End Sub
Private Sub Class_Terminate
Set VLApp = Nothing
Set App = Nothing
End Sub
Private Function ActiveDocument()
Dim doc
On Error Resume Next
Set doc = App.ActiveDocument
If doc Is Nothing Then
Die "Cannot get active CAD document."
End If
On Error Goto 0
Set ActiveDocument = doc
End Function
Public Sub Load(filename)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(filename) Then
Die "Cannot find the file specified."
End If
filename = Replace(fso.GetAbsolutePathName(filename), "\", "/")
Dim doc
Set doc = ActiveDocument ' Test if there is an ActiveDocument
Select Case HostApp
Case ha_AutoCAD
VLApp.ActiveDocument.Functions.Item("load").funcall(CStr(filename))
Case ha_BricsCAD
ActiveDocument.EvaluateLisp _
"(eval (read """ & _
"(load \""" & filename & "\"")" & _
"""))"
Case ha_IntelliCAD
App.LoadLISP(filename)
Case Else
Die "Load: Unsupported CAD application."
End Select
Set doc = Nothing
End Sub
End Class
Sub Die(msg)
WScript.Echo "AutoLISP: " & msg
WScript.Quit(1)
End Sub
Sub Help()
WScript.Echo "Usage: autolisp [options] filename"
WScript.Echo
WScript.Echo " -h, --help Show this help"
WScript.Echo " --acad Use AutoCAD as a host application"
WScript.Echo " --bcad Use BricsCAD as a host application"
WScript.Echo " --icad Use IntelliCAD as a host application"
WScript.Quit()
End Sub
If WScript.Arguments.Count = 0 Then
Die "No LISP file specified."
Else
Dim arg, i
For i = 0 To WScript.Arguments.Count - 1
arg = WScript.Arguments(i)
If Left(arg, 1) = "-" Then
Select Case arg
Case "-h", "--help"
Help
Case "--acad"
happ = ha_AutoCAD
Case "--bcad"
happ = ha_BricsCAD
Case "--icad"
happ = ha_IntelliCAD
Case Else
Die "Bad option: " & arg
End Select
Else
Dim filename
filename = arg
End If
Next
End If
Dim al
Set al = (New AutoLisp)(happ)
al.Load filename
Set al = Nothing