在 cadjiaohu.Form1.查询ToolStripMenuItem1_Click(Object sender, EventArgs e) 位置 E:\vs\cadjiaohu\Form1.cs:行号 113
只能说到里了,你也不贴有用的代码,这些代码什么也看不出来?

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using Autodesk.AutoCAD.Interop;
    using Autodesk.AutoCAD.Interop.Common;
    using System.Reflection;
    using Microsoft.VisualBasic.ApplicationServices;
    namespace cadjiaohu
    {
        public partial class Form1 : Form
        {
            AcadLine returnLine;
            AcadPoint returnPointObj;
            AcadBlockReference returnBlock;
            AcadCircle returncircle;
            AcadText returnTextObj;
            AcadMText returnMTextObj;
            AcadSpline returnSpline;
            AcadLWPolyline returnPolyLine;
            AcadSelectionSet mySelectionSet;
            public Int16[] FilterType= new Int16[4]{0,0,0,0}; 
            public object[] FilterData= new object[4]{"*","*","*","*"};
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                try
                {
                    chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
                }
                catch
                {
                    chuangkou = new AcadApplication();
                }
                finally
                {
                    wenjian = chuangkou.ActiveDocument;
                    chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
                    chuangkou.Visible = true;
                    Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
                }
            }        private void chuangkou_BeginQuit(ref bool Cancel)
            {
                    chuangkou = null;
                    wenjian = null;
                    MessageBox.Show("结束了CAD程序");
            }        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
            {            DialogResult jieguo;
                jieguo = openFileDialog1.ShowDialog();
                if (jieguo == DialogResult.OK)
                {
                    if (openFileDialog1.FileName == null)
                        MessageBox.Show("请选择有效的文件");
                    else
                    {
                        try
                        {
                            chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
                        }
                        catch
                        {
                            chuangkou = new AcadApplication();
                        }
                        finally
                        {
                            chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
                            chuangkou.Visible = true;
                            Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
                        }
                        chuangkou.Application.Visible = true;
                        wenjian = chuangkou.Documents.Open(openFileDialog1.FileName, null, null);
                        chuangkou.BeginQuit+=new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
                    }
                }
                Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
            }        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                chuangkou.Quit();
                wenjian.Close(null,null);
            }        private void 查询ToolStripMenuItem1_Click(object sender, EventArgs e)
            {
                richTextBox1.Text = "";
                object ReturnObj=new object ();
                object pickPoint=new object ();
                string pickPrompt = "选取对象";
                 wenjian.Utility.GetEntity(out ReturnObj, out pickPoint, pickPrompt);
      

  2.   

    本人刚学习c#对cad的ActiveX Automation技术开发!
    想通过wenjian.Utility.GetEntity(out ReturnObj, out pickPoint, pickPrompt);获得cad中的对象(wenjian是定义的ducoment对象),出现未处理 System.Runtime.InteropServices.COMException
      Message="灾难性故障 (异常来自 HRESULT:0x8000FFFF (E_UNEXPECTED))"
      Source="Autodesk.AutoCAD.Interop"
      ErrorCode=-2147418113
      StackTrace:
      在 Autodesk.AutoCAD.Interop.AcadUtilityClass.GetEntity(Object& Object, Object& PickedPoint, Object Prompt)
      在 cadjiaohu.Form1.查询ToolStripMenuItem1_Click(Object sender, EventArgs e) 位置 E:\vs\cadjiaohu\Form1.cs:行号 113
      在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
      在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
      在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
      在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
      在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      在 System.Windows.Forms.Control.WndProc(Message& m)
      在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
      在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
      在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
      在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
      在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.Run(Form mainForm)
      在 cadjiaohu.Program.Main() 位置 E:\vs\cadjiaohu\Program.cs:行号 18
      InnerException:  
    错误!望高手解答啊!不胜感激啊!
    代码如下:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using Autodesk.AutoCAD.Interop;
    using Autodesk.AutoCAD.Interop.Common;
    using System.Reflection;
    using Microsoft.VisualBasic.ApplicationServices;
    namespace cadjiaohu
    {
      public partial class Form1 : Form
      {
      AcadLine returnLine;
      AcadPoint returnPointObj;
      AcadBlockReference returnBlock;
      AcadCircle returncircle;
      AcadText returnTextObj;
      AcadMText returnMTextObj;
      AcadSpline returnSpline;
      AcadLWPolyline returnPolyLine;
      AcadSelectionSet mySelectionSet;
      public Int16[] FilterType= new Int16[4]{0,0,0,0};  
      public object[] FilterData= new object[4]{"*","*","*","*"};
      public Form1()
      {
      InitializeComponent();
      }  private void Form1_Load(object sender, EventArgs e)
      {  }  private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
      {
      try
      {
      chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
      }
      catch
      {
      chuangkou = new AcadApplication();
      }
      finally
      {
      wenjian = chuangkou.ActiveDocument;
      chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
      chuangkou.Visible = true;
      Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
      }
      }  private void chuangkou_BeginQuit(ref bool Cancel)
      {
      chuangkou = null;
      wenjian = null;
      MessageBox.Show("结束了CAD程序");
      }  private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
      {  DialogResult jieguo;
      jieguo = openFileDialog1.ShowDialog();
      if (jieguo == DialogResult.OK)
      {
      if (openFileDialog1.FileName == null)
      MessageBox.Show("请选择有效的文件");
      else
      {
      try
      {
      chuangkou = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
      }
      catch
      {
      chuangkou = new AcadApplication();
      }
      finally
      {
      chuangkou.BeginQuit += new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
      chuangkou.Visible = true;
      Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
      }
      chuangkou.Application.Visible = true;
      wenjian = chuangkou.Documents.Open(openFileDialog1.FileName, null, null);
      chuangkou.BeginQuit+=new _DAcadApplicationEvents_BeginQuitEventHandler(chuangkou_BeginQuit);
      }
      }
      Microsoft.VisualBasic.Interaction.AppActivate(chuangkou.Caption);
      }  private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
      {
      chuangkou.Quit();
      wenjian.Close(null,null);
      }  private void 查询ToolStripMenuItem1_Click(object sender, EventArgs e)
      {
      richTextBox1.Text = "";
      object ReturnObj=new object ();
      object pickPoint=new object ();
      string pickPrompt = "选取对象";
      wenjian.Utility.GetEntity(out ReturnObj, out pickPoint, pickPrompt);