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

信息 灵感 创新

I? =Information,Inspiration,Innovation

 
 
 

日志

 
 
关于我

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

网易考拉推荐

实体的镜像  

2010-12-30 16:09:19|  分类: ObjectARX |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

实体的镜像

下面的程序用于演示实体关于三个坐标平面的镜像,和AutoCAD中的Mirror3d类似,但是没有它的功能强大,因为AutoCAD的该命令具有对任意平面的镜像能力,而本程序只能实现对三个坐标平面的镜像,不过好处是,稍加修改就可以在实体创建过程中自动实现镜像,创建对称实体将会很容易。以后试图实现对任意平面的镜像,下面是代码:

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

    {

        #region 实体镜像

        [CommandMethod("MEnt")]//Mirror Entity

        public void MirrorEntity()

        {

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //XOY平面的对称变换

            double[] dmXOY = new double[16];

            dmXOY[0] = 1;

            dmXOY[5] = 1;

            dmXOY[10] = -1;

            dmXOY[15] = 1;

            Matrix3d TmXOY = new Matrix3d(dmXOY);

            //YOZ平面的对称变换

            double[] dmYOZ = new double[16];

            dmYOZ[0] = -1;

            dmYOZ[5] = 1;

            dmYOZ[10] = 1;

            dmYOZ[15] = 1;

            Matrix3d TmYOZ = new Matrix3d(dmYOZ);

            //ZOX平面的对称变换

            double[] dmZOX = new double[16];

            dmZOX[0] = 1;

            dmZOX[5] = -1;

            dmZOX[10] = 1;

            dmZOX[15] = 1;

            Matrix3d TmZOX = new Matrix3d(dmZOX);

            Matrix3d TM;

            PromptStringOptions pso = new PromptStringOptions("请输入镜像平面:XY/YZ/ZX:");

            PromptResult pr = ed.GetString(pso);

            if (pr.Status == PromptStatus.OK)

            {

                switch (pr.StringResult.ToUpper())

                {

                    case "YX":

                    case "XY":

                        TM = TmXOY; break;

                    case "YZ":

                    case "ZY":

                        TM = TmYOZ; break;

                    case "ZX":

                    case "XZ":

                        TM = TmZOX; break;

                    default:

                        ed.WriteMessage("\n不认识的命令,退出");

                        return;

                }

            }

            else

            {

                ed.WriteMessage("\n" + pr.Status.ToString());

                return;

            }

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

            peo.SetRejectMessage("\n选择实体");

            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status == PromptStatus.OK)

            {

                //开始镜像

                using (Transaction trans = db.TransactionManager.StartTransaction())

                {

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

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

                    Entity ent = trans.GetObject(per.ObjectId, OpenMode.ForWrite) as Entity;

                    Entity entClone = ent.Clone() as Entity;

                    entClone.TransformBy(TM);

                    btr.AppendEntity(entClone);

                    trans.AddNewlyCreatedDBObject(entClone, true);

                    pso.Message="\n是否删除原实体?Y/N";

                    pr = ed.GetString(pso);

                    if (pr.Status == PromptStatus.OK)

                    {

                        switch (pr.StringResult.ToUpper())

                        {

                            case "Y":

                                ent.Erase(true);

                                ed.WriteMessage("\n实体被删除");

                                break;

                            case "N":

                                ed.WriteMessage("\n实体保留");

                                break;

                        }

                    }

                    trans.Commit();

                }

            }

            else

            {

                ed.WriteMessage("\n" + per.Status.ToString());

            }

        }

        #endregion

    }

}

 

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

历史上的今天

评论

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

页脚

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