本文主要是介绍C# Cad2016二次开发选择文本信息导出(六),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//选文本信息导出
[CommandMethod("getdata")]
public void getdata()
{// 获取当前文档和数据库Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;// 获取当前图形数据库的路径string path = db.Filename;// 提示用户选择文本PromptSelectionResult selectionResult = doc.Editor.GetSelection(new SelectionFilter(new TypedValue[] { new TypedValue((int)DxfCode.Start, "TEXT") }));if (selectionResult.Status == PromptStatus.OK){using (Transaction trans = db.TransactionManager.StartTransaction()){SelectionSet selection = selectionResult.Value;StreamWriter mydata = new StreamWriter(path + "文字信息.csv", append: true, Encoding.Default);string value = "图层,名称,X,Y,字高,颜色\t,";mydata.WriteLine(value);// 遍历选择集中的文本对象foreach (ObjectId id in selection.GetObjectIds()){DBText text = trans.GetObject(id, OpenMode.ForRead) as DBText;if (text != null){// 获取图层名称string layerName = text.Layer;//文本信息string textContent = text.TextString;// 获取文本坐标double xPos = text.Position.X;double yPos = text.Position.Y;// 获取文本颜色int colorIndex = text.Color.ColorIndex;// 获取文本字高double textHeight = text.Height;//拼接CSV字符串value = layerName + "," + textContent + "," + xPos + "," + yPos + "," + textHeight + "," + colorIndex + "\t,";// 打印输入输出ed.WriteMessage("\n" + value);mydata.WriteLine(value);}}mydata.Close();// 打印输入输出ed.WriteMessage("\n导出完成");trans.Commit();}}
}
这篇关于C# Cad2016二次开发选择文本信息导出(六)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!