明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1454|回复: 3

[求助]启动CAD2009后无法指向工程

[复制链接]
发表于 2009-9-16 01:07 | 显示全部楼层 |阅读模式

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using System.Runtime.InteropServices;

private void Form1_Load(object sender, EventArgs e)
        {
            double a;
           
            string strProgId = "AutoCAD.Application";
            Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
            //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
            //Autodesk.AutoCAD.ApplicationServices.Application acAppComObj;
            //acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId);
            //Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();
        }

上述方法已经启动了CAD2009

但是下述方法则无法运行

private void Form1_Load(object sender, EventArgs e)
        {
            double a;
           
            string strProgId = "AutoCAD.Application";
            Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true);
            Autodesk.AutoCAD.ApplicationServices.Application acAppComObj;
            acAppComObj = (Autodesk.AutoCAD.ApplicationServices.Application)Marshal.GetActiveObject(strProgId);
            Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();
        }

而且只要定义了Autodesk.AutoCAD.ApplicationServices.Application acAppComObj就报错

未处理TypeInitializationException

<Module>的类型初始值设定项发生异常

发表于 2009-9-16 01:12 | 显示全部楼层

Autodesk.AutoCAD.ApplicationServices

NetApi只能生成类库,在Cad环境里用NetLoad命令或注册表方式加载

不能以应用程序的形式运行

看看基本教程先

而且ComApi和NetApi是两回事

 楼主| 发表于 2009-9-16 01:19 | 显示全部楼层

多谢多谢!这么晚还不睡

原来是这样,只能生成dll

那这么说.net用来做批量绘图之类的就没办法了,只能在CAD里面输命令,那能干什么事情啊,没什么用啊。不知道对不对。

还不如com.api,就是引用2009lib和ObjectDBX来进行编程更好,不知道.net.api 有什么优点。

发表于 2009-9-16 07:42 | 显示全部楼层

批量绘图用NetApi当然可以!

NetApi-》ObjectArx.Net

而且可以实现ComApi不可能或很难实现的功能,具体可以看看置顶mccad的帖子

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 13:37 , Processed in 0.139629 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表