C# CAD创建点

C# CAD创建点_第1张图片

///创建点,DbEditTransaction是数据库编辑相关的处理器,doc是当前文档
 using (var trans = new DbEditTransaction(_doc.Database))
            {
                // 创建点,传入坐标
                DBPoint DBPoint = new DBPoint(new Point3d(100, 100, 50));

                // 控制点的显示外观
                _doc.Database.Pdmode = 35;
                _doc.Database.Pdsize = 5;

                //判断是否存在图层并解锁
                CheckLayer(_doc.Database, LayerInfo.LayerName_Tdz);

                DBPoint.ColorIndex = 1;
                trans.CreateEntity(DBPoint, LayerInfo.LayerName_Tdz, EnumSpaceMode.ModelSapce);

                trans.Commit();
            }

        //判断是否存在图层并解锁
        public void CheckLayer(Database db, string strLayerName)
        {
            //根据要素模型中定义的图层名称得到图层的设置模型
            LayerModel layerModel = AppConfigUtil.LayerConfig.Layers.FirstOrDefault(p => p.LayerName.Equals(strLayerName));
            if (layerModel == null)
            {
                throw new Exception($"配置错误:未找到图层名为{strLayerName}的LayerModel");
            }

            //创建图层
            using (var trans = new DbEditTransaction(db))
            {
                //判断图层是否存在
                bool hasLayer = trans.HasLayer(layerModel.LayerName);
                if (!hasLayer)
                {
                    //创建图层
                    trans.CreateLayer(layerModel.LayerName, layerModel.ColorIndex, layerModel.LineTypeName);
                }
                else
                {
                    //图层解锁
                    trans.UnlockLayer(layerModel.LayerName);
                }

                trans.Commit();
            }
        }

你可能感兴趣的:(笔记,cad,c#)