CAD 审图意见的导出

看图的时候喜欢在图上直接标注意见,但是如果还要再把意见一行一行的导出到word里面就很麻烦,在网上看了一个审图软件,报价要980,而且那个审图意见做的太复杂了。

我的需求就是把图上标的单行文字和多行文字直接导出来就行,因此,采用C#写了这个程序。

不多说,直接上图,上代码。

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using System.Xml.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System.IO;

namespace dcyj
{
    public class Class1
    {

        //审图意见导出,内置了默认路径和默认图层,避免重复劳动
        [CommandMethod("stjjdc")]
        public void BlockInLayerCAD()
        {
            Document arcdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database arcdb = HostApplicationServices.WorkingDatabase;
            Editor ed = arcdoc.Editor;
            // 创建文本
            StreamWriter txtWtriter = new StreamWriter(Stream.Null);
            if (File.Exists("E:\\24审图意见\\temple_yjdc.txt"))
            {
                File.Delete("E:\\24审图意见\\temple_yjdc.txt");
            }
            String layerforexp = "00000styj";
            ed.WriteMessage("\n 先把文字都调整到00000图层,文本保持目录为:E:\\24审图意见\\temple_yjdc.txt");
            using (Transaction trans = arcdb.TransactionManager.StartTransaction())
            {              
                txtWtriter = File.AppendText("E:\\24审图意见\\temple_yjdc.txt");
                txtWtriter.WriteLine("以下意见详见CAD文件批注。");
                LayerTable lt = (LayerTable)trans.GetObject(arcdb.LayerTableId, OpenMode.ForRead);
                if (!(lt.Has(layerforexp)))
                {
                    ed.WriteMessage("\n 找不图层:00000styj,请先把文字都调整到00000styj图层");
                }
                else
                {
                    ed.WriteMessage("\n 已找到图层:00000styj");
                    BlockTableRecord ltr = (BlockTableRecord)trans.GetObject(arcdb.CurrentSpaceId, OpenMode.ForRead);
                    String stryj = "";
                    String enttype = "";
                    int index_YJ = 1;
                    foreach (ObjectId objectid in ltr)
                    {
                        Entity ent = (Entity)trans.GetObject(objectid, OpenMode.ForRead);
                        enttype= ent.GetType().Name;
                       // ed.WriteMessage("\n enttype是:"+ enttype);
                        if (enttype.Equals("MText")&&ent.Layer.Equals(layerforexp)) {
                            stryj = index_YJ+(ent as MText).Text.ToString();
                            txtWtriter.WriteLine(stryj);
                            ed.WriteMessage("\n 文字内容是:" + stryj);
                            index_YJ++;
                        }
                        else if (enttype.Equals("DBText") && ent.Layer.Equals(layerforexp))
                        {
                            stryj = index_YJ + (ent as DBText).TextString.ToString();
                            txtWtriter.WriteLine(stryj);
                            ed.WriteMessage("\n 文字内容是:" + stryj);
                            index_YJ++;
                        }
                    }
                } 
                trans.Commit();
                txtWtriter.Flush();
                txtWtriter.Close();
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值