请教 vb.net 向cad发送一个命令后,得到cad执行命令后在命令行输出的内容??
我正在尝试捕获AutoCAD的“List”命令的输出的文本。选择对象的List方法不返回任何内容,而是直接输出在命令行。
可以通过以下三个系统变量控制是否保存命令行信息,保存到指定文件。
LOGFILEMODE
LOGFILENAME
LOGFILEPATH
这是个例子,天正对象(很到属性我们不知道,程序也不好访问,只能通过list名称查看,但是程序怎么得到list查询的结果呢?)
Public Class tdb
<CommandMethod("tdb")> _
Public Sub TZBH()
On Error Resume Next
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acEditor As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
'过滤条件
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "TCH_OPENING"), 0)
'acTypValAr.SetValue(New TypedValue(DxfCode.Start, "BlockReference"), 0)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim acSSPrompt As PromptSelectionResult = acEditor.GetSelection(acSelFtr)
Dim acSSet As SelectionSet = acSSPrompt.Value
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim I As Long
For I = 0 To acSSet.Count - 1
Dim e As Entity = acTrans.GetObject(acSSet.Item(I).ObjectId, OpenMode.ForRead)
Application.SetSystemVariable("LOGFILEMODE", 1) 'Log开
e.List() '就是AutoCAD的list命令
Application.SetSystemVariable("LOGFILEMODE", 0) 'Log关
Dim LogPath As String = Application.GetSystemVariable("LOGFILENAME")
acDoc.Editor.WriteMessage(vbCrLf + LogPath)
MsgBox(LogPath)
Dim DataString As Object
DataString = ReadFile(LogPath)
Dim J As Int16 = UBound(DataString)
Dim N As Int16
Dim Str As String = ""
For N = J - 13 To J
Str = Str & vbCrLf & DataString(N)
Next
MsgBox(Str)
Next
acTrans.Commit()
End Using
MsgBox(Err.Source)
End Sub
Function ReadFile(ByVal Path As String) As Object
Dim DataString() As String = Nothing
Dim F As System.IO.StreamReader
F = FileIO.FileSystem.OpenTextFileReader(Path, System.Text.Encoding.Default)
Dim I As Long
Do While Not F.EndOfStream
ReDim Preserve DataString(I)
DataString(I) = F.ReadLine
I = I + 1
Loop
ReadFile = DataString
End Function
End Class
输入tdb命令后,选择天正的窗户,得到list查询的结果显示在msgbox中。
List<string> lines = Autodesk.AutoCAD.Internal.Utils.GetLastCommandLines(4, true);