AutoCAD 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.
Centerline Circle is a common drawing element in the engineering design world but is not provided by AutoCAD natively. Though AutoCAD has some means to control how to show the circle center point, it is far from enough. We presented the centerline circle overrule implementation in some earlier posts. Let’s contine to enhance the centerline circle in this post, making centerlines support viewport dependant graphics.
Here is the enhanced version of the Centerline Circle.
using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcWindowsNS = Autodesk.AutoCAD.Windows;
/// A derivative from the DrawableOverrule;
/// Being made a singleton to avoid duplicate registrations;
/// UCS being hornored;
/// Adding center lines to all cirlces;
/// ViewportDraw being overridden to draw view dependant graphics;
public class CenterlineCircle_DrawableOverrule2 : DrawableOverrule
protected static CenterlineCircle_DrawableOverrule2 mInstance;
public static CenterlineCircle_DrawableOverrule2 Instance
if (mInstance == null)
mInstance = new CenterlineCircle_DrawableOverrule2();
mInstance = value;
public override bool WorldDraw(Drawable drawable, WorldDraw wd)
public override void ViewportDraw(Drawable drawable, ViewportDraw vd)
if (drawable is Circle)
Matrix3d ucs = vd.Viewport.EyeToWorldTransform;
Circle cir = drawable as Circle;
Point3d cen = cir.Center.TransformBy(ucs.Inverse());
double rad = cir.Radius;
Point3d line1Pt1 = new Point3d(cen.X - rad * 1.2, cen.Y, cen.Z).TransformBy(ucs);
Point3d line1Pt2 = new Point3d(cen.X + rad * 1.2, cen.Y, cen.Z).TransformBy(ucs);
Point3d line2Pt1 = new Point3d(cen.X, cen.Y - rad * 1.2, cen.Z).TransformBy(ucs);
Point3d line2Pt2 = new Point3d(cen.X, cen.Y + rad * 1.2, cen.Z).TransformBy(ucs);
Here are the commands to show or hide centerlines for circles.
public static void ShowCircleCenterline2_Method()
public static void HideCircleCenterline2_Method()
After the centerline circle overrule assembly is loaded into AutoCAD and the ShowCircleCenterline1 command is run, all regular circles will become centerline circles automatically with the centerlines looking real CENTER.
If the WorldDraw is implemented but the ViewportDraw not in the Overrule, as was done previously, the centerlines of circles will only honor the view direction of the UCS/WCS of the model/world view. In each viewport of layouts, the centerlines may not be parallel to the layout coordinate system.
If the ViewportDraw is implemented instead in the Overrule, as was done here, the centerlines of circles will not only honor the view direction of the UCS/WCS of the model/world view but also each viewport direction of each layout. In each viewport of layouts, the centerlines will be parallel to the layout coordinate system.
However, the centerlines may not look natural along with the circle graphics in each viewport, as shown by the above screenshot. We will address this matter in later posts.
Some highlights may look good to help understand the centerline circle overrule.
• The centerline circle overrule is derived from the DrawableOverrule API class;
• The centerline circle overrule is made a singleton to avoid duplicate registrations or similar issues;
• The centerline circle overrule works with both UCS and WCS;
• The WorldDraw of the centerline circle overrule has been overridden and its Geometry.WorldLine is used to draw the centerlines;
• The centerline circle overrule draws the centerlines with a hard coded color (Cyan with index 4) through setting the WorldDraw.SubEntityTraits.Color property.
• The ViewportDraw has been implemented to support viewport dependant graphics.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various project wizards, item wizards, coders including a Ribbon Creator, and widgets to help program AutoCAD .NET addins.