Update element properties at a certain time using overrules implementation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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(); } } }