马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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.
- #region Namespaces
-
- using System;
- using System.Text;
- using System.Linq;
- using System.Xml;
- using System.Reflection;
- using System.ComponentModel;
- using System.Collections;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
-
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Windows;
-
- using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
- using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
- using AcWindowsNS = Autodesk.AutoCAD.Windows;
-
- #endregion
-
- using Autodesk.AutoCAD.GraphicsInterface;
-
- namespace AcadNetAddinWizard_Namespace
- {
- /// <summary>
- /// Features:
- /// List out the custom name for the Centerline Circle when applicable.
- /// </summary>
- public class CenterlineCircle_PropertiesOverrule1 : PropertiesOverrule
- {
- private CenterlineCircle_PropertiesOverrule1()
- {
- //The overrule only works with certain circles marked with the Extension Dictionary Entry.
- SetExtensionDictionaryEntryFilter(CenterlineCircle_Gadgets.CLCircle_ID);
-
- }
-
- private static CenterlineCircle_PropertiesOverrule1 mInstance;
- public static CenterlineCircle_PropertiesOverrule1 Instance
- {
- get
- {
- if (mInstance == null)
- mInstance = new CenterlineCircle_PropertiesOverrule1();
- return mInstance;
- }
- }
-
- public override void List(Entity entity)
- {
- base.List(entity);
-
- MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCustom name: {0}", CenterlineCircle_Gadgets.CLCircle_ID);
-
- double ratio = 1;
- object value = CenterlineCircle_Gadgets.GetDictionaryEntryTypedValue(
- CenterlineCircle_Gadgets.GetExtensionDictionaryEntry(entity.ObjectId, CenterlineCircle_Gadgets.CLCircle_ID),
- (int)DxfCode.ExtendedDataScale);
- if (value == null)
- ratio = CenterlineCircle_Gadgets.DefaultRatioLengthToRadius;
- else
- ratio = Convert.ToDouble(value);
- MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLength ratio: {0}", ratio);
- }
- }
- }
Here is the test command.
- [CommandMethod("AddCLCirclePropertiesOverrule1")]
- public static void AddCLCirclePropertiesOverrule1_Method()
- {
- CenterlineCircle_Gadgets.RegisterOverrule(typeof(Circle), CenterlineCircle_PropertiesOverrule1.Instance);
- }
-
- [CommandMethod("RemoveCLCirclePropertiesOverrule1")]
- public static void RemoveCLCirclePropertiesOverrule1_Method()
- {
- CenterlineCircle_Gadgets.UnregisterOverrule(typeof(Circle), CenterlineCircle_PropertiesOverrule1.Instance);
- }
Some highlights may look good to help understand the code.
• The centerline circle property overrule is derived from the PropertiesOverrule API class;
• The centerline circle PropertiesOverrule is made a singleton to avoid duplicate registrations or similar issues;
• The half-length to radius ratio is retrieved from the extension dictionary if any or uses the default value.
|