here my code :
Public Function LectureDefLine() As Collection Dim db As Database = New Database(True, False) Dim OkErreur As Boolean = False dim cCollDefTypeLine as collection = New Collection Try Dim path As String = HostApplicationServices.Current.FindFile("acad.lin", db, FindFileHint.Default) db.LoadLineTypeFile("*", path) Catch ex As Autodesk.AutoCAD.Runtime.Exception If (ex.ErrorStatus = Autodesk.AutoCAD.Runtime.ErrorStatus.FilerError) Then MsgBox("Impossible de trouver le fichier " & "acad.lin", MsgBoxStyle.Information, "Erreur système") OkErreur = True ElseIf (ex.ErrorStatus = Autodesk.AutoCAD.Runtime.ErrorStatus.DuplicateRecordName) Then 'Ligne déja connu --> passe Else MsgBox(ex.ToString, MsgBoxStyle.Information, "Erreur système") OkErreur = True End If End Try If OkErreur = False Then 'iterate les typeline Dim tr As Transaction = db.TransactionManager.StartTransaction() Try Dim TypelineT As DBObject = tr.GetObject(db.LinetypeTableId, OpenMode.ForRead) Dim tbl As SymbolTable = CType(TypelineT, SymbolTable) If IsNothing(tbl) = False Then Dim tblRecId As ObjectId For Each tblRecId In tbl Dim tmpObj1 As DBObject = tr.GetObject(tblRecId, OpenMode.ForRead) Dim rec As SymbolTableRecord = CType(tmpObj1, LinetypeTableRecord) If Not (rec Is Nothing) Then cCollDefTypeLine.Add(rec.Name, rec.Name) 'ed.WriteMessage("Adding LineType " & rec.Name & vbCrLf) End If Next End If Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Information, "err") Finally tr.Commit() tr.Dispose() End Try End If db.Dispose() db = Nothing Return cCollDefTypeLine End Function
cCollDefTypeLine : i use it for populate a ComboxColumn of a dataview.
I want populate a ColumnDataview but not integrate all the linetype in mu current dwg.
This code run but acad crash after .. So have you a function/sub working fine ?
Thx All
Solved! Go to Solution.
There was a post on this subject here:
Hope that helps.
Quigs.
I'm Not 100% sure this will solve the problem, but try calling db.CloseInput(True) before calling db.Dispose.
You could also mkaybe do something like this?
[CommandMethod("ListLineTypes")] public void ListLineTypes() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; string path = HostApplicationServices.Current.FindFile("acad.lin", db, FindFileHint.Default); using (StreamReader sr = new StreamReader(path)) { Char[] c = new Char[] { ',' }; while (sr.Peek() >= 0) { string s = sr.ReadLine(); if (s.StartsWith("*")) { string[] info = s.Split(c); ed.WriteMessage("\nName:{0} --- Description:{1}", info[0].Substring(1), info[1]); } } } }
thank all
DesignProQuiq --> I dont want load all typeline in my current drawing.
Jeff --> Oh i have to test that tomorrow.
Thx it is working good.
Here the code in vb.net.
Public Function LectureDefLine() As Collection 'chargement des type de ligne connu Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database 'Dim ed As Autodesk.AutoCAD.EditorInput.Editor = doc.Editor cCollDefTypeLine = New Collection Dim path As String = HostApplicationServices.Current.FindFile(NomFichierLigne, db, FindFileHint.Default) Using sr As System.IO.StreamReader = New System.IO.StreamReader(path) Dim c As Char() = New Char() {","} While (sr.Peek() >= 0) Dim s As String = sr.ReadLine() If (s.StartsWith("*")) Then Dim info() As String = s.Split(c) 'ed.WriteMessage("\nName:{0} --- Description:{1}", info(0).Substring(1), info(1)) cCollDefTypeLine.Add(info(0).Substring(1), info(0).Substring(1)) End If End While End Using Return cCollDefTypeLine End Function
I swear I posted this last night, but it is not here now, so here it is again.
I noticed something, and checked my own code, and I believe the problem with your original code was the New Database constructor. My code is always reading an existing drawing, and calls New Database (False, True). With your code creating a databse from scratch, I think you did need the first argument {buildDefaultDrawing} to be True, but you definitely needed the second argument {noDocument} to be True.
That is pretty much "For your information", because I agree that if all you need is a list of linetype names, it is better to just parse them out of the text file than to do all that stuff with the new database.
Can't find what you're looking for? Ask the community or share your knowledge.