1、开发环境配置:

(1)安装AutoCAD2018;

(2)安装VS2015;

(3)安装ObjectARX 2018类库;

(4)安装ObjectARX 2018 .NET开发向导(ObjectARXWizards.msi)。

2、利用向导新建一个ObjectARX项目:File>NEW>project,在项目名称输入yunyou.ke.qq.com,确定。

3、确定后弹出如下对话框:

4、确定后生成项目:

5 、向导自动添加两个类,一个继承IExtensionApplication接口,这个是dll的入口,cad会从这个类加载程序做一些初始化的操作;另外一个可以写自定义的一些cad命令。

6、添加COM库的应用。

7、在“myplugin”中补充如下的命名空间引用。

using Autodesk.AutoCAD.Windows;

using AutoCAD;//com库

8、myplugin.cs代码修改如下:

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using AutoCAD;//com库

// This line is not mandatory, but improves loading performances
[assembly: ExtensionApplication(typeof(yunyou.ke.qq.com_1.MyPlugin))]

namespace yunyou.ke.qq.com
{

    // This class is instantiated by AutoCAD once and kept alive for the
    // duration of the session. If you don't do any one time initialization
    // then you should remove this class.
    public class MyPlugin : IExtensionApplication
    {

        void IExtensionApplication.Initialize()
        {
            //加载dll的时候执行相关加载操作
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("\n加载 云幽学院 yunyou.ke.qq.com\n");
            load();
        }

        void IExtensionApplication.Terminate()
        {
            //这个是推出时执行
            Document doc = Application.DocumentManager.MdiActiveDocument;
            doc.LockDocument(DocumentLockMode.NotLocked, "", "", false);
        }

        private void load()
        {
            //这里添加一个工具条,添加一个按钮绑定下面的MyCommand命令
            //这个是通过com组件实现需要引用cad的两个com组件.
            AcadMenuGroups menugroups = (AcadMenuGroups)Application.MenuGroups;
            AcadToolbar toolbar = menugroups.Item().Toolbars.Add("云幽学院 yunyou.ke.qq.com");
            AcadToolbarItem item = toolbar.AddToolbarButton(toolbar.Count, "MyCommand", "云幽学院MyCommand", "MyCommand\n");
            item.SetBitmaps("16x16.bmp", "32x32.bmp");
            toolbar.Dock(AcToolbarDockStatus.acToolbarDockTop);
        }
    }
}

7、Mycommand.cs

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(yunyou.ke.qq.com_1.MyCommands))]

namespace yunyou.ke.qq.com_1
{

    // This class is instantiated by AutoCAD for each document when
    // a command is called by the user the first time in the context
    // of a given document. In other words, non static data in this class
    // is implicitly per-document!
    public class MyCommands
    {
        // Modal Command with localized name
        [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]//特性标识,标识这个是cad命令
        public void Init()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("云幽学院 yunyou.ke.qq.com\n");

        }
      }
}

10、调试,在项目属性中,设置调试->启动外部程序,指定cad的启动路径,指定工作目录为当前程序的生成目录,既可调试。这里每次调试后,都要在启动cad后,通过netload命令加载dll,避免复杂调试、用自己的程序启动AutoCAD 并加载自己开发应用程序等高级方法请见云幽学院的视频课程 yunyou.ke.qq.com 。

使用.NET开发AutoCAD——C#/AutoCAD 2018/ObjectArx/二次开发入门(二)的更多相关文章

  1. VC++开发AutoCAD 2018/objectARX 用向导新建项目无法新建的问题

    话说笔者最近想用新机子上装的AutoCAD ObjectARX 2018来进行二次开发,兴致勃勃安装了ARX API和向导, 然后打开VS2015,新建项目,无法新建. 折腾了一下,还是没有解决,后面 ...

  2. C#/AutoCAD 2018/ObjectArx/二次开发添加圆对象的的例子(五)

    C#/AutoCAD 2018/ObjectArx/二次开发添加圆对象的的例子(五) 1.创建一个图形对象的步骤如下见上一篇博客(三)2.添加删除实体的工具函数见上一篇博客(四) 3.添加圆的例子(完 ...

  3. C#/AutoCAD 2018/ObjectArx/二次开发添加删除实体的工具函数(四)

    1.添加删除实体 C# ObjectARX二次开发添加删除实体是非常容易主要代码如下: 添加实体: objId = btr.AppendEntity(entity); trans.AddNewlyCr ...

  4. C#/AutoCAD 2018/ObjectArx/二次开发添加图形对象步骤和添加直线的例子(三)

    1.创建一个图形对象的步骤如下(1)得到创建对象的图形数据库:(2)在内存中创建实体类的一个对象:(3)定义一个指向当前数据库的事务处理:(4)打开图形数据库的块表:(5)打开一个存储实体的块表记录( ...

  5. AutoCAD二次开发-使用ObjectARX向导创建应用程序(HelloWorld例子)

    AutoCAD2007+vs2005 首先自己去网上搜索下载AutoCAD2007的ARX开发包. 解压后如下 打开后如下 classmap文件夹为C++类和.net类的框架图,是一个DWG文件. d ...

  6. AutoCad 二次开发 .net 之创建Table

    我使用了COM对象来在cad2018中创建table表格,需要的ObjectArx开发包可以在官网上下载,并且需要使用.netframework4.6的库才行. 项目里除了引用常规的Cad开发dll, ...

  7. 利用C#进行AUTOCAD的二次开发

    众所周知,对AutoCAD进行二次开发用到的主要工具有:ObjectArx,VBA,VLisp.但它们的优缺点是显而易见的:ObjectArx功能强大,编程效率高,但它的缺点是编程者必须掌握VC++, ...

  8. AutoCAD二次开发——AutoCAD.NET API开发环境搭建

    AutoCAD二次开发工具:1986年AutoLisp,1989年ADS,1990年DCL,1993年ADS-RX,1995年ObjectARX,1996年Active X Automation(CO ...

  9. 1,下载和部署开发环境--AutoCAD二次开发

    环境需求为: AutoCAD 2020版 ObjectARX SDK 下载地址:https://www.autodesk.com/developer-network/platform-technolo ...

  10. AutoCad 二次开发 文字镜像

    AutoCad 二次开发 文字镜像 参考:https://adndevblog.typepad.com/autocad/2013/10/mirroring-a-dbtext-entity.html 在 ...

随机推荐

  1. ClassLoader原理

    ClassLoader原理 JVM规范定义了两种类型的类装载器:启动内装载器 (bootstrap) 和用户自定义装载器 (user-defined class loader) . 一.    Cla ...

  2. Linux显示使用者将不能利用交谈式指令来对行程

    Linux显示使用者将不能利用交谈式指令来对行程 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ top -s top - 19:23:34 up 52 min ...

  3. 使用vue-cli脚手架初始化Vue项目下的项目结构

    概述 vue-cli是Vue 提供的一个官方命令行工具,可用于快速搭建大型单页应用.该工具提供开箱即用的构建工具配置,带来现代化的前端开发流程.只需几分钟即可创建并启动一个带热重载.保存时静态检查以及 ...

  4. CentOS时钟同步服务器

    ①本地时钟服务器需要安装chrony服务,可以通过yum.rpm.源码包安装,chrony支持C/S模式 ②编辑本地时钟服务,使其指向提供标准时间服务器,例如:中国国家授时中心NTP服务器. 修改配置 ...

  5. NVIDIA Geforce GT 730 OpenGL 图形显示异常花屏

    原因:C盘空间爆表,用dism++清理.结果用力过猛,清完后程序里的图形直接马赛克了... 上个图感受一下吧... 嘿别说,还有那么点艺术风! 别闹了,这个问题很严重,很严肃好不好! 因为程序和数据都 ...

  6. Flutter 初尝:从 Java 无缝过渡

    准备阶段 下载 Flutter SDK 新建 Flutter 文件夹,克隆 Flutter SDK: git clone -b beta https://github.com/flutter/flut ...

  7. UVA10294 Arif in Dhaka (群论,Polya定理)

    UVA10294 Arif in Dhaka (群论,Polya定理) 题意 : 给你一个长为\(n\)的项链和手镯,每个珠子有\(m\)种颜色. 两个手镯定义为相同,即它们通过翻转和旋转得到一样的手 ...

  8. 【BZOJ4538】【HNOI2016】网络(树链剖分,线段树,堆)

    题目链接,我是真的懒得调题目的格式... 题解 树链剖分搞一下LCA 把线段树弄出来 这只是形式上的线段树 本质上是维护一段区间的一个堆 每次把堆插入节点, 询问的时候查询线段树上的堆的最大值就行了 ...

  9. LightOJ1245 Harmonic Number (II)

    题意 \(求\Sigma \lfloor \frac{n}{i} \rfloor\) Input starts with an integer T (≤ 1000), denoting the num ...

  10. 打造MacOS版“XShell”

    1.背景 XShell作为一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议.作为server端开发,几乎是必备工具了. 很多刚 ...