zoukankan      html  css  js  c++  java
  • CAD二次开发(01)-绘制直线

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.Runtime;
    
    namespace _01_LineD
    {
        public class Class1
        {
            [CommandMethod("LineDemo")]
            public void LineDemo()
            {
                Line line1 = new Line();//声明一个直线对象
                Point3d startPoint3D = new Point3d(100, 100, 0);//创建两个点
                Point3d endPoint3D = new Point3d(100, 200, 0);
                line1.StartPoint = startPoint3D;//设置属性
                line1.EndPoint = endPoint3D;
                //声明图形数据库对象
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                
                Line line2 = new Line(new Point3d(100, 200, 0), new Point3d(200, 200, 0));
                Line line3 = new Line(new Point3d(200, 200, 0), new Point3d(200, 100, 0));
                Line line4 = new Line(new Point3d(200, 100, 0), new Point3d(100, 100, 0));
                //开启事务处理
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);//打开块表
                    BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);//打开块表记录
                    btr.AppendEntity(line1);//加直线到块表记录
                    btr.AppendEntity(line2);//加直线到块表记录
                    btr.AppendEntity(line3);//加直线到块表记录
                    btr.AppendEntity(line4);//加直线到块表记录
                    trans.AddNewlyCreatedDBObject(line1, true);//更新数据
                    trans.AddNewlyCreatedDBObject(line2, true);//更新数据
                    trans.AddNewlyCreatedDBObject(line3, true);//更新数据
                    trans.AddNewlyCreatedDBObject(line4, true);//更新数据
                    trans.Commit();//提交事务
                }
            }
    
        }
    }
  • 相关阅读:
    1022. D进制的A+B (20)
    1032. 挖掘机技术哪家强(20)
    1001. 害死人不偿命的(3n+1)猜想 (15)
    结构-06. 复数四则运算(15)
    结构-05. 有理数均值(20)
    结构-04. 通讯录的录入与显示(10)
    结构-03. 平面向量加法(10)
    软考错题合集之13-05-AM
    软考笔记第八天之法律发规与标准化知识
    软考笔记第七天之程序设计语言与语言处理程序基础
  • 原文地址:https://www.cnblogs.com/civil/p/9045090.html
Copyright © 2011-2022 走看看