绘制图形(线、圆、弧、多段线信息)
[CommandMethod("DrawEnt")]
public void DrawEnt()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
using (doc.LockDocument())
{
Database db = doc.Database;
Editor ed = doc.Editor;
string pathL = "Line.json";
string dataL = File.ReadAllText(pathL);
List<MyLine> myLines = JsonConvert.DeserializeObject<List<MyLine>>(dataL);
Line line = new Line();
var startXs = myLines.Select(x => x.StartX).ToList();
var startYs = myLines.Select(x => x.StartY).ToList();
var endXs = myLines.Select(x => x.EndX).ToList();
var endYs = myLines.Select(x => x.EndY).ToList();
var lineIndex = myLines.Select(x => x.ColorIndex).ToList();
var lineLayer = myLines.Select(x => x.Layer).ToList();
if (myLines.Count != 0)
{
for (int i = 0; i < startXs.Count; i++)
{
line = new Line(new Point3d(startXs[i], startYs[i], 0), new Point3d(endXs[i], endYs[i], 0));
this.AddLayer(lineLayer[i], lineIndex[i]);
line.Layer = lineLayer[i];
line.ColorIndex = lineIndex[i];
line.Color = Color.FromColorIndex(ColorMethod.ByLayer, (short)lineIndex[i]);
this.AddEntityToModeSpace(line, db);
}
}
string pathCirCle = "Cir.json";
string dataCirCle = File.ReadAllText(pathCirCle);
List<MyCircle> myCirCles = JsonConvert.DeserializeObject<List<MyCircle>>(dataCirCle);
Circle cir = new Circle();
var cirRadius = myCirCles.Select(x => x.Radius).ToList();
var cirCenterX = myCirCles.Select(X => X.CirCenterX).ToList();
var cirCenterY = myCirCles.Select(x => x.CirCenterY).ToList();
var cirIndex = myCirCles.Select(x => x.CirIndex).ToList();
var cirLayer = myCirCles.Select(x => x.CirLayer).ToList();
if (myCirCles.Count != 0)
{
for (int i = 0; i < cirRadius.Count; i++)
{
cir = new Circle(new Point3d(cirCenterX[i], cirCenterY[i], 0), Vector3d.ZAxis, cirRadius[i]);
this.AddLayer(cirLayer[i], cirIndex[i]);
cir.Layer = cirLayer[i];
cir.ColorIndex = cirIndex[i];
this.AddEntityToModeSpace(cir, db);
}
}
string pathArc = "Arc.json";
string dataArc = File.ReadAllText(pathArc);
List<MyArc> myArcs = JsonConvert.DeserializeObject<List<MyArc>>(dataArc);
Arc arc = new Arc();
var arcRadius = myArcs.Select(x => x.ArcRadius).ToList();
var arcCEnterX = myArcs.Select(x => x.ArcCenterX).ToList();
var arcCEnterY = myArcs.Select(x => x.ArcCenterY).ToList();
var startAngle = myArcs.Select(x => x.StartAngle).ToList();
var endAngle = myArcs.Select(x => x.EndAngle).ToList();
var arcIndex = myArcs.Select(x => x.ArcIndex).ToList();
var arcLAyer = myArcs.Select(x => x.ArcLayer).ToList();
if (myArcs.Count != 0)
{
for (int i = 0; i < arcRadius.Count; i++)
{
arc = new Arc(new Point3d(arcCEnterX[i], arcCEnterY[i], 0), arcRadius[i], startAngle[i], endAngle[i]);
this.AddLayer(arcLAyer[i], arcIndex[i]);
arc.Layer = arcLAyer[i];
arc.ColorIndex = arcIndex[i];
this.AddEntityToModeSpace(arc, db);
}
}
string pathPl = "pline.json";
string dataPl = File.ReadAllText(pathPl);
List<MyPolyline> myPolyLines = JsonConvert.DeserializeObject<List<MyPolyline>>(dataPl);
var plVertexX = myPolyLines.Select(x => x.VertecX).ToList();
var plVartexY = myPolyLines.Select(x => x.VertecY).ToList();
var plEndX = myPolyLines.Select(x => x.EndPointX).ToList();
var plEndY = myPolyLines.Select(x => x.EndPointY).ToList();
var plIndex = myPolyLines.Select(x => x.ColorIndex).ToList();
var plLayer = myPolyLines.Select(x => x.Layer).ToList();
if (myPolyLines.Count != 0)
{
for (int i = 0; i < myPolyLines.Count; i++)
{
Polyline pline = new Polyline();
for (int j = 0; j < plVertexX[i].Count; j++)
{
pline.AddVertexAt(j, new Point2d(plVertexX[i][j], plVartexY[i][j]), 0, 0, 0);
}
int index = (int)(pline.EndParam + 1);
pline.AddVertexAt(index, new Point2d(plEndX[i], plEndY[i]), 0, 0, 0);
this.AddLayer(plLayer[i], plIndex[i]);
pline.Layer = plLayer[i];
pline.ColorIndex = plIndex[i];
pline.Closed = false;
this.AddEntityToModeSpace(db, pline);
}
}
}
}