CAD二次开发c#.Net编程 - 工具类集合

这个代码片段展示了如何在AutoCAD中进行一系列图形操作,包括创建新图层、镜像实体、管理块以及删除模型空间内的实体对象。此外,还提供了弧度和角度之间的转换方法。这些功能对于AutoCAD的编程和定制非常实用。

创建新图层

public static void CreateLayer(string LayerName)
        {
   
   
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;//获取当前数据库
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
   
   
                //以读的方式打开图层表
                LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                string sLayerName = LayerName;//设定一个图层名称
                if (acLyrTbl.Has(sLayerName) == false)
                {
   
   
                    using (LayerTableRecord acLyrTblRec = new LayerTableRecord())
                    {
   
   
                        acLyrTblRec.Name = sLayerName;// 指定图层名称
                        acLyrTbl.UpgradeOpen();//修改图层打开方式为写
                        acLyrTbl.Add(acLyrTblRec);//将新图层追加到图层表
                        acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
                    }
                }
                acTrans.Commit();
            }
        }

镜像CAD实体对象

 public static Entity MirrorEntity(this ObjectId entId, Point3d point1, Point3d point2, bool isEraseSource)
        {
   
   
            // 声明一个图形对象用于返回
            Entity entR;
            // 计算镜像的变换矩阵
            Matrix3d mt = Matrix3d.Mirroring(new Line3d(point1, point2));
            // 打开事务处理
            using (Transaction trans = entId.Database.TransactionManager.StartTransaction())
            {
   
   
                // 判断是否删除原对象
                if (isEraseSource)
                {
   
   
                    // 打开原对象
                    Entity ent = (Entity)trans.GetObject(entId, OpenMode.ForWrite);
                    // 执行变换
                    ent.TransformBy(mt);
                    entR = ent;
                }
                else
                {
   
   

                    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值