.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Disable layer edit functionality

1 REPLY 1
Reply
Message 1 of 2
Anonymous
424 Views, 1 Reply

Disable layer edit functionality

Hi!

 

In our custom application we don't want the user to be able to
create/rename/delete the existing layers from the autocad layer palette.

We want to retain the layer palette but just block those functions.

Please let us know if it is possible to do so.

Thanks!

1 REPLY 1
Message 2 of 2
norman.yuan
in reply to: Anonymous

The usual approach of preventing AutoCAD to do something is to handle DocumentLockModeChanged event and veto particular command. However, in your case, that approach could not be used, because the command "Layer" has more options, besides creating/renaming layers, and layers can also be created, renamed, or even deleted from AutoCAD built-in UI (Layer Manager).

 

to preventing layer from being renamed or deleted (assume the layer is empty layer, of course), you probably can use ObjectOverrule. That is:

 

1. To prevent renaming, in overridden Open() method, you watch layer being opened for writing, and save the layer name in class level. And then in Close() method, compare the layer's OBjectId and name to determine if the name has been changed. If yes, you can change them back.

 

2. To preventing deleting, in overridden Erase() method, you can raise an eNotApplicable exception, as Kean's article shows.

 

I wrote a bit of code to quickly test the ObjectOverrule idea and successfully prevented layer being renamed and erased.

 

However, it is difficult to prevent layer to be created. In this case, OBjectOverrule does not apply because it only works with existing object (i.e. after layer being created). I imagine you probably need to watch Database events to find out if a new layer has been added to database and after the fact you can somehow erase it right away (of course, if you have already implemented an ObjectOverrule to prevent erasing, you need to temporarily disable it).

 

Even you successfully did all above, if the user uses AutoCAD UI (Layer Manager) to create/rename/delete layers, the layers may remain unchanged, the the UI would be likely show the change user makes and closing and reopening it is probably required to re-sync/restore the UI to show the correct, unchanged Layer information.

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report