明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: carrot1983

[JIG] [求助]利用Jig动态拖拽实现动态修改圆大小(C#版)

  [复制链接]
发表于 2009-12-24 13:14 | 显示全部楼层
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.Runtime;
  7. using Autodesk.AutoCAD.Geometry;
  8. using Autodesk.AutoCAD.ApplicationServices;
  9. using Autodesk.AutoCAD.GraphicsInterface;
  10. [assembly: CommandClass(typeof(TlsCad.Jigs.CircleDrawJig))]
  11. namespace TlsCad.Jigs
  12. {
  13.     public class CircleDrawJig : DrawJig
  14.     {
  15.         private Point3d _center;
  16.         private double _radius;
  17.         private Vector3d _normal = Vector3d.ZAxis;
  18.         private static double _defaultValue = 10.0;
  19.         public CircleDrawJig(Point3d center)
  20.         {
  21.             _center = center;
  22.         }
  23.         //调用图形接口绘制图元
  24.         protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw wd)
  25.         {
  26.             SubEntityTraits set = wd.SubEntityTraits;
  27.             set.Color = 1;
  28.             set.LineWeight = LineWeight.LineWeight050;
  29.             wd.Geometry.Circle(_center,_radius,_normal);
  30.             set.Color = 2;
  31.             set.LineWeight = LineWeight.LineWeight035;
  32.             wd.Geometry.Circle(_center, _radius/2, _normal);
  33.             return true;
  34.         }
  35.         protected override SamplerStatus Sampler(JigPrompts prompts)
  36.         {
  37.             JigPromptDistanceOptions opts = new JigPromptDistanceOptions();
  38.             opts.UserInputControls =
  39.                 UserInputControls.Accept3dCoordinates |
  40.                 UserInputControls.NullResponseAccepted;     //允许空值输入,即空格和鼠标右键
  41.             opts.BasePoint = _center;
  42.             opts.UseBasePoint = true;
  43.             opts.Message = "\n请输入半径:";
  44.             opts.Cursor = CursorType.RubberBand;
  45.             opts.DefaultValue = _defaultValue;
  46.             PromptDoubleResult res = prompts.AcquireDistance(opts);
  47.             if (res.Status == PromptStatus.OK)
  48.             {
  49.                 if (_radius == res.Value)
  50.                 {
  51.                     return SamplerStatus.NoChange;
  52.                 }
  53.                 else
  54.                 {
  55.                     _radius = res.Value;
  56.                     return SamplerStatus.OK;
  57.                 }
  58.             }
  59.             else if (res.Status == PromptStatus.None)
  60.             {
  61.                 //空值输入时返回
  62.                 return SamplerStatus.OK;
  63.             }
  64.             else
  65.             {
  66.                 return SamplerStatus.Cancel;
  67.             }
  68.             
  69.         }
  70.         public Entity GetEntity()
  71.         {
  72.             return new Circle(_center, _normal, _radius);
  73.         }
  74.         [CommandMethod("tej")]
  75.         public static void DoIt()
  76.         {
  77.             Document doc = Application.DocumentManager.MdiActiveDocument;
  78.             Editor ed = doc.Editor;
  79.             PromptPointResult pntRes = ed.GetPoint("\n请选择圆心");
  80.             if (pntRes.Status == PromptStatus.OK)
  81.             {
  82.                 CircleDrawJig jig = new CircleDrawJig(pntRes.Value);
  83.                 PromptResult jigRes = ed.Drag(jig);
  84.                 if (jigRes.Status == PromptStatus.OK)
  85.                 {
  86.                     Database db = doc.Database;
  87.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  88.                     {
  89.                         BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
  90.                         Entity ent = jig.GetEntity();
  91.                         btr.AppendEntity(ent);
  92.                         tr.AddNewlyCreatedDBObject(ent,true);
  93.                         tr.Commit();
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.     }
  99. }

本帖子中包含更多资源

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

x
发表于 2010-12-17 09:11 | 显示全部楼层
原来在这,右键取消捆饶1天,学习了
发表于 2013-7-25 17:25 | 显示全部楼层
发表于 2014-1-18 10:02 | 显示全部楼层
看到代码中 有 set.LineWeight = LineWeight.LineWeight035;
我尝试将其LineWeight035 改为最大的LineWeight211,发现绘制的时候,宽度没有变化。
请问,这个是什么原因呢?
谢谢哈
发表于 2014-1-18 14:28 | 显示全部楼层
l510319004 发表于 2014-1-18 10:02
看到代码中 有 set.LineWeight = LineWeight.LineWeight035;
我尝试将其LineWeight035 改为最大的LineWeig ...

设置LWDISPLAY系统变量为1
发表于 2014-1-18 15:16 | 显示全部楼层
sieben 发表于 2014-1-18 14:28
设置LWDISPLAY系统变量为1

感谢下先~

不过通过 set 命令查看

LWDISPLAY 是打开的状态的~
发表于 2015-8-9 18:42 | 显示全部楼层
本帖最后由 caiqs 于 2015-8-9 19:02 编辑

public Circle myCircle;
            private double cirRadius;
            private Point3d cirCenter;
            // 利用myCircle派生EntityJig基类
public CircleJig(Circle myCircle): base(myCircle)
            {
//原来的问题出在圆未实例化,导致重绘失败
myCirRadius=new Circle(new Point3d(0,0,0),new Vector3d(0,0,1),10));
               
cirCenter = myCircle.Center;
                cirRadius = myCircle.Radius;
            }

protected override bool Update()
            {
Cirlce tmpcir=(Circle)Entity;
tmpcir.Radius=cirRadius;               
                return true;
            }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-19 13:10 , Processed in 0.397717 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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