Update element properties at a certain time using overrules implementation

ahmedshawkey95
Advocate

Update element properties at a certain time using overrules implementation

ahmedshawkey95
Advocate
Advocate

Hi,

I'm using the following DrawableOverrule  implementation to update color and pattern angle for hatches (filtered by XData).

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.

 

But I had to open transaction every time WorldDraw is called which affected the performance.

Do I need to implement another overrule method (something like InvalidateEntities) to be called manually when required only (not at any change in the geometric shape)?

 

my DrawableOverrule  implementation:

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) 
return base.WorldDraw(drawable, wd);
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; } } }

 And when the user update my element's properties:

 

        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();
                }
            }
        }

 

0 Likes
Reply
470 Views
2 Replies
Replies (2)

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

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... 

 

 

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes

ahmedshawkey95
Advocate
Advocate

Thanks for your reply.

You are right but in the code design, each AutoCAD entity has XData contains the associated element ID(but element hasn't reference to the AutoCAD entities).

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 WorldDraw method.

0 Likes