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

Dealing with objects in LOCKED layer

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
dynamicscope
3269 Views, 3 Replies

Dealing with objects in LOCKED layer

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();            

            }

3 REPLIES 3
Message 2 of 4
kdub_nz
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

Message 3 of 4

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 4 of 4

ForceOpenOnLockedLayer Parameter, 

 

That sure helped me. Thanks!Smiley Happy

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost