用objectARX实现了一个复杂实体的Jig

点选一点,动态标注改点坐标。

用objectARX实现了一个复杂实体的Jig..

//坐标标注JIg类
    class ZBJig : DrawJig
    {
        public readonly static double TextHeight = 8;
        public readonly static double Len = 80;
 
        private Point3d mLocation;
        private string strZb = "";
        private DBText mText;
        private Polyline mPline;
        public void Bzb()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            PromptPointOptions opt = new PromptPointOptions("\n选择标注点:");
            PromptPointResult res = ed.GetPoint(opt);
            if (res.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d FirstPoint = res.Value;
            strZb = string.Format("X={0:0.0000},Y={1:0.0000}", FirstPoint.X, FirstPoint.Y);
            mText = new DBText();
           // mText.TextStyleId = TextStyles.AddTextStyle("hztxt");
            mText.Position = FirstPoint;
            mText.TextString = strZb;
            mText.Height = TextHeight;
            mText.WidthFactor = 0.7;
            mText.Rotation = 0.00;
 
            mPline = new Polyline();
            mPline.AddVertexAt(0, new Point2d(FirstPoint.X, FirstPoint.Y), 0, 0, 0);
            mPline.AddVertexAt(1, new Point2d(FirstPoint.X, FirstPoint.Y), 0, 0, 0);
            mPline.AddVertexAt(2, new Point2d(FirstPoint.X + Len, FirstPoint.Y), 0, 0, 0);
 
            PromptResult res2 = ed.Drag(this);
            if (res2.Status == PromptStatus.OK)
            {
                AppendEntity();
            }
        }
 
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions jigOpts = new JigPromptPointOptions();
            jigOpts.UserInputControls =
                UserInputControls.Accept3dCoordinates |
                UserInputControls.NoZeroResponseAccepted |
                UserInputControls.NoNegativeResponseAccepted;
            jigOpts.Message = "\n标注位置:";
            PromptPointResult res = prompts.AcquirePoint(jigOpts);
            Point3d positionTemp = res.Value;
            if (positionTemp != mLocation)
            {
                mLocation = positionTemp;
            }
            else
                return SamplerStatus.NoChange;
            if (res.Status == PromptStatus.Cancel)
                return SamplerStatus.Cancel;
            else
                return SamplerStatus.OK;
        }
 
        protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
        {
            try
            {
                Update();
                draw.Geometry.Draw(mPline);
                draw.Geometry.Draw(mText);
            }
            catch (System.Exception)
            {
                return false;
            }
            return true;
        }
 
        private void Update()
        {
            mPline.SetPointAt(1, new Point2d(mLocation.X, mLocation.Y));
            mPline.SetPointAt(2, new Point2d(mLocation.X + Len, mLocation.Y));
            mText.Position = mLocation;
        }
 
        //在当前图形文件中添加实体
        private void AppendEntity()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false);          
                Update();
                btr.AppendEntity(mText);
                tr.AddNewlyCreatedDBObject(mText, true);
                btr.AppendEntity(mPline);
                tr.AddNewlyCreatedDBObject(mPline, true);
                tr.Commit();
            }
        }
    }

增加一个AutoCAD命令

      [CommandMethod("Bzb")]
        static public void Cmd5() // This method can have any name
        {
            ZBJig bzb1 = new ZBJig();
            bzb1.Bzb();
        }

实现效果如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值