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

How to list all linetype of Acad.lin

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
AubelecBE
1302 Views, 6 Replies

How to list all linetype of Acad.lin

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

6 REPLIES 6
Message 2 of 7
DesignProQuig
in reply to: AubelecBE

There was a post on this subject here:

http://through-the-interface.typepad.com/through_the_interface/2010/03/loading-multiple-linetypes-in...

 

Hope that helps.

 

Quigs.

http://www.designprosoftware.co.uk/
Message 3 of 7
chiefbraincloud
in reply to: AubelecBE

I'm Not 100% sure this will solve the problem, but try calling db.CloseInput(True) before calling db.Dispose.

Dave O.                                                                  Sig-Logos32.png
Message 4 of 7
jeff
in reply to: AubelecBE

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]);
                    
                    }

                }            
            }

        }

 

You can also find your answers @ TheSwamp
Message 5 of 7
AubelecBE
in reply to: jeff

thank all

DesignProQuiq --> I dont want load all typeline in my current drawing.

Jeff --> Oh i have to test that tomorrow.

 

 

 

Message 6 of 7
AubelecBE
in reply to: AubelecBE

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

 

Message 7 of 7
chiefbraincloud
in reply to: AubelecBE

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.

Dave O.                                                                  Sig-Logos32.png

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