[求助]启动CAD2009后无法指向工程
<p>using System;<br/>using System.Collections.Generic;<br/>using System.ComponentModel;<br/>using System.Data;<br/>using System.Drawing;<br/>using System.Text;<br/>using System.Windows.Forms;<br/>using Autodesk.AutoCAD.Runtime;<br/>using Autodesk.AutoCAD.ApplicationServices;<br/>using System.Runtime.InteropServices;</p><p>private void Form1_Load(object sender, EventArgs e)<br/> {<br/> double a;<br/> <br/> string strProgId = "AutoCAD.Application";<br/> Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);<br/> //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);<br/> //Autodesk.AutoCAD.ApplicationServices.Application acAppComObj;<br/> //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId);<br/> //Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();<br/> }</p><p>上述方法已经启动了CAD2009</p><p>但是下述方法则无法运行</p><p>private void Form1_Load(object sender, EventArgs e)<br/> {<br/> double a;<br/> <br/> string strProgId = "AutoCAD.Application";<br/> Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);<br/> Autodesk.AutoCAD.ApplicationServices.Application acAppComObj;<br/> acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId);<br/> Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();<br/> }</p><p>而且只要定义了Autodesk.AutoCAD.ApplicationServices.Application acAppComObj就报错</p><p>未处理TypeInitializationException</p><p><Module>的类型初始值设定项发生异常</p><p></p> <p>Autodesk.AutoCAD.ApplicationServices</p><p>NetApi只能生成类库,在Cad环境里用NetLoad命令或注册表方式加载</p><p>不能以应用程序的形式运行</p><p>看看基本教程先</p><p>而且ComApi和NetApi是两回事</p> <p>多谢多谢!这么晚还不睡</p><p>原来是这样,只能生成dll</p><p>那这么说.net用来做批量绘图之类的就没办法了,只能在CAD里面输命令,那能干什么事情啊,没什么用啊。不知道对不对。</p><p>还不如com.api,就是引用2009lib和ObjectDBX来进行编程更好,不知道.net.api 有什么优点。</p> <p>批量绘图用NetApi当然可以!</p><p>NetApi-》ObjectArx.Net</p><p>而且可以实现ComApi不可能或很难实现的功能,具体可以看看置顶mccad的帖子</p>
页:
[1]