1 /// <summary> 2 /// 加载CAD自定义线型 3 /// </summary> 4 /// <param name="strLinetype"></param> 5 /// <param name="strFileName"></param> 6 /// <param name="Success"></param> 7 /// <returns></returns> 8 /// LoadLinetype("RL", "C:/Users/Administrator/Desktop/断面方面.lin", ref success1)); 9 public ObjectId LoadLinetype(string strLinetype, string strFileName, ref bool Success) 10 { 11 ObjectId myLinetypeId = new ObjectId(); 12 Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; 13 Database db = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase; 14 Transaction trans = db.TransactionManager.StartTransaction(); 15 try 16 { 17 LinetypeTable myLinetypeTable = (LinetypeTable)trans.GetObject(db.LinetypeTableId, OpenMode.ForRead); 18 if (myLinetypeTable.Has(strLinetype)) 19 { 20 Success = true; 21 return myLinetypeId = myLinetypeTable[strLinetype]; 22 } 23 else 24 { 25 db.LoadLineTypeFile(strLinetype, strFileName); 26 myLinetypeId = myLinetypeTable[strLinetype]; 27 Success = myLinetypeTable.Has(strLinetype); 28 trans.Commit(); 29 } 30 } 31 catch 32 { 33 ed.WriteMessage("\nError"); 34 } 35 finally 36 { 37 trans.Dispose(); 38 } 39 return myLinetypeId; 40 }