找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 3701|回复: 0

[分享] AutoCAD Overrule .NET: Centerline Circle PropertiesOverrule Version 2

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2013-6-12 06:47:45 | 显示全部楼层 |阅读模式

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

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

×
AutoCAD Overrule .NET: Centerline Circle PropertiesOverrule Version 2AutoCAD has provided the Overrule .NET API in recent versions. It is the most powerful .NET API so far and can provide almost the custom entity feature that is still only available in the most powerful AutoCAD API, ObjectARX. On the other hand, however, the Overrule API is also the most complex part in the AutoCAD .NET.
We have provided a Centerline Circle PropertiesOverrule before, but the first version of Centerline Circle PropertiesOverrule only lists out the Centerline Circle as custom name. In this post, let’s implement the PropertiesOverrule version 2 and add the critical ratio of length to diameter or half length to radius. Here is the code.
  1. #region Namespaces

  2. using System;
  3. using System.Text;
  4. using System.Linq;
  5. using System.Xml;
  6. using System.Reflection;
  7. using System.ComponentModel;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Windows;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Forms;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;

  16. using Autodesk.AutoCAD.ApplicationServices;
  17. using Autodesk.AutoCAD.DatabaseServices;
  18. using Autodesk.AutoCAD.Runtime;
  19. using Autodesk.AutoCAD.EditorInput;
  20. using Autodesk.AutoCAD.Geometry;
  21. using Autodesk.AutoCAD.Windows;

  22. using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
  23. using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
  24. using AcWindowsNS = Autodesk.AutoCAD.Windows;

  25. #endregion

  26. using Autodesk.AutoCAD.GraphicsInterface;

  27. namespace AcadNetAddinWizard_Namespace
  28. {
  29.     /// <summary>
  30.     /// Features:
  31.     ///     List out the custom name for the Centerline Circle when applicable.
  32.     /// </summary>
  33.     public class CenterlineCircle_PropertiesOverrule1 : PropertiesOverrule
  34.     {
  35.         private CenterlineCircle_PropertiesOverrule1()
  36.         {
  37.             //The overrule only works with certain circles marked with the Extension Dictionary Entry.
  38.             SetExtensionDictionaryEntryFilter(CenterlineCircle_Gadgets.CLCircle_ID);

  39.         }

  40.         private static CenterlineCircle_PropertiesOverrule1 mInstance;
  41.         public static CenterlineCircle_PropertiesOverrule1 Instance
  42.         {
  43.             get
  44.             {
  45.                 if (mInstance == null)
  46.                     mInstance = new CenterlineCircle_PropertiesOverrule1();
  47.                 return mInstance;
  48.             }
  49.         }

  50.         public override void List(Entity entity)
  51.         {
  52.             base.List(entity);

  53.             MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCustom name: {0}", CenterlineCircle_Gadgets.CLCircle_ID);

  54.             double ratio = 1;
  55.             object value = CenterlineCircle_Gadgets.GetDictionaryEntryTypedValue(
  56.                             CenterlineCircle_Gadgets.GetExtensionDictionaryEntry(entity.ObjectId, CenterlineCircle_Gadgets.CLCircle_ID),
  57.                             (int)DxfCode.ExtendedDataScale);
  58.             if (value == null)
  59.                 ratio = CenterlineCircle_Gadgets.DefaultRatioLengthToRadius;
  60.             else
  61.                 ratio = Convert.ToDouble(value);
  62.             MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLength ratio: {0}", ratio);
  63.         }
  64.     }
  65. }

Here is the test command.
  1. [CommandMethod("AddCLCirclePropertiesOverrule1")]
  2. public static void AddCLCirclePropertiesOverrule1_Method()
  3. {
  4.     CenterlineCircle_Gadgets.RegisterOverrule(typeof(Circle), CenterlineCircle_PropertiesOverrule1.Instance);
  5. }

  6. [CommandMethod("RemoveCLCirclePropertiesOverrule1")]
  7. public static void RemoveCLCirclePropertiesOverrule1_Method()
  8. {
  9.     CenterlineCircle_Gadgets.UnregisterOverrule(typeof(Circle), CenterlineCircle_PropertiesOverrule1.Instance);
  10. }

Some highlights may look good to help understand the code.
&#8226; The centerline circle property overrule is derived from the PropertiesOverrule API class;
&#8226; The centerline circle PropertiesOverrule is made a singleton to avoid duplicate registrations or similar issues;
&#8226; The half-length to radius ratio is retrieved from the extension dictionary if any or uses the default value.



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-6 05:07 , Processed in 0.448506 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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