<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Update element properties at a certain time using overrules implementation in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8744019#M22652</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm using the following&amp;nbsp;&lt;EM&gt;DrawableOverrule &lt;/EM&gt;&amp;nbsp;implementation to update color and pattern angle for hatches (filtered by XData).&lt;/P&gt;
&lt;P&gt;When the user changes the color or the angle of my custom object from my propertygrid, I'm using Editor.Regen() to redraw the hatch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I had to open transaction every time &lt;STRONG&gt;&lt;EM&gt;WorldDraw&lt;/EM&gt; &lt;/STRONG&gt;is called which affected the performance.&lt;/P&gt;
&lt;P&gt;Do I need to implement another overrule method (something like &lt;STRONG&gt;&lt;EM&gt;InvalidateEntities&lt;/EM&gt;&lt;/STRONG&gt;) to be called manually when required only (not at any change in the geometric shape)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my&amp;nbsp;&lt;EM&gt;DrawableOverrule &lt;/EM&gt;&amp;nbsp;implementation:&lt;/P&gt;
&lt;PRE&gt;using System;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.GraphicsInterface;
using QuoteRNZ.AutoCAD.Extensions;
using QuoteRNZ.BLL.Products;

namespace QuoteRNZ.AutoCAD
{
    class HatchDrawingOverrule : DrawableOverrule
    {
        public HatchDrawingOverrule()
        {
            SetXDataFilter(XDataExtensions.RegAppName);
        }

        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            Hatch hatch = drawable as Hatch;
            if (hatch == null) &lt;BR /&gt;                return base.WorldDraw(drawable, wd);&lt;BR /&gt;
            ElementBL element = hatch.GetExtendedQRNZElement();
            if (element == null)
                return base.WorldDraw(drawable, wd);

            if (hatch.PatternType == HatchPatternType.UserDefined)
            {
                using (var tr = new OpenCloseTransaction())
                {
                    hatch.UpgradeOpen();
                    hatch.PatternAngle = element.PanelsAngle * (Math.PI / 180);
                    hatch.DowngradeOpen();
                }
            }

            return base.WorldDraw(hatch, wd);
        }

        public override int SetAttributes(Drawable drawable, DrawableTraits traits)
        {
            var result = base.SetAttributes(drawable, traits);
            if (drawable is Entity dbObject)
            {
                ElementBL element = dbObject.GetExtendedQRNZElement();
                if (element == null)
                    return result;

                traits.Color = Color.FromColor(element.CrossSection.Color).ColorIndex;
            }
            return result;
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And when the user update my element's properties:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private static void ProfilePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (sender is ProductProfile profile)
            {
                if (e.PropertyName == nameof(profile.Color)|| e.PropertyName == nameof(profile.PanelsAngle))
                {
                    Application.DocumentManager.MdiActiveDocument.Editor.Regen();
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 21 Apr 2019 13:06:47 GMT</pubDate>
    <dc:creator>ahmedshawkey95</dc:creator>
    <dc:date>2019-04-21T13:06:47Z</dc:date>
    <item>
      <title>Update element properties at a certain time using overrules implementation</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8744019#M22652</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm using the following&amp;nbsp;&lt;EM&gt;DrawableOverrule &lt;/EM&gt;&amp;nbsp;implementation to update color and pattern angle for hatches (filtered by XData).&lt;/P&gt;
&lt;P&gt;When the user changes the color or the angle of my custom object from my propertygrid, I'm using Editor.Regen() to redraw the hatch.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I had to open transaction every time &lt;STRONG&gt;&lt;EM&gt;WorldDraw&lt;/EM&gt; &lt;/STRONG&gt;is called which affected the performance.&lt;/P&gt;
&lt;P&gt;Do I need to implement another overrule method (something like &lt;STRONG&gt;&lt;EM&gt;InvalidateEntities&lt;/EM&gt;&lt;/STRONG&gt;) to be called manually when required only (not at any change in the geometric shape)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my&amp;nbsp;&lt;EM&gt;DrawableOverrule &lt;/EM&gt;&amp;nbsp;implementation:&lt;/P&gt;
&lt;PRE&gt;using System;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.GraphicsInterface;
using QuoteRNZ.AutoCAD.Extensions;
using QuoteRNZ.BLL.Products;

namespace QuoteRNZ.AutoCAD
{
    class HatchDrawingOverrule : DrawableOverrule
    {
        public HatchDrawingOverrule()
        {
            SetXDataFilter(XDataExtensions.RegAppName);
        }

        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            Hatch hatch = drawable as Hatch;
            if (hatch == null) &lt;BR /&gt;                return base.WorldDraw(drawable, wd);&lt;BR /&gt;
            ElementBL element = hatch.GetExtendedQRNZElement();
            if (element == null)
                return base.WorldDraw(drawable, wd);

            if (hatch.PatternType == HatchPatternType.UserDefined)
            {
                using (var tr = new OpenCloseTransaction())
                {
                    hatch.UpgradeOpen();
                    hatch.PatternAngle = element.PanelsAngle * (Math.PI / 180);
                    hatch.DowngradeOpen();
                }
            }

            return base.WorldDraw(hatch, wd);
        }

        public override int SetAttributes(Drawable drawable, DrawableTraits traits)
        {
            var result = base.SetAttributes(drawable, traits);
            if (drawable is Entity dbObject)
            {
                ElementBL element = dbObject.GetExtendedQRNZElement();
                if (element == null)
                    return result;

                traits.Color = Color.FromColor(element.CrossSection.Color).ColorIndex;
            }
            return result;
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And when the user update my element's properties:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private static void ProfilePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (sender is ProductProfile profile)
            {
                if (e.PropertyName == nameof(profile.Color)|| e.PropertyName == nameof(profile.PanelsAngle))
                {
                    Application.DocumentManager.MdiActiveDocument.Editor.Regen();
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Apr 2019 13:06:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8744019#M22652</guid>
      <dc:creator>ahmedshawkey95</dc:creator>
      <dc:date>2019-04-21T13:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update element properties at a certain time using overrules implementation</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8754637#M22653</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you need to avoid modifying of hatch in draw overrule. i feel you need to refactor your code. so that you can avoid "hatch.PatternAngle = element.PanelsAngle" inside draw overrule. One possible solution is to update the "hatch.PatternAngle" same place where "element.PanelsAngle" is updated...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2019 07:37:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8754637#M22653</guid>
      <dc:creator>Virupaksha_aithal</dc:creator>
      <dc:date>2019-04-26T07:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update element properties at a certain time using overrules implementation</title>
      <link>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8755465#M22654</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;You are right but in the code design, each AutoCAD entity has &lt;EM&gt;XData&lt;/EM&gt; contains the associated element ID(but element hasn't reference to the AutoCAD entities).&lt;/P&gt;
&lt;P&gt;So when the element's hatch changed, I need to call a method to update all AutoCAD entities to change hatch angle (and other properties) to avoid updating them in every call to &lt;EM&gt;WorldDraw&lt;/EM&gt; method.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2019 13:47:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/update-element-properties-at-a-certain-time-using-overrules/m-p/8755465#M22654</guid>
      <dc:creator>ahmedshawkey95</dc:creator>
      <dc:date>2019-04-26T13:47:24Z</dc:date>
    </item>
  </channel>
</rss>

