.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 4 (1,122 Views)
Accepted Solution

Dealing with objects in LOCKED layer

1122 Views, 3 Replies
05-01-2012 06:14 PM

Hi

 

I am trying to assign objects (only in UNLOCKED layers) with a new layer.

So basically, the user will select all the objects in the drawing.

After selecting (ex. press enter after window selecting), only objects in UNLOCKED layers will have a new layer.

Following is the code I am using...

But I keep getting eOnLockedLayer exception.

How should I handle this issue?

 

   using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())

            {

                PromptSelectionOptions pSelOpts = new PromptSelectionOptions();

                pSelOpts.MessageForAdding = "Select all objects";

                PromptSelectionResult pSelRes = acDoc.Editor.GetSelection(pSelOpts);

 

                if (pSelRes.Status == PromptStatus.OK)

                {                    

                    SelectionSet acSSet = pSelRes.Value;

                    foreach (SelectedObject acSSObj in acSSet)

                    {

                        if (acSSObj != null)

                        {  

    // This line I am getting eOnLockedLayer exception

                            Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;

                           

                            if (acEnt != null)

                            {

                                acEnt.Layer = "newLayer";

                                acEnt.ColorIndex = 20;                               

                            }

                        }

                    }

                }               

                acTrans.Commit();            

            }

Just stop them being selected

 

// Autodesk.AutoCAD.EditorInput.PromptSelectionOptions
public bool RejectObjectsOnLockedLayers

{ // < ..>

}

 

Regards

 

Valued Mentor
KerryBrown
Posts: 276
Registered: ‎11-29-2008
Message 2 of 4 (1,116 Views)

Re: Dealing with objects in LOCKED layer

05-01-2012 07:52 PM in reply to: dynamicscope

Just stop them being selected

 

// Autodesk.AutoCAD.EditorInput.PromptSelectionOptions
public bool RejectObjectsOnLockedLayers

{ // < ..>

}

 

Regards

 

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

*Expert Elite*
Alfred.NESWADBA
Posts: 9,417
Registered: ‎06-29-2007
Message 3 of 4 (1,097 Views)

Re: Dealing with objects in LOCKED layer

05-01-2012 10:50 PM in reply to: dynamicscope

Hi,

 

...or check the full syntax for TransAction.GetObject:

Public Overridable Function GetObject(id As Autodesk.AutoCAD.DatabaseServices.ObjectId, mode As Autodesk.AutoCAD.DatabaseServices.OpenMode, openErased As Boolean, forceOpenOnLockedLayer As Boolean) As Autodesk.AutoCAD.DatabaseServices.DBObject
     Member von Autodesk.AutoCAD.DatabaseServices.Transaction

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 4 of 4 (1,036 Views)

Re: Dealing with objects in LOCKED layer

06-12-2012 08:16 AM in reply to: Alfred.NESWADBA

ForceOpenOnLockedLayer Parameter, 

 

That sure helped me. Thanks!:smileyhappy:

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!