我有一个DWG文件,并在那里画了一些折线。
我想提取这些多边形的坐标,并将它们保存到csv中,使用系统。
在Autocad中可以做这样的事情吗?
布莱尼斯
发布于 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还有其他几个教程。您可以使用此示例代码启动项目。
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);
}
}
}
}https://stackoverflow.com/questions/48166560
复制相似问题