.NET

Reply
Distinguished Contributor
GeeHaa
Posts: 150
Registered: ‎04-14-2005
Message 1 of 10 (562 Views)
Accepted Solution

ReadDWGFile Slow in ACAD2013

562 Views, 9 Replies
06-12-2013 10:32 AM

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.

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 10 (510 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 08:36 AM 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

Developer Technical Services

Autodesk Developer Network


Distinguished Contributor
GeeHaa
Posts: 150
Registered: ‎04-14-2005
Message 3 of 10 (506 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 09:20 AM 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

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 4 of 10 (499 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 11:49 AM in reply to: GeeHaa

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





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Mentor
jeff
Posts: 327
Registered: ‎05-12-2009
Message 5 of 10 (490 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 01:06 PM 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
Distinguished Contributor
GeeHaa
Posts: 150
Registered: ‎04-14-2005
Message 6 of 10 (485 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 02:56 PM 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

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 7 of 10 (482 Views)

Re: ReadDWGFile Slow in ACAD2013

06-19-2013 03:02 PM 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

Developer Technical Services

Autodesk Developer Network


Distinguished Contributor
GeeHaa
Posts: 150
Registered: ‎04-14-2005
Message 8 of 10 (458 Views)

Re: ReadDWGFile Slow in ACAD2013

06-20-2013 12:19 PM 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

*Expert Elite*
_gile
Posts: 2,082
Registered: ‎04-29-2006
Message 9 of 10 (439 Views)

Re: ReadDWGFile Slow in ACAD2013

06-21-2013 06:13 AM 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
Distinguished Contributor
GeeHaa
Posts: 150
Registered: ‎04-14-2005
Message 10 of 10 (407 Views)

Re: ReadDWGFile Slow in ACAD2013

06-24-2013 11:14 AM 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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.