首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用autocad提取北斗

用autocad提取北斗
EN

Stack Overflow用户
提问于 2018-01-09 10:53:50
回答 1查看 688关注 0票数 0

我有一个DWG文件,并在那里画了一些折线。

我想提取这些多边形的坐标,并将它们保存到csv中,使用系统。

在Autocad中可以做这样的事情吗?

布莱尼斯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-19 10:09:30

您可以编写一个autocad .NET插件(c#),它遍历特定层的所有行,并将该行的每个点导出到csv。有关第一个示例,请参见https://knowledge.autodesk.com/support/autocad/learn-explore/caas/video/youtube/watch-v-5a50QULamuU.html。下面是一个基本示例,它创建了一个插件,可以通过命令"Action“启动该插件。但是线出口的部分丢失了。这个插件在每个图层中生成随机点和线条。autocad还有其他几个教程。您可以使用此示例代码启动项目。

代码语言:javascript
复制
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.Runtime;
using Autodesk.AutoCAD.Geometry;

[assembly: CommandClass(typeof(AcadLayerPlugin.LayerPlugin))]

namespace AcadLayerPlugin
{
    public class LayerPlugin
    {
        [CommandMethod("Action")]
        public static void Action()
        {

            //System.Windows.Forms.MessageBox.Show("Huhu");
            Database database = HostApplicationServices.WorkingDatabase;
            try
            {
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    SymbolTable symTable = (SymbolTable)transaction.GetObject(database.LayerTableId, OpenMode.ForRead);
                    foreach (ObjectId id in symTable)
                    {
                        LayerTableRecord symbol = (LayerTableRecord)transaction.GetObject(id, OpenMode.ForWrite);

                        //TODO: Access to the symbol
                        //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
                        // Open the Block table for read
                        BlockTable acBlkTbl;
                        acBlkTbl = transaction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable;

                        // Open the Block table record Model space for write
                        BlockTableRecord acBlkTblRec;
                        acBlkTblRec = transaction.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                        OpenMode.ForWrite) as BlockTableRecord;

                        // Create a line that starts at 5,5 and ends at 12,3
                        Random r = new Random();
                        Line acLine = new Line(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()),
                                               new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
                        acLine.LayerId = id;
                        Autodesk.AutoCAD.DatabaseServices.DBPoint point = new DBPoint(new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble()));
                        point.LayerId = id;

                        MText acMText = new MText();
                        acMText.Location = new Point3d(r.NextDouble(), r.NextDouble(), r.NextDouble());
                        acMText.Width = 8;
                        acMText.Contents = "Ohlsen was here.";
                        acMText.LayerId = id;

                        acBlkTblRec.AppendEntity(acLine);
                        acBlkTblRec.AppendEntity(point);
                        acBlkTblRec.AppendEntity(acMText);
                        transaction.AddNewlyCreatedDBObject(acLine, true);
                        transaction.AddNewlyCreatedDBObject(point, true);
                        transaction.AddNewlyCreatedDBObject(acMText, true);
                        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
                        // Save the new object to the database
                        transaction.Commit();
                    }

                    transaction.Commit();
                }
            }catch(System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48166560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档