shilei 发表于 2006-3-1 18:35:00

[求助]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
}
}

nasky 发表于 2006-6-6 12:25:00

<P>同样的问题我也发过了,这个论坛上都是牛人,这种事没人理啊....</P>

yangxi 发表于 2006-6-12 23:50:00

<P>你的 Acad.Documents.Open(...); 是怎么定义的,</P>
<P>我用下面的代码就可以:</P>
<P>AutoCAD.AcadApplication cad;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AutoCAD.AcadDocument AcadDoc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AutoCAD.AcadModelSpace AcadSpace;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cad = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.16");</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcadDoc = cad.Documents.Open(strFileName,false, null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcadSpace = AcadDoc.ModelSpace;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MessageBox.Show(AcadSpace.Count.ToString());</P>

myway0103 发表于 2006-6-15 21:47:00

<P>private&nbsp;&nbsp; AcadApplication a ;<BR>&nbsp;&nbsp;Autodesk.AutoCAD.Interop.AcadApplication a;<BR>&nbsp;&nbsp;Autodesk.AutoCAD.DatabaseServices.Database db;<BR>&nbsp;&nbsp;</P>
<P><BR>&nbsp;&nbsp;private void Form1_Load(object sender, System.EventArgs e)<BR>&nbsp;&nbsp;{&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;this.pt1.Text="1,1,1";<BR>&nbsp;&nbsp;&nbsp;&nbsp;this.pt2.Text="122,122,122";<BR>&nbsp;&nbsp;&nbsp;a = new AcadApplicationClass();</P>
<P>&nbsp;&nbsp;this.acadDoc=a.Documents.Open(@"c:\test.dwg", null, null);&nbsp; //本条语句自动打开一个图形文件<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;a.ZoomAll(); //图形文件实行全局缩放;</P>

zhouhuaiku 发表于 2006-6-23 10:29:00

<P>最好用autocad2006</P>
页: [1]
查看完整版本: [求助]c#打开ACAD图纸出错??