作为问题。这就是我获取元素数量的方式:
using (var trans = myDatabase.TransactionManager.StartTransaction())
{
BlockTableRecord btrec = (BlockTableRecord)trans.GetObject(myDatabase.CurrentSpaceId, OpenMode.ForWrite);
foreach (ObjectId objid in btrec)
{
Entity ent = trans.GetObject(objid, OpenMode.ForWrite) as Entity;
if (ent.GetType().Name.Contains("Mline"))
{
Mline dbtxta = (Mline)ent;
// mline style
MlineStyle mlsta = ((MlineStyle)dbtxta.Style.GetObject(OpenMode.ForRead));
// The result is i wanna get.
int result = mlsta.Elements.Count;
}
}
}
就像这条多线,计数是 4。经过我的算法处理后,我想画一条 5 条线(计数)的多线。我怎样才能做到这一点。这是我画的代码:
using (var trans = database.TransactionManager.StartTransaction())
{
for (int i = 0; i < xyz.Count; i++)
{
Mline mine = new Mline();
//mine.Style.
mine.Scale = 0; //?
mine.AppendSegment(new Point3d(xyz[i].X, xyz[i].Y, xyz[i].Z));
mine.Element(new Point3d(xyz[i].X, xyz[i].Y, xyz[i].Z));
// The comment code is also drawing mline,but the number of mline cannot be specified
//Point2d point2D1 = new Point2d(xyz[i].X, xyz[i].Y); // start point
//Point2d point2D2 = new Point2d(xyz[i+1].X, xyz[i + 1].Y); // end point
//Teigha.DatabaseServices.Polyline pl = new Teigha.DatabaseServices.Polyline();
//pl.AddVertexAt(0, point2D1, 0,1,1);
//pl.AddVertexAt(1, point2D2, 0,1,1);
BlockTableRecord btr = trans.GetObject(database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(mine);
mine.Layer = LayerName;
trans.AddNewlyCreatedDBObject(mine, true);
}
trans.Commit();
database.Save();
}
哪种方式可以绘制具有 5 个元素的 mline(仅计数“get”函数,而不是“set”函数),所以我该怎么做:
mline.style.Elements.Count = 5;