获取当前Civil3D文档中的图层信息,并保存到文件
[CommandMethod("GetLayerNames")]
public void GetLayerNames()
{
var list = new List<string>();
using (var tr = db.TransactionManager.StartTransaction())
{
var lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (var id in lt)
{
var ltr = tr.GetObject(id, OpenMode.ForRead) as LayerTableRecord;
list.Add($"{ltr.Name},{ltr.Color},{ltr.Description}");
}
tr.Commit();
}
var sfd = new SaveFileDialog();
sfd.InitialDirectory = @"C:\Users\Administrator\Desktop";
sfd.Title = "请选择要保存的位置:";
sfd.Filter = "TXT文件|*.txt|所有文件|*.*";
sfd.ShowDialog();
var path = sfd.FileName;
if (path == "") return;
using (var fsWrite = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
{
var sw = new StreamWriter(fsWrite);
foreach (var s in list) sw.WriteLine(s);
}
MessageBox.Show("保存成功!");
}