马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
AutoCAD Overrule .NET: Register and Un-Register OverrulesAutoCAD 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 introduced various overrules for the Centerline Circle, which is a common drawing element in the engineering design world but is not provided by AutoCAD natively. Two help methods are used frequently to register and unregister those overrule instances. Here they are.
- public static void RegisterOverrule(Type type, Overrule overrule)
- {
- Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
- try
- {
- Overrule.AddOverrule(RXClass.GetClass(type), overrule, true);
- MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.Regen();
- }
- catch (Autodesk.AutoCAD.Runtime.Exception acadEx)
- {
- if (acadEx.ErrorStatus == ErrorStatus.DuplicateKey)
- ed.WriteMessage("\nThe Overrule has already been registered.");
- else
- ed.WriteMessage("\n" + acadEx.Message);
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage(ex.Message);
- }
- }
-
- public static void UnregisterOverrule(Type type, Overrule overrule)
- {
- Overrule.RemoveOverrule(RXClass.GetClass(type), overrule);
- MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.Regen();
- }
Here are some sample uses:
- …
- CenterlineCircle_Gadgets.RegisterOverrule(typeof(Circle), CenterlineCircle_DrawableOverrule.Instance);
- …
- CenterlineCircle_Gadgets.UnregisterOverrule(typeof(Circle), CenterlineCircle_DrawableOverrule.Instance);
They are straightforward. We just wrapped the Overrule.AddOverrule() and the Overrule.RemoveOverrule() methods a bit, added the Editor.Region() call, and added exception handling to make things more convenience and reliable.
|