2013-08-12 34 views
0

运行AutoCAD脚本文件,我使用下面的代码打开AutoCAD文件:编程方式使用VB6

Dim DwgName As String 
On Error Resume Next 
Set acadApp = GetObject(, "AutoCAD.Application") 
If Err Then 
    Set acadApp = CreateObject("AutoCAD .Application") 
    Err.Clear 
End If 

Set acadDoc = acadApp.ActiveDocument 
If acadDoc.FullName <> DwgName Then 
    acadDoc.Open DwgName 
End If 

Dim str As String, str1 As String 
str1 = "_-insert" & vbLf & """" & "C:\AZ665.dwg" & """" & vbLf & "0,0,0" & vbLf & vbLf & vbLf & vbLf & "z" & vbLf & "a" & vbLf 
acadDoc.SendCommand str1 
acadApp.Visible = True 

以上代码的工作fine.But每次我都以做任何更改,打造“STR1”字符串。因此,我在“.scr”文件中写入scipt,但无法调用此文件。 请帮忙。

+0

你可以发表你的.scr的文件吗? – rags

+0

什么版本的autocad? –

回答

0

我发现下面的解决方案的字符串:

acadDoc.SendCommand "_script" & vbCr & ScriptFilePath & vbCr 
0

下面的代码将读取一个.scr的文件,并创建你需要为你SendCommand

Dim strData as string 
x = FreeFile 
Open "myscript.scr" For Input As #x 

Do 
    Line Input #x, strData 
    str1 = str1 & strData & vbNewLine 
    If EOF(x) Then Exit Do 
Loop 

Close #x