• 大小: 0.02M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-03
  • 语言: C#
  • 标签: cad开发  

资源简介

CAD图框外扩

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//用于图形文件中对对象的操作
//当处理图形文件中存储的对象中
//acdbmgd.dll
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
//using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.layerManager;

//用于对AutoCad应用程序进行操作
//当处理AutoCad应用程序和用户接口时引用
//acmgd.dll
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Windows.ToolPalette;
using Autodesk.AutoCAD.Internal.Windows;
using Autodesk.AutoCAD.Internal.Forms;


namespace NetCad
{
    public static class AddEntity
    {
        #region
        /// 
        /// 向图形中添加单个实体
        /// 

        /// 图形数据库
        /// 图形对象
        /// 返回图形objectid
        public static objectId AddEntityToModelSpass(Database db Entity ent)
        {
            //声明一个objectid,用于返回,以便后期修改图形的颜色等等。
            objectId entId = objectId.Null;
            //开启事务处理
            Transaction trans = db.TransactionManager.StartTransaction();
            using (trans)
            {
                //打开块表
                BlockTable blkTbl = trans.Getobject(db.BlockTableId OpenMode.ForRead) as BlockTable;
                //打开块表记录
                BlockTableRecord blkTbRec = trans.Getobject(blkTbl[BlockTableRecord.ModelSpace] OpenMode.ForWrite) as BlockTableRecord;
                //添加图形到块表记录
                //AppendEntity()返回值是objectid
                entId = blkTbRec.AppendEntity(ent);
                //更新数据信息
                trans.AddNewlyCreatedDBobject(ent true);
                //提交事务
                trans.Commit();
            }
            return entId;
        }
        #endregion

        #region
        /// 
        /// 向图形中添加多个实体
        /// 

        /// 图形数据库
        /// 图形对象,可变参数
        /// objectID,数组返回
        public static objectId[] AddEntityToModelSpace(Database db params Entity[] ent)
        {
            objectId[] entId = new objectId[ent.Length];
            Transaction trans = db.TransactionManager.StartTransaction();
            using (trans)
            {
                BlockTable blkTbl = trans.Getobject(db.BlockTableId OpenMode.ForRead) as BlockTable;
                BlockTableRecord blkTblRec = trans.Getobject(blkTbl[BlockTableRecord.ModelSpace] OpenMode.ForWrite) as BlockTableRecord;

                for (int i = 0; i < ent.Length; i++)
                {
                    entId[i] = blkTblRec.AppendEntity(ent[i]);
                    trans.AddNewlyCreatedDBobject(ent[i] true);
                }

                trans.Commit();
            }
            return entId;
        }
        #endregion


    

评论

共有 条评论