【问题标题】:Extracting northing easting using autocad使用AutoCAD提取北向东距
【发布时间】:2018-01-09 10:53:50
【问题描述】:

我有一个 DWG 文件,并在其中绘制了一些折线。

我想提取这些折线的坐标并使用东向北坐标系统将它们保存到 csv 中。

在 Autocad 中可以做类似的事情吗?

兄弟, 爱奥尼斯

【问题讨论】:

    标签: coordinates gis autocad


    【解决方案1】:

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

    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);
                }
            }
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 2019-07-05
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多