Simple drawable overrule skeleton

<?xml encoding=”UTF-8″>By Augusto Goncalves

We have a few samples of our blog showing how create drawable overrule. But what’s the skeleton to set up? This is actually a recurrent question on our support, so I decided to share what is my recommendation.

To make it work you’ll need a class that implements the DrawableOverrule class and the WorldDraw method (and the ViewportDraw is more specific). I prefer have a command to active/deactivate the overrule and make it as startup command (using bundle format). The command will check the variable and Add or Remove the overrule. Finally, remember to call Regen(), otherwise the new geometry will not appear.

The sample below should work for MText (for other types, just replace the class name).

[<span>CommandMethod</span>(<span>"simpleOverrule"</span>)]<br><span>public</span> <span>void</span> CmdSimpleOverrule()<br>{<br>  <span>if</span> (_overrule == <span>null</span>)<br>  {<br>    _overrule = <span>new</span> <span>TextOverrule</span>();<br>    <span>Overrule</span>.AddOverrule(<br>      <span>RXClass</span>.GetClass(<span>typeof</span>(<span>MText</span>)),<br>      _overrule, <span>false</span>);<br>  }<br>  <span>else</span><br>  {<br>    <span>Overrule</span>.RemoveOverrule(<br>      <span>RXClass</span>.GetClass(<span>typeof</span>(<span>MText</span>)),<br>      _overrule);<br>    _overrule = <span>null</span>;<br>  }<br>  <span>Application</span>.DocumentManager.MdiActiveDocument.Editor.Regen();<br>}<br> <br><span>private</span> <span>static</span> <span>TextOverrule</span> _overrule = <span>null</span>;<br> <br><span>public</span> <span>class</span> <span>TextOverrule</span> : <span>DrawableOverrule</span><br>{<br>  <span>public</span> <span>override</span> <span>bool</span> WorldDraw(<span>Drawable</span> drawable, <span>WorldDraw</span> wd)<br>  {<br>    <span>// draw the base class</span><br>    <span>bool</span> ret = <span>base</span>.WorldDraw(drawable, wd);<br> <br>    <span>// your custom code here</span><br>    <span>//</span><br>    <span>//</span><br> <br>    <span>// return the base</span><br>    <span>return</span> ret;<br>  }<br>}

Comments

5 responses to “Simple drawable overrule skeleton”

  1. This is what I use.
    public abstract class DrawableOverrule : DrawableOverrule where T : Entity
    {
    private readonly RXClass _targetClass = RXObject.GetClass(typeof(T));
    OverruleStatus _status = OverruleStatus.Off;
    public OverruleStatus Status
    {
    get
    {
    return _status;
    }
    set
    {
    if (value == OverruleStatus.On && _status == OverruleStatus.Off)
    {
    AddOverrule(_targetClass, this, true);
    _status = OverruleStatus.On;
    }
    else if (value == OverruleStatus.Off && _status == OverruleStatus.On)
    {
    RemoveOverrule(_targetClass, this);
    _status = OverruleStatus.Off;
    }
    }
    }
    protected DrawableOverrule(OverruleStatus status = OverruleStatus.On)
    {
    Status = status;
    }
    }
    public enum OverruleStatus
    {
    Off= 0,
    On = 1
    }

  2. Thanks for sharing Jeff, nice implementation too :-)
    Cheers,
    Augusto Goncalves

  3. Thanks and sorry but angle brackets do not show up in comments missing T in some places for a generic class

  4. Hi Augusto!
    You did the simple typo in your’s post. Instead of DBText have to be MText.

  5. Thanks Alexander, I have fixed it.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading