.NET

Reply
Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 1 of 2 (124 Views)

How to reject layer deleting

124 Views, 1 Replies
08-17-2012 04:47 AM

I want to lock my layer from deleting.

 

I did it as for object:

 

    public class NonErasableLayer : ObjectOverrule
    {
        public NonErasableLayer()
        {
            this.SetCustomFilter();
        }

 

        protected override void Dispose(bool value)
        {
            this.SetNoFilter();
            base.Dispose(value);
        }

 

        public override bool IsApplicable(Autodesk.AutoCAD.Runtime.RXObject overruledSubject)
        {
            if (overruledSubject == null)
                return false;

            return (overruledSubject is LayerTableRecord);
        }

 

        public override void Erase(DBObject dbObject, bool erasing)
        {
            if (dbObject is LayerTableRecord)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLAYER IS LOCKED.\n");
            }

            throw new Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.NotApplicable);
        }
    }

 

Then I set overrule for Drawable objects:

 

     ObjectOverrule.AddOverrule(RXClass.GetClass(typeof(Drawable))...

 

When I run it I saw my message from Erase method but... layer is deleted.

This method works fine for any objects as Line or Circle, but doen't work for layer.

 

How I can reject layer deleting?

 

Thanks,

Pavel.

 

 

 

Valued Mentor
jeff
Posts: 335
Registered: ‎05-12-2009
Message 2 of 2 (110 Views)

Re: How to reject layer deleting

08-17-2012 12:19 PM in reply to: pva75

In link below is a similar thread and was to store the LayerTableRecord's ObjectIDs as Hard Pointers.

 

Would use the advice to store in Owners ExtensionDictionary

 

http://www.theswamp.org/index.php?topic=41870.msg469858#msg469858

You can also find your answers @ TheSwamp
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!