一直对AutoCAD的插件运行环境没有搞清楚,希望高手讲解一下。 我的代码如下,编译之后用netload加载到CAD2008中,执行到打开文件的时候,老是报致命错误,然后CAD2008退出了。 [CommandMethod("CloseXP", CommandFlags.Session)] public void StartWatch() { System.Windows.Forms.MessageBox.Show("测试开始", "开始监听!"); try { IPEndPoint e = new IPEndPoint(IPAddress.Any, 1234); Udp = new UdpClient(e); Udp.EnableBroadcast = true; Udp.BeginReceive(new AsyncCallback(Udp_ER), Udp); } catch { } } [CommandMethod("CloseXP1", CommandFlags.Session)] public static void OpenXP() { try { //此处老是报错 Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(fileName); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "打开文件出错!"); } } protected static string fileName; [CommandMethod("CloseXP2",CommandFlags.Session)] public static void Udp_ER(IAsyncResult ar) { byte[] msg = null; IPEndPoint addr = null; try { msg = Udp.EndReceive(ar, ref addr); Udp.BeginReceive(new AsyncCallback(Udp_ER), null); } catch (System.Exception ex) { } if (msg != null && msg.Length > 0) { //接受其他程序发送过来的网络信息,信息为:文件路径信息,绝对正确。 System.Windows.Forms.MessageBox.Show(Encoding.Default.GetString(msg), "收到信息!"); fileName = Encoding.Default.GetString(msg); OpenXP(); } } |