1 Star 1 Fork 178

徐雷 / IFoxCAD

forked from InspireFunction / IFoxCAD 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

IFoxCAD

介绍

基于.NET的Cad二次开发类库。

可以加群交流:

ifoxcad用户交流群群二维码

软件架构及相关说明

安装教程

  1. vs新建net standard 类库
  2. 修改项目TargetFramework为net45,保存重加载项目
  3. 右键项目,管理nuget程序包,搜索ifoxcad,安装最新版就可以了

使用说明

  1. 快速入门

    • 打开vs,新建一个standard类型的类库项目,注意,需要选择类型的时候一定要选standord2.0

    • 双击项目,打开项目文件:

      • 修改项目文件里的<TargetFramework>netcore2.0</TargetFramework><TargetFrameworks>NET45</TargetFrameworks>。其中的net45,可以改为NET45以上的标准TFM(如:net45、net46、net47等等)。同时可以指定多版本。具体的详细的教程见 VS通过添加不同引用库,建立多条件编译

      • <PropertyGroup> xxx </PropertyGroup> 中增加 <LangVersion>preview</LangVersion>,主要是为了支持最新的语法,本项目采用了最新的语法编写。项目文件现在的内容类似如下:

      <Project Sdk="Microsoft.NET.Sdk">
         <PropertyGroup>
             <TargetFramework>net45</TargetFramework>
             <LangVersion>preview</LangVersion>
         </PropertyGroup>
      </Project>
    • 右键项目文件,选择管理nuget程序包。

    • 在nuget程序里搜索ifoxcad,直接选择最新的版本(如果你是 net40 或者 net35 的用户,可以安装 0.1.6 版本),然后点击安装IFoxCAD.Cad,nuget会自动安装ifoxcad依赖的库。(按下图绿色框框里选择浏览,程序包来源选择nuget.org,安装IFoxCAD.Cad包。IFoxCAD.Basal是IFoxCAD.Cad的依赖项会自动安装,如果要开发wpf界面的话,可以安装IFoxCAD.WPF,提供了简单的mvvm支持)

    • 添加引用

    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.DatabaseServices;
    using IFoxCAD.Cad;
    • 添加代码
    [CommandMethod("hello")]
    public void Hello()
    {
     using var tr = new DBTrans();
     var line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));
     tr.CurrentSpace.AddEntity(line1);
     // 如果你没有添加<LangVersion>preview</LangVersion>到项目文件里的话:按如下旧语法:
     // using(var tr = new DBTrans())
     // {
     //     var line1 = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));
     //     tr.CurrentSpace.AddEntity(line1);
     // }
    }

    这段代码就是在cad的当前空间内添加了一条直线。

    • F6生成,然后打开cad,netload命令将刚刚生成的dll加载。

    • 运行hello命令,然后缩放一下视图,现在一条直线和一个圆已经显示在屏幕上了。

  2. 事务管理器用法

  3. 选择集过滤器用法

  4. 符号表用法

  5. WPF支持

  6. 天秀的自动加载与初始化

    为了将程序集的初始化和通过写注册表的方式实现自动加载统一设置,减少每次重复的工作量,内裤提供了AutoRegAssem抽象类来完成此功能,只要在需要初始化的类继承AutoRegAssem类,然后实现Initialize()Terminate()两个函数就可以了。特别强调的是,一个程序集里只能有一个类继承,不管是不是同一个命名空间。

     using Autodesk.AutoCAD.Runtime;
     using IFoxCAD.Cad;
     using System;
     using System.Reflection;
     [assembly: ExtensionApplication(typeof(CadLoad.CmdINI))]
     namespace CadLoad
     {
         internal class CmdINI : AutoRegAssem
         {
             public override void Initialize()
             {
                 throw new NotImplementedException();
             }
    
             public override void Terminate()
             {
                 throw new NotImplementedException();
             }
         }
     }
  7. 天秀的打开模式提权

    由于cad的对象是有打开模式,是否可写等等,为了安全起见,在处理对象时,一般是用读模式打开,然后需要写数据的时候在提权为写模式,然后在降级到读模式,但是这个过程中,很容易漏掉某些步骤,然后cad崩溃。为了处理这些情况,内裤提供了提权类来保证读写模式的有序转换。

    using(line.ForWrite()) //开启对象写模式提权事务
    {
      //处理代码
    } //关闭事务自动处理读写模式
  8. 未完待续。。。。

MIT License Copyright (c) 2021 InspireFunction Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于.NET的Cad二次开发类库 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/xulei112233/ifoxcad.git
git@gitee.com:xulei112233/ifoxcad.git
xulei112233
ifoxcad
IFoxCAD
develop

搜索帮助

53164aa7 5694891 3bd8fe86 5694891