Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Object is referenced by other object(s) exception

0 REPLIES 0
Reply
Message 1 of 1
Kaustubh.Devasthali
220 Views, 0 Replies

Object is referenced by other object(s) exception

Hello Everyone,

 

I am trying to create a standalone exe project which removes some unwanted layers from a AutoCAD drawing.

I am using Visual Studio 2010 with .NET Framework4 and C#.NET as programming language.

I have AutoCAD 2014 installed on my machine.

 

When i try to run the following code, I get the exception - "Object is referenced by other object(s)"

 

 

Autodesk.AutoCAD.Interop.AcadApplication acadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.19.1");

 

Autodesk.AutoCAD.Interop.AcadDocument acadDoc = acadApp.Documents.Open("AutoCAD Drawing File Path", false);

 

foreach (Autodesk.AutoCAD.Interop.Common.AcadLayer Layer in acadDoc.Layers)
            {
                string sLayerName = Layer.Name;

                

                // check the layer is not among the layers that we want to keep in the drawing


                IEnumerable<DataRow> drLayer = from layer in dtLayers.AsEnumerable()
                                               where layer.Field<string>("Layer").Trim() == sLayerName
                                               select layer;

                if (drLayer.Count<DataRow>() == 0)
                {                   
                        //Layer.LayerOn = false;  // works fine                     

                        Layer.Delete(); // throws exception

                        acadApp.Application.Update();
                }
            }

 

 

 

Please tell me the solution for this problem.

 

Thanks,

Kaustubh Devasthali.

 

0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report

”Boost