AutoCAD .NET Overrule API provides an Overrule.HasOverrule() method and it has the following signature:
public static bool HasOverrule(Autodesk.AutoCAD.Runtime.RXObject overruledSubject, Autodesk.AutoCAD.Runtime.RXClass targetClass)
Member of Autodesk.AutoCAD.Runtime.Overrule
As can be seen, the method surprisingly needs both the RXClass type of the target Entity Class and an instance of the Overruled Subject such as a Circle or Line object. Not sure why it looks like so, but it is not so useful and convenient for sure.
First, it is not consistent with the signatures of the AddOverrule() or the RemoveOverrule():
Autodesk.AutoCAD.Runtime.Overrule.AddOverrule(Autodesk.AutoCAD.Runtime.RXClass, Autodesk.AutoCAD.Runtime.Overrule, System.Boolean)
The two methods only care about the target RXClass type and the Overrule instance, meaning an Overrule can apply either to all objects of the RXClass type or none at all putting aside the filtering stuff at this moment. That is, we can only add an Overrule to the whole instances of a certain RXClass type and remove the Overrule from all instantances of the same RXClass type. We are not supposed to add an Overrule to a single RXObject instance.
Second, the HasOverrule() method does not concern what specific Overrule at all. Instead, it cares about whether a single instance of an RXObject such as Circle or Line has been applied any Overrule or not. What real use cases might be for it?
Third, OK, let’s suppose we really have the need to check whether a Circle instance has been overruled or not. Why do we have to provide the RXClass type at the same time? Isn’t it redundant at all? Can’t we get the RXClass from the RXObject through the RXObject.GetRXClass() call?
Fourth, does the HasOverrule() method take into account the Overrule Filters such as XData and XRecord Filters that we have demonstrated a few time? Does it take into account view specific overrule graphics?
Not likely, from what we can see. Maybe it will yield something if the method is reflected. Please give it a try if interested.
The real question comes: how can we check whether an Overrule instance has been registered onto an AutoCAD Type (or RXClass) or not?
Here we go.
/// Check if the Overrule has been registered into the system.
/// <param name="type"></param>
/// <param name="overrule"></param>
public static bool IsOverruleRegistered(Type type, Overrule overrule)
//The Overrule.HasOverrule() method only works with a particular RXObject instance!
//Overrule.HasOverrule(RXObject object, RXClass class);
//So we have to work around the issue using the AddOverrule and RemoveOverrule call!
//It is not perfect, but it works!
Overrule.AddOverrule(RXClass.GetClass(type), overrule, true);
catch (System.Exception ex)
if (ex is Autodesk.AutoCAD.Runtime.Exception && (ex as Autodesk.AutoCAD.Runtime.Exception).ErrorStatus == ErrorStatus.DuplicateKey)
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.