• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 258
    Registered: ‎01-27-2010
    Accepted Solution

    How to list all linetype of Acad.lin

    290 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

    Please use plain text.
    Active Contributor
    Posts: 28
    Registered: ‎03-02-2012

    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/
    Please use plain text.
    *Expert Elite*
    chiefbraincloud
    Posts: 736
    Registered: ‎02-13-2008

    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
    Please use plain text.
    Mentor
    Posts: 241
    Registered: ‎05-12-2009

    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
    Please use plain text.
    Mentor
    Posts: 258
    Registered: ‎01-27-2010

    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.

     

     

     

    Please use plain text.
    Mentor
    Posts: 258
    Registered: ‎01-27-2010

    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

     

    Please use plain text.
    *Expert Elite*
    chiefbraincloud
    Posts: 736
    Registered: ‎02-13-2008

    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
    Please use plain text.