明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1192|回复: 4

[基础] 循环添加实体应用

[复制链接]
发表于 2010-12-12 08:54 | 显示全部楼层 |阅读模式
本帖最后由 chpmould 于 2010-12-12 08:57 编辑

请老师帮助在以下绘制圆的程序中增加一个循环(while)...
执行程序效果是:当运行画圆程序后,就可以一直连续选点画圆,如果我需要退出画圆,只需要右键就结束...

 楼主| 发表于 2010-12-12 08:55 | 显示全部楼层
本帖最后由 chpmould 于 2010-12-12 08:59 编辑

以下是绘圆程序,请老师帮助修添加一个循环

  1.         public void CreateCircle()
  2.         {
  3.             Document doc = Application.DocumentManager.MdiActiveDocument;
  4.             Editor ed = doc.Editor;
  5.             PromptPointOptions p = new PromptPointOptions("\n请选取圆心点:");
  6.             PromptPointResult result = ed.GetPoint(p);
  7.             if (result.Status != PromptStatus.OK)
  8.                 return;
  9.             Point3d centerPoint = result.Value;
  10.             Database db = doc.Database;
  11.             using (doc.LockDocument())
  12.             using (Transaction tr = db.TransactionManager.StartTransaction())
  13.             {
  14.                 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  15.                 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  16.                 Circle c1 = new Circle(centerPoint, Vector3d.ZAxis, 10);              
  17.                 btr.AppendEntity(c1);
  18.                 tr.AddNewlyCreatedDBObject(c1, true);
  19.                 tr.Commit();
  20.             }   
  21.         }
发表于 2010-12-12 10:52 | 显示全部楼层
本帖最后由 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[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                Circle c1 = new Circle(result.Value, Vector3d.ZAxis, 10);              
                btr.AppendEntity(c1);
                tr.AddNewlyCreatedDBObject(c1, true);
                tr.Commit();
            }
            result = ed.GetPoint(p);
             }
        }
//备注:未做过测试
发表于 2010-12-12 11:09 | 显示全部楼层
可以一直连续选点:while
右键就结束:p.AllowNone = true;
自己试下吧,加几行代码就行了
 楼主| 发表于 2010-12-12 12:52 | 显示全部楼层
本帖最后由 chpmould 于 2010-12-15 12:40 编辑

谢谢各位老师的指导,问题已解决了。。。            

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 13:47 , Processed in 0.207497 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表