.NET

Reply
Valued Mentor
AubelecBE
Posts: 394
Registered: ‎01-27-2010
Message 1 of 7 (415 Views)
Accepted Solution

How to list all linetype of Acad.lin

415 Views, 6 Replies
04-01-2012 10:19 PM

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

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

 

Active Contributor
DesignProQuig
Posts: 32
Registered: ‎03-02-2012
Message 2 of 7 (397 Views)

Re: How to list all linetype of Acad.lin

04-02-2012 09:31 AM 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/
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 3 of 7 (388 Views)

Re: How to list all linetype of Acad.lin

04-02-2012 03:08 PM 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
Valued Mentor
jeff
Posts: 335
Registered: ‎05-12-2009
Message 4 of 7 (381 Views)

Re: How to list all linetype of Acad.lin

04-02-2012 07:45 PM 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
Valued Mentor
AubelecBE
Posts: 394
Registered: ‎01-27-2010
Message 5 of 7 (375 Views)

Re: How to list all linetype of Acad.lin

04-02-2012 10:25 PM 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.

 

 

 

Valued Mentor
AubelecBE
Posts: 394
Registered: ‎01-27-2010
Message 6 of 7 (347 Views)

Re: How to list all linetype of Acad.lin

04-03-2012 10:24 AM 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

 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 7 of 7 (338 Views)

Re: How to list all linetype of Acad.lin

04-03-2012 12:34 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!