Unlock layer of selected object

Unlock layer of selected object

Anonymous
Not applicable
760 Views
1 Reply
Message 1 of 2

Unlock layer of selected object

Anonymous
Not applicable

 

I have a drawing file which contains several layers and some of which are locked. When I select objects and want to display block name, I can do that easily for objects in unlocked layers but when I come across objects in Locked layer code throws an error "eOnLockedLayer" and exits. 

 

My question is, how can I find the layer associated with the selected object and unlock it if it is locked > Display Blockname > lock that particular layer again.

 


Thank you,

0 Likes
761 Views
1 Reply
Reply (1)
Message 2 of 2

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

 

I have a drawing file which contains several layers and some of which are locked. When I select objects and want to display block name, I can do that easily for objects in unlocked layers but when I come across objects in Locked layer code throws an error "eOnLockedLayer" and exits. 

 

My question is, how can I find the layer associated with the selected object and unlock it if it is locked > Display Blockname > lock that particular layer again.

 


Thank you,


You can use the optional 4th argument to the Transaction.GetObject() method to open objects on locked layers for write:

 

 

  myTransaction.GetObject(someObjectId, OpenMode.ForWrite, false, true);


When OpenMode is OpenMode.ForWrite, and the forth argument is true, you will not get an eOnLockedLayer exception, and there's no need to unlock any layers.