public static void AddKCDJPL()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "文本文件|*.txt";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string dataPath = openFileDialog.FileName;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
string[] pts = File.ReadAllLines(dataPath, Encoding.UTF8);
for (int i = 12; i < pts.Length; i++)
{
string txtLine = pts[i];
if (txtLine.Contains("@"))
{
Polyline pl = new Polyline();
string[] ss = txtLine.Split(new char[] { ',' });
string countStr = ss[0];
int jdCount = Convert.ToInt32(countStr);
string dkName = ss[3];
DBText text = new DBText();
text.Height = 50;
text.TextString = dkName;
int k = 0;
for (int j = i + 1; j < i + 1 + jdCount; j++)
{
string ptLine = pts[j];
string[] ptStr = ptLine.Split(new char[] { ',' });
string dhStr = ptStr[0];
string xStr = ptStr[3];
string yStr = ptStr[2];
double x = double.Parse(xStr);
double y = double.Parse(yStr);
text.Position = new Point3d(x, y, 0);
pl.AddVertexAt(k, new Point2d(x, y), 0, 0, 0);
k++;
}
pl.Closed = true;
pl.ColorIndex = 1;
AddEntity.AddEntToModeSpace(db, pl);
AddEntity.AddEntToModeSpace(db, text);
}
else
{
continue;
}
}
trans.Commit();
}
}
}