Hello!
I am using below code to add list of entites into autocad.
After first time adding entities, autocad alocate about 50MB additional memory,
but after using same function second time (for same number of entities, than AutoCAD
alocate about 300MB memory more and signitifical slow down performance (about 5-10 sec).
Tested:
If I add entities to autocad, and than close AutoCAD file, and again open it, than
for first time all is ok. After second time calling function again AutoCAD alocate to
much memory, and slow down perfomance.
'If I repeat this few times, than autocad crash (memory insuficient).
Any idea, what is reason for this
Public Sub AddEntities(ByVal Ents As List(Of Entity))
If Ents Is Nothing Then Exit Sub
Dim lock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument()
Using myTrans As Transaction = doc.TransactionManager.StartTransaction()
'Open the database for Read
Dim myBT As Autodesk.AutoCAD.DatabaseServices.BlockTable = doc.Database.BlockTableId.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
'Open ModelSpace for Write
Dim myBTR As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord = myBT(Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace).GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
For Each Ent As Entity In Ents
Ent.SetDatabaseDefaults()
myBTR.AppendEntity(Ent)
myTrans.AddNewlyCreatedDBObject(Ent, True)
Next
myTrans.Commit()
End Using
lock.Dispose()
End Sub