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

ReadDWGFile Slow in ACAD2013

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
GeeHaa
1368 Views, 9 Replies

ReadDWGFile Slow in ACAD2013

Hi,

I recently converted a vb.net program that extracts attribute data to work with ACAD2013. The program runs but is very slow It takes a full 10 minutes to read 120 small dwg files. The same program running in ACAD2010 takes about 3 seconds. Has anyone else run into this?

 

Thanks in Advance

 

G.

9 REPLIES 9
Message 2 of 10
fenton.webb
in reply to: GeeHaa

can you send us some sample code please? I'd like to test it for you to see where the problem is.




Fenton Webb
AutoCAD Engineering
Autodesk

Message 3 of 10
GeeHaa
in reply to: GeeHaa

For x As Integer = 0 To UBound(listOfFiles)
            Dim layoutStrings() As String = Nothing
            Dim acCurDB As New Database(False, True)
            acCurDB.ReadDwgFile(listOfFiles(x), FileOpenMode.OpenForReadAndReadShare, True, "")
              Using acTrans As Transaction = acCurDB.TransactionManager.StartTransaction
                Dim acLayoutMgr As LayoutManager
                acLayoutMgr = LayoutManager.Current
                 Dim layoutdict As DBDictionary = acTrans.GetObject(acCurDB.LayoutDictionaryId, OpenMode.ForRead)
                ReDim layoutStrings(layoutdict.Count - 2)
                For Each Ent As DBDictionaryEntry In layoutdict
                    Dim desc_Txt As String = ""
                    Dim lay As Layout = acTrans.GetObject(Ent.Value, OpenMode.ForRead)
                    Dim layBTRId As ObjectId = lay.BlockTableRecordId
                    Dim btr As BlockTableRecord = TryCast(layBTRId.GetObject(OpenMode.ForRead), BlockTableRecord)
                    If (Not lay.LayoutName = "Model") Then
                        myWS.Cells(curRow, "D") = File.GetLastWriteTime(listOfFiles(x))
                        For Each entId3 As ObjectId In btr
                            Dim ent3 As Entity = entId3.GetObject(OpenMode.ForRead)
                            Dim nextRow As Boolean = False

                            If TypeOf ent3 Is DatabaseServices.BlockReference Then
                                Dim bref As BlockReference = ent3

                                Dim atts As AttributeCollection = bref.AttributeCollection

                                For Each attId As ObjectId In atts
                                    Dim AttRef As AttributeReference = attId.GetObject(OpenMode.ForRead)
                                    Select Case AttRef.Tag

                                        Case getTags(0)
                                            If Trim(AttRef.TextString) <> "" Then
                                                myWS.Cells(curRow, "A") = AttRef.TextString
                                                myWS.Cells(curRow, "J") = fixDwgName(AttRef.TextString)
                                                myWS.Cells(curRow, "G") = ListOfNames(x)
                                            End If

                                        Case getTags(1)
                                            If Trim(AttRef.TextString) <> "" Then
                                                myWS.Cells(curRow, "C") = Trim(AttRef.TextString)
                                            End If
                                                                                    Case getTags(2)
                                            If Trim(AttRef.TextString) <> "" Then
                                                myWS.Cells(curRow, "E") = Trim(AttRef.TextString)
                                            End If

                                            
                                        Case getTags(3)
                                            If Trim(AttRef.TextString) <> "" Then
                                                myWS.Cells(curRow, "F") = Trim(AttRef.TextString)
                                            End If

                                     End Select
                                Next attId
                                Dim tempstr As String = ""
                                For x2 As Integer = 4 To getTags.Count - 1
                                    For Each attId As ObjectId In atts
                                        Dim AttRef As AttributeReference = attId.GetObject(OpenMode.ForRead)
                                        If AttRef.Tag = getTags(x2) Then
                                            tempstr = tempstr + AttRef.TextString + " "
                                        End If
                                    Next attId
                                Next
                                If (Not Trim(tempstr) = "") Then
                                    myWS.Cells(curRow, "B") = Trim(tempstr)
  
                                End If

                                If nextRow = True Then
                                     curRow += 1

                                End If
                            End If
                            'End If 'invp

                        Next entId3
                        curRow += 1
                    End If
                    'MsgBox("layoutname = " + lay.LayoutName)
                Next
                acTrans.Dispose()
            End Using
            acCurDB.CloseInput(True)
        Next

 Here it is Some of it. I hope it's all you need.

 

Thanks Very Much

Message 4 of 10
fenton.webb
in reply to: GeeHaa

remove closeInput and also try changing the open mode to just read (no sharing)




Fenton Webb
AutoCAD Engineering
Autodesk

Message 5 of 10
jeff
in reply to: fenton.webb

Try commiting your transaction instead of disposing it which will call Abort

http://www.theswamp.org/index.php?topic=44037.msg493005#msg493005

 

You can also find your answers @ TheSwamp
Message 6 of 10
GeeHaa
in reply to: GeeHaa

Removing CloseInput helped. Still Not as fast as 2010 and it crashes at about 1600 drawings always on a different drawing though. Is anything else wrong that you can see? I also committed the Transaction instead of disposing it

 

Thanks Again

Message 7 of 10
fenton.webb
in reply to: GeeHaa

make sure you set the workingDatabase. Also, if you are not writing anything I recommend you use StartOpenCloseTransaction instead of StartTransaction




Fenton Webb
AutoCAD Engineering
Autodesk

Message 8 of 10
GeeHaa
in reply to: GeeHaa

I added your recommendations but it still crashes with the following error at around 1600 drawings out of 2100.

 

System.AccessViolationException was unhandled
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=Acdbmgd
  StackTrace:
       at Autodesk.AutoCAD.Runtime.RXObject.DeleteUnmanagedObject()
       at Autodesk.AutoCAD.Runtime.DisposableWrapper.!DisposableWrapper()
       at Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose(Boolean )
  InnerException:

 

Thanks

Message 9 of 10
_gile
in reply to: GeeHaa

Hi,

 

You do not need to explicitly dispose your transaction as you're using a 'Using' block.

You might dispose the side Database too.

 

Using acCurDB As New Database(False, True)
    acCurDB.ReadDwgFile(listOfFiles(x), FileOpenMode.OpenForReadAndReadShare, True, "")
    Using acTrans As Transaction = acCurDB.TransactionManager.StartTransaction

    ' ...

    End Using
End Using

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 10
GeeHaa
in reply to: GeeHaa

Disposing of the side database worked. AS far as speed goes I was running the program in Debug Mode. The release version is as fast as 2010 if not faster.

 

Thanks Again

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