明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2860|回复: 14

[求助]请教一下Dimension如何做到拖动的效果

  [复制链接]
发表于 2009-6-2 15:40 | 显示全部楼层 |阅读模式
   我使用DrawJig, 好像不行 。有谁做过类似的功能吗?就是鼠标移动Dimension也移动。
发表于 2009-6-2 17:24 | 显示全部楼层
没写过JIG的标注,但感觉和其他JIG程序应该差不多。
 楼主| 发表于 2009-6-2 19:14 | 显示全部楼层
ahlzl发表于2009-6-2 17:24:00没写过JIG的标注,但感觉和其他JIG程序应该差不多。

是的 我一开始也是这么做的 可是在sampler里 第二次循环到PromptPointResult result = prompts.AcquirePoint(options); 时就出现访问protect memory。然后就出错了

发表于 2009-6-2 20:18 | 显示全部楼层
代码看下?
 楼主| 发表于 2009-6-3 08:35 | 显示全部楼层

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;

namespace XEIZ.AutoCAD.Util.Jig
{
    public class demoDimensionJig:DrawJig
    {
        Database _db = HostApplicationServices.WorkingDatabase;
        Point3d _minpt;
        Point3d _oldpt;

        Point3d _startVertex;
        DBPoint _oriPt;
        private Feature feature = null;
        private Feature selFeature = null;

        AlignedDimension dimension;


        public DBPoint OrgPt { set { _oriPt = value; } }
        public Feature Feat { set { feature = value; } }
        public Feature SelFeat { set { selFeature = value; } }
        public Point3d StartVertex { set { _startVertex = value; } }


        public void Excute()
        {
            ObjectId result = ObjectId.Null;
            BlockTable bt;

            BlockTableRecord btr;
            try
            {
                DBPoint dbpt = (DBPoint)GeometryToEntityConverter.GeometryToEntity(feature.MapGeometry);
                _minpt = dbpt.Position;

                dimension = new AlignedDimension();
                dimension.DimLinePoint = _minpt;
                dimension.XLine1Point = _startVertex;
                dimension.XLine2Point = _minpt;
                using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    //Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = _db.TransactionManager;
                    //using (Transaction trans = _db.TransactionManager.StartTransaction())
                    //{
                    //    bt = (BlockTable)tm.GetObject(_db.BlockTableId, OpenMode.ForRead);
                    //    if ( bt.Has("xTextBlock"))
                    //    {
                    //        btr = (BlockTableRecord)trans.GetObject(bt["xTextBlock"], OpenMode.ForWrite);
                    //        _xValue = new BlockReference(new Point3d(0, 0, 0), btr.Id);
                    //        trans.Commit();
                    //    }

                    //}

                    bool bCancel = false;
                    PromptResult var = _ed.Drag(this);
                    if (var.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    
                }
            }
            catch(System.Exception e)
            {
                throw new System.Exception(e.ToString());
            }
        }

        /// <summary>
        /// implementation of WorldDraw
        /// </summary>
        /// <param name="draw">WorldDraw</param>
        /// <returns>true:on success, false: on fail</returns>
        protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
        {
           
            draw.Geometry.Draw(dimension);

            return true;
        }//end of function WorldDraw()

        /// <summary>
        /// implementation of Sampler
        /// </summary>
        /// <param name="prompts">JigPrompts</param>
        /// <returns>SamplerStatus</returns>
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            JigPromptPointOptions options = new JigPromptPointOptions("\nPosition");
            options.UserInputControls =
                (UserInputControls.AcceptOtherInputString);
            PromptPointResult result = prompts.AcquirePoint(options);
            if (result.Status != PromptStatus.OK)
            {
                return SamplerStatus.NoChange;
            }
            //Point3d cur = result.Value;
            //if (_oldpt == cur)
            //{
            //    return SamplerStatus.NoChange;
            //}
            dimension.DimLinePoint = result.Value;
            dimension.XLine1Point = _startVertex;
            dimension.XLine2Point = _minpt;
            _oldpt = result.Value;
            return SamplerStatus.OK;
        }//end of function Sampler()

    }
}

发表于 2009-6-3 09:28 | 显示全部楼层
dimension.SetDatabaseDefaults();
 楼主| 发表于 2009-6-3 10:22 | 显示全部楼层
谢谢 我下去试试。  另外我还有个问题请教你。就是PromptPointResult result = prompts.AcquirePoint(options); 如果我在命令行中输入一些字符 那左键单击就失效了 这个用代码能解决吗?就是有API清掉命令行中的代码吗?
发表于 2009-6-3 11:26 | 显示全部楼层
Cad内部命令也有同样的问题,:)
 楼主| 发表于 2009-6-3 14:46 | 显示全部楼层
嗯 那到是比较麻烦
 楼主| 发表于 2009-6-6 10:35 | 显示全部楼层

另外再请教一下 CAD中的 linear dimension 好像没有对应的API?是吗?我只找到AlignedDimension

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

本版积分规则

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

GMT+8, 2024-6-2 03:51 , Processed in 0.190534 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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