注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

we are 5. Mathematics, Computation, Programming, Engineering, and Making fun of life.

网易考拉推荐

.NET中将圆转成多义线  

2011-01-05 22:02:38|  分类: ObjectARX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

直接上代码:

using System;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

namespace CADTest

{

    public class Class1

    {

        [CommandMethod("c2p")]

        public void CircleToPloyline()

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            Transaction trans = db.TransactionManager.StartTransaction();

            BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);

            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

            PromptSelectionResult psr = ed.GetSelection();

            //获取选择集,这里就不过滤了

            SelectionSet ss = null;

            if (psr.Status == PromptStatus.OK)

            {

                ss = psr.Value;

                foreach (SelectedObject so in ss)

                {

                    Circle c = trans.GetObject(so.ObjectId, OpenMode.ForWrite) as Circle;

                    double r = c.Radius;

                    Point3d cc = c.Center;

                    Point2d p1 = new Point2d(cc.X + r, cc.Y);

                    Point2d p2 = new Point2d(cc.X - r, cc.Y);

                    Polyline poly = new Polyline();

                    poly.AddVertexAt(0, p1, 1, 0, 0);

                    poly.AddVertexAt(1, p2, 1, 0, 0);

                    poly.AddVertexAt(2, p1, 1, 0, 0);

                    btr.AppendEntity(poly);

                    trans.AddNewlyCreatedDBObject(poly, true);

                    c.Erase(true);

                }

            }

            trans.Commit();

            trans.Dispose();

        }

 

        [CommandMethod("GET")]

        public void GetEntityType()

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("请选择一个实体");

            PromptEntityResult per = null;

            try

            {

                per = ed.GetEntity(peo);

                if (per.Status == PromptStatus.OK)

                {

                    ObjectId id = per.ObjectId;

                    Transaction trans = db.TransactionManager.StartTransaction();

                    Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, true);

 

                    ed.WriteMessage("\n实体ObjectId为:" + ent.ObjectId + "\n实体类型为:" + ent.GetType().FullName);

                    trans.Commit();

                    trans.Dispose();

                }

            }

            catch (Autodesk.AutoCAD.Runtime.Exception exc)

            {

                ed.WriteMessage("发生异常,原因为:" + exc.Message);

            }

        }

    }

}

运行效果如下:

.NET中将圆转成多义线 - Castor - 趁年轻,多折腾~~

 

 

  评论这张
 
阅读(1122)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016