循环添加实体应用
本帖最后由 chpmould 于 2010-12-12 08:57 编辑请老师帮助在以下绘制圆的程序中增加一个循环(while)...
执行程序效果是:当运行画圆程序后,就可以一直连续选点画圆,如果我需要退出画圆,只需要右键就结束...
本帖最后由 chpmould 于 2010-12-12 08:59 编辑
以下是绘圆程序,请老师帮助修添加一个循环
public void CreateCircle()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptPointOptions p = new PromptPointOptions("\n请选取圆心点:");
PromptPointResult result = ed.GetPoint(p);
if (result.Status != PromptStatus.OK)
return;
Point3d centerPoint = result.Value;
Database db = doc.Database;
using (doc.LockDocument())
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Circle c1 = new Circle(centerPoint, Vector3d.ZAxis, 10);
btr.AppendEntity(c1);
tr.AddNewlyCreatedDBObject(c1, true);
tr.Commit();
}
}
本帖最后由 sieben 于 2010-12-12 11:08 编辑
public void CreateCircle()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptPointOptions p = new PromptPointOptions("\n请选取圆心点:");
PromptPointResult result = ed.GetPoint(p);
while (result.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Circle c1 = new Circle(result.Value, Vector3d.ZAxis, 10);
btr.AppendEntity(c1);
tr.AddNewlyCreatedDBObject(c1, true);
tr.Commit();
}
result = ed.GetPoint(p);
}
}
//备注:未做过测试
可以一直连续选点:while
右键就结束:p.AllowNone = true;
自己试下吧,加几行代码就行了 本帖最后由 chpmould 于 2010-12-15 12:40 编辑
谢谢各位老师的指导,问题已解决了。。。
页:
[1]