[求助]c#打开ACAD图纸出错??
我在执行下面代码打autocad图纸时AcadDoc = Acad.Documents.Open(strFileName,false,null);
AcadSpace = AcadDoc.ModelSpace
在执行到第2句时
发生 {System.Runtime.InteropServices.COMException} 类型的异常
请教这个怎么办啊??
--------------------------------------
我用的是vs.net和autocad2004
using System;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using VBA;
using AutoCAD;
namespace FoTon.Ov.PDMSign
{
/// <summary>
/// AutoCAD签字组件(类)
/// </summary>
public class SignToDWG
{
#region AutoCAD签字过程
/// <summary>
/// AutoCAD签字过程
/// </summary>
/// <param name="strFileName">图纸名称(包括路径)</param>
/// <param name="strSignToName">签字名称</param>
/// <param name="Point">签字位置(相对标题框右下角)</param>
public static void SignProcess(string strFileName,string strSignContent,double[] Point)
{
AutoCAD.AcadDocument AcadDoc;
AutoCAD.AcadModelSpace AcadSpace;
AutoCAD.AcadBlockReference BlockRef;
double[] BlockPoint = new double;
double[] TxtXPointMin = new double;
AcadDoc = Acad.Documents.Open(strFileName,false,null);//打开一个AutoCAD文档,password为""
AcadSpace = AcadDoc.ModelSpace;//模型
.....
}
#endregion
}
}
<P>同样的问题我也发过了,这个论坛上都是牛人,这种事没人理啊....</P> <P>你的 Acad.Documents.Open(...); 是怎么定义的,</P>
<P>我用下面的代码就可以:</P>
<P>AutoCAD.AcadApplication cad;<BR> AutoCAD.AcadDocument AcadDoc;<BR> AutoCAD.AcadModelSpace AcadSpace;</P>
<P> cad = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.16");</P>
<P> AcadDoc = cad.Documents.Open(strFileName,false, null)<BR> AcadSpace = AcadDoc.ModelSpace;<BR> MessageBox.Show(AcadSpace.Count.ToString());</P> <P>private AcadApplication a ;<BR> Autodesk.AutoCAD.Interop.AcadApplication a;<BR> Autodesk.AutoCAD.DatabaseServices.Database db;<BR> </P>
<P><BR> private void Form1_Load(object sender, System.EventArgs e)<BR> { <BR> this.pt1.Text="1,1,1";<BR> this.pt2.Text="122,122,122";<BR> a = new AcadApplicationClass();</P>
<P> this.acadDoc=a.Documents.Open(@"c:\test.dwg", null, null); //本条语句自动打开一个图形文件<BR> <BR> a.ZoomAll(); //图形文件实行全局缩放;</P> <P>最好用autocad2006</P>
页:
[1]