请教各位大能,如何新建mline实体啊
本帖最后由 lamntree 于 2012-8-19 17:37 编辑如何用代码新建mline实体啊,是不是用Mline.AppendSegment(Point3d)方法新建mline实体啊,我用这个方法写的代码,调试时在这一行出现eInvaildStyle异常
public static void Multline()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult ppr1 = doc.Editor.GetPoint("\nspecial start point1");
PromptPointResult ppr2 = doc.Editor.GetPoint("\nspecial start point2");
Point3d pt1 = new Point3d(((ppr1.Value.X + ppr2.Value.X) / 2), ((ppr1.Value.Y + ppr2.Value.Y) / 2), 0);
PromptPointResult ppr3 = doc.Editor.GetPoint("\nspecial end point");
Point3d pt2 = ppr3.Value;
double l = Math.Sqrt(Math.Pow((ppr2.Value.X - ppr1.Value.X), 2) + Math.Pow((ppr1.Value.Y - ppr2.Value.Y), 2));
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Mline ml = new Mline();
ml.SetDatabaseDefaults();
ml.Scale = l;
ml.AppendSegment(pt1);
ml.AppendSegment(pt2);
btr.AppendEntity(ml);
trans.AddNewlyCreatedDBObject(ml, true);
trans.Commit();
}
}
我自己研究出来了,这个命令是用3点画MLINE,第一点第二点的距离是MLINE的SCALE,第一点第二点的中点是MLINE的起点,第三点是MLINE的终点。下面是代码
public static void Multline()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult ppr1 = doc.Editor.GetPoint("\nspecial start point1");
PromptPointResult ppr2 = doc.Editor.GetPoint("\nspecial start point2");
Point3d pt1 = new Point3d(((ppr1.Value.X + ppr2.Value.X) / 2), ((ppr1.Value.Y + ppr2.Value.Y) / 2), 0);
PromptPointResult ppr3 = doc.Editor.GetPoint("\nspecial end point");
Point3d pt2 = ppr3.Value;
double l = Math.Sqrt(Math.Pow((ppr2.Value.X - ppr1.Value.X), 2) + Math.Pow((ppr1.Value.Y - ppr2.Value.Y), 2));
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Mline ml = new Mline();
ml.SetDatabaseDefaults();
DBDictionary MlineStyleDic = (DBDictionary)trans.GetObject(db.MLStyleDictionaryId, OpenMode.ForWrite);
MlineStyle ms = new MlineStyle();
ms = (MlineStyle)trans.GetObject(MlineStyleDic.GetAt("STANDARD"), OpenMode.ForRead);
ml.Style = ms.ObjectId;
ml.Scale = l;
ml.Justification = MlineJustification.Zero;
Vector3d vec = new Vector3d(0,0,1);
ml.Normal = vec;
ml.AppendSegment(pt1);
ml.AppendSegment(pt2);
btr.AppendEntity(ml);
trans.AddNewlyCreatedDBObject(ml, true);
trans.Commit();
}
} public double DistanceTo(Autodesk.AutoCAD.Geometry.Point3d point)
Autodesk.AutoCAD.Geometry.Point3d 的成员 学习了,呵呵
页:
[1]