没注意,原来我仅有的俩明经币是狐哥给的。既然那么给力,我就再贴出我最新的调试方法。如下:
启动的外部程序为下面的代码编写的debug.exe程序。只需将生产dll的名字改为你命令的名字+数字即可。比如
- Imports Autodesk.AutoCAD.Runtime
- Public Class Class1
- <CommandMethod("xxx")> _
- Public Sub xxx()
- End Sub
- End Class
你的命令是XXX,那么生产编译程序的时候,在“应用程序”—“程序集名称”里面将生产dll名称改为 “xxx 数字”即可,我用正则来判断的,当然你可以任意发挥。CAD一直保持打开状态,然后 启动调试(F5),调试后,直接切到CAD窗口,按 空格键即可查看效果。重复调试只需更改数字就行了。下面是debug.exe的源码(vb.net)及工程:- Imports System.IO
- Public Class Form1
- Public Function SortbycreateTime(ByVal x As String, ByVal y As String) As Integer
- Dim xinfo As New FileInfo(x)
- Dim yinfo As New FileInfo(y)
- Return -xinfo.CreationTime.CompareTo(yinfo.CreationTime)
- End Function
- Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
-
- Me.Hide()
- Me.Dispose(True)
- End
- End Sub
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Dim Mpath As String = My.Computer.FileSystem.CurrentDirectory
- Dim Mdlls As String() = Directory.GetFiles(Mpath, "*.dll")
- Array.Sort(Mdlls, AddressOf SortbycreateTime)
- Dim Filestr As String = Mdlls(0)
- Dim Myinfo As New FileInfo(Filestr)
- Dim Mcmd As String = System.Text.RegularExpressions.Regex.Replace(Myinfo.Name, "\d*\.dll$", "")
- ' MsgBox(Mcmd)
- If Filestr <> "" Then
- Dim acadApp As Object = GetObject(, "AutoCAD.Application")
- Dim AcadD As Object = acadApp.ActiveDocument
- Dim Mnet As String = Replace(Filestr, "", "/")
- AcadD.SetVariable("FILEDIA", 0)
- AcadD.SendCommand("(command " & Chr(34) & "netload" & Chr(34) & Chr(34) & Mnet & Chr(34) & ")" & Chr(13))
- AcadD.SetVariable("FILEDIA", 1)
- AcadD.SendCommand(Mcmd)
- AcadD = Nothing
- acadApp = Nothing
- End If
- End Sub
- End Class
注意,最好不要开多个CAD.我一直用的是CAD2012调试的,VS2010。
|