找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 707|回复: 1

[分享] 块的拖动类的实现

[复制链接]

已领礼包: 1个

财富等级: 恭喜发财

发表于 2017-5-20 19:25:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
按照Arx例子写了一个块的拖动类,有两个动作:移动和旋转
移动取点,旋转取角度
代码中PromptPointResult res = prompts.AcquirePoint(jigOpts);是取点的动作,想改为AcquireAngle一直没有成功
代码如下:

[C#] 纯文本查看 复制代码
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
namespace TlsCad
{
       public class BlockRefJig:EntityJig
       {
              Point3d mPosition;
              double mAngle;
              int mPromptCounter;

              public BlockRefJig(ObjectId id):base(new BlockReference(new Point3d(0,0,0),id))
              {
                     mPosition=new Point3d(0,0,0);
                     mAngle=0;
              }
              
              protected override SamplerStatus Sampler(JigPrompts prompts)
              {
                     JigPromptOptions jigOpts = new JigPromptOptions();
                     
                     if(mPromptCounter == 0)
                     {
                            jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted );
                            jigOpts.Message = "\n请输入基点:";
                            PromptPointResult dres = prompts.AcquirePoint(jigOpts);
                            Point3d positionTemp = dres.Value;
                            if(positionTemp != mPosition)
                            {
                                   mPosition = positionTemp;
                            }
                            else
                                   return SamplerStatus.NoChange;

                            if(dres.Status == PromptStatus.Cancel)
                                   return SamplerStatus.Cancel;
                            else
                                   return SamplerStatus.OK;
                                   
                                   
                     }
                     else if (mPromptCounter == 1) 
                     {
                            jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted);
                            jigOpts.BasePoint = mPosition;
                            jigOpts.UseBasePoint = true;
                            jigOpts.Message = "\n请输入旋转角度:";
                            double angleTemp = -1;
                            PromptPointResult res = prompts.AcquirePoint(jigOpts);
                            Point3d AnglePnt = res.Value;

                            angleTemp = AnglePnt.GetVectorTo(mPosition).AngleOnPlane(
                                   new Plane(
                                   Application.DocumentManager.MdiActiveDocument.Database.Ucsorg,
                                   Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir,
                                   Application.DocumentManager.MdiActiveDocument.Database.Ucsydir
                                   ));
                            if (angleTemp != mAngle)
                                   mAngle = angleTemp;
                            else 
                                   return SamplerStatus.NoChange;

                            if(res.Status == PromptStatus.Cancel)
                                   return SamplerStatus.Cancel;
                            else
                                   return SamplerStatus.OK;
                     
                     }
                     else
                     {
                            return SamplerStatus.NoChange;
                     }
                            
                            
              }

              protected override bool Update()
              {
                            
                     try
                     {
                            ((BlockReference)Entity).Position=mPosition;
                            ((BlockReference)Entity).Rotation =mAngle;                                    
                     }
                     catch(System.Exception)
                     {
                            return false;  
                     }
                            
                     return true;  

              }

              public void setPromptCounter(int i)
              {
                     mPromptCounter = i;
              }
              public Entity GetEntity()
              {
                     return Entity;
              }
       }
}


2007下,下面修改了一些BUG

[C#] 纯文本查看 复制代码
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;

namespace TlsCad
{
    public class BlockRefJig:EntityJig
    {
        Point3d mPosition;
        double mAngle;
        int mPromptCounter;

        public BlockRefJig(ObjectId id):base(new BlockReference(new Point3d(0,0,0),id))
        {
            mPosition=new Point3d(0,0,0);
            mAngle=0;
        }
        
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            
            if(mPromptCounter == 0)
            {
                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 != mPosition)
                {
                    mPosition = positionTemp;
                }
                else
                    return SamplerStatus.NoChange;

                if(res.Status == PromptStatus.Cancel)
                    return SamplerStatus.Cancel;
                else
                    return SamplerStatus.OK;
                    
                    
            }
            else if (mPromptCounter == 1)
            {
                JigPromptAngleOptions jigOpts = new JigPromptAngleOptions();
                jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted);
                jigOpts.BasePoint = mPosition;
                jigOpts.UseBasePoint = true;
                jigOpts.Message = "\n请输入旋转角度:";
                PromptDoubleResult res = prompts.AcquireAngle(jigOpts);
                double angleTemp = res.Value;

                if (angleTemp != mAngle)
                    mAngle = angleTemp;
                else
                    return SamplerStatus.NoChange;

                if (res.Status == PromptStatus.Cancel)
                    return SamplerStatus.Cancel;
                else
                    return SamplerStatus.OK;

            }
            else
            {
                return SamplerStatus.NoChange;
            }
                
                
        }

        protected override bool Update()
        {
                
            try
            {
                ((BlockReference)Entity).Position=mPosition;
                ((BlockReference)Entity).Rotation =mAngle;                     
            }
            catch(System.Exception)
            {
                return false;  
            }
                
            return true;  

        }

        public void setPromptCounter(int i)
        {
            mPromptCounter = i;
        }
        public Entity GetEntity()
        {
            return Entity;
        }
    }
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 3191个

财富等级: 富可敌国

发表于 2017-5-21 08:10:01 | 显示全部楼层
学习了,好好学习天天向上
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-18 21:24 , Processed in 0.165719 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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