Message 1 of 7

Not applicable
07-06-2016
06:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Guys,
This is what I am trying to do,
- Access a remote dwg and get the lsit of layers
- Check if the layers exists in the current drawing
- Create the layers (bulk)
I am able to first two points, last point is there AutoCAD crahsing.
I have a collection of layertablerecord. Which says the count is 4 when do a foreach on that to read the layer names it is crashing autocad.
List<LayerTableRecord> layers = new List<LayerTableRecord>(); layers = Helper.CADHelper.GetLayerfromDWG(GV.dwgTemplatePath, layernames);
public static void AddLayersToCurrentDrawing(List<LayerTableRecord> layerList) { if (layerList == null) throw new ArgumentNullException("layerList"); if (layerList.Count == 0) throw new ArgumentOutOfRangeException("layerList"); var curDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; if (curDoc == null) throw new ArgumentNullException("MdiActiveDocument"); var curDb = curDoc.Database; try { using (var trans = curDb.TransactionManager.StartOpenCloseTransaction()) { var layerTable = (LayerTable)trans.GetObject(curDb.LayerTableId, OpenMode.ForWrite); foreach (var layer in layerList) { if (layerTable.Has(layer.Name)) continue; layerTable.Add(layer); trans.AddNewlyCreatedDBObject(layer, true); } trans.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { System.Diagnostics.Debug.Write(ex.ToString()); curDoc.Editor.WriteMessage(ex.ToString()); } catch (SystemException ex) { curDoc.Editor.WriteMessage(ex.ToString()); } }
it is crashing at the highlighted line. When creating layer.
Please advise.
Solved! Go to Solution.