Author Topic: AutoCAD memory alocation...  (Read 3828 times)

0 Members and 1 Guest are viewing this topic.

dann.boy.001

  • Guest
AutoCAD memory alocation...
« on: January 14, 2011, 06:08:54 AM »

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  :|

Code: [Select]

            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

vegbruiser

  • Guest
Re: AutoCAD memory alocation...
« Reply #1 on: January 14, 2011, 06:44:15 AM »
I suppose it depends on how many entities are added the first time the code runs, and how many are added on subsequent occasions?

dann.boy.001

  • Guest
Re: AutoCAD memory alocation...
« Reply #2 on: January 14, 2011, 07:09:14 AM »
I suppose it depends on how many entities are added the first time the code runs, and how many are added on subsequent occasions?

Number of entities may vary, but I tested adding about 2000 entities.

I can't understand why for first time all is ok, but when again run
function autocad slow down...

Danijel

kaefer

  • Guest
Re: AutoCAD memory alocation...
« Reply #3 on: January 14, 2011, 07:35:40 AM »
[I can't understand why for first time all is ok, but when again run
function autocad slow down...

Wild guess:
By any chance, are you adding the same Entities over and over again? That would explain the crashes, since you may not add an Entity to a Database that you haven't cretead (by way of new or Clone).

Please send the complete code for the chance of a more complete diagnosis...

dann.boy.001

  • Guest
Re: AutoCAD memory alocation...
« Reply #4 on: January 14, 2011, 10:31:56 AM »

Unfortunately, there is a lot of code, and it is imposible
to publish.

I initialize list of variables every time, and entites clone before add it to list,
I will again check it...

Thank you...

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: AutoCAD memory alocation...
« Reply #5 on: January 14, 2011, 01:00:14 PM »
Any chance the entities include annotative objects? in dynamic blocks?
I've seen that bloat drawings dramatically.

What kind of entities are we talking about here?
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

dann.boy.001

  • Guest
Re: AutoCAD memory alocation...
« Reply #6 on: January 14, 2011, 05:45:44 PM »
Any chance the entities include annotative objects? in dynamic blocks?
I've seen that bloat drawings dramatically.

What kind of entities are we talking about here?

I check again, number of entities is more than 13000, maybe it can be problem!?

I am using lines, polylines, MText and RotatedDimension without any additional data.

Finaly I found where is problem, it is RotatedDimension entity.
I am creating dimensions and add to list with below code:

Code: [Select]

        Dim acRotDim1 As RotatedDimension = New RotatedDimension()
        acRotDim1.SetDatabaseDefaults()
        acRotDim1.XLine1Point = New Point3d(CrossParametri.ptLL.X, Centar.Z + CrossParametri.ptLL.Y, 0)
        acRotDim1.XLine2Point = New Point3d(CrossParametri.ptLD.X, Centar.Z + CrossParametri.ptLD.Y, 0)
        acRotDim1.DimLinePoint = New Point3d(CrossParametri.ptLL.X, Centar.Z + CrossParametri.ptLL.Y + 5, 0)
        acRotDim1.DimensionStyle = KoteKlasa.dsId

        List.Add(acRotDim1)



Danijel
« Last Edit: January 15, 2011, 04:18:05 AM by dann.boy.001 »

dann.boy.001

  • Guest
Re: AutoCAD memory alocation...
« Reply #7 on: January 15, 2011, 04:22:27 AM »
Finaly, problem is in setting dimension style after creating entity. :?

I will set current dimension style, and I think all will be ok.
« Last Edit: January 15, 2011, 04:41:47 AM by dann.boy.001 »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: AutoCAD memory alocation...
« Reply #8 on: January 15, 2011, 06:18:15 AM »
I ran this 35 times so over half million entites.
Can you run this?

Code: [Select]


        <CommandMethod("CreateCircles")> _
        Public Sub CreateCircles()

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database


            Using trx As Transaction = db.TransactionManager.StartTransaction


                Dim EntsList As New List(Of Entity)
                Dim rdn As New Random

                For i As Integer = 0 To 15000

                    Dim dimTbl As DimStyleTable = db.DimStyleTableId.GetObject(OpenMode.ForRead)
                    Dim dimTblRecAnno As DimStyleTableRecord = dimTbl("Annotative").GetObject(OpenMode.ForRead)
                    Dim dimTblRecStd As DimStyleTableRecord = dimTbl("Annotative").GetObject(OpenMode.ForRead)
                    db.Dimstyle = dimTblRecStd.ObjectId
                    Dim x As Double = rdn.Next(500)
                    Dim y As Double = rdn.Next(500)
                    Dim rad As Double = rdn.Next(10)
                    Dim c As New Circle(New Point3d(x, y, 0), Vector3d.ZAxis, rad)

                    EntsList.Add(c)
                    Dim acRotDim1 As RotatedDimension = New RotatedDimension()
                    acRotDim1.SetDatabaseDefaults()
                    acRotDim1.XLine1Point = New Point3d(x, y, 0)
                    acRotDim1.XLine2Point = New Point3d(x + 5, y, 0)
                    acRotDim1.DimLinePoint = New Point3d(x, y + 5, 0)
                    acRotDim1.DimensionStyle = dimTblRecAnno.ObjectId
                Next
                AddEntities(EntsList)
                trx.Commit()
            End Using

        End Sub

        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()


                Dim myBT As Autodesk.AutoCAD.DatabaseServices.BlockTable = doc.Database.BlockTableId.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)                '
                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

Jeff H

  • Needs a day job
  • Posts: 6150
Re: AutoCAD memory alocation...
« Reply #9 on: January 15, 2011, 06:30:34 AM »
I left this out

 EntsList.Add(acRotDim1)


Code: [Select]

 acRotDim1.SetDatabaseDefaults()
                    acRotDim1.XLine1Point = New Point3d(x, y, 0)
                    acRotDim1.XLine2Point = New Point3d(x + 5, y, 0)
                    acRotDim1.DimLinePoint = New Point3d(x, y + 5, 0)
                    acRotDim1.DimensionStyle = dimTblRecAnno.ObjectId

                    EntsList.Add(acRotDim1)

It went from taking 1 not even 2 seconds to around 10 to 15 seconds after adding line.

Ran out of memory on the 8th time.

kaefer

  • Guest
Re: AutoCAD memory alocation...
« Reply #10 on: January 15, 2011, 08:57:57 AM »
It went from taking 1 not even 2 seconds to around 10 to 15 seconds after adding line.

Ran out of memory on the 8th time.

So this behaviour is totally correct and by design, then?  Your dimensions seem to incur an overhead around ten times the simple objects, in terms of time and space.

Might be an idea to check for the available memory, at a cost of 3-5 kB per dimenson.

Cheers

Jeff H

  • Needs a day job
  • Posts: 6150
Re: AutoCAD memory alocation...
« Reply #11 on: January 15, 2011, 09:08:50 AM »
I have never used RotatedDimension, but I am sure the 15,000 blocks added did not help.

When MgdDbg took 5 to 10 seconds to open I knew something was up.

Thorsten,
regular dimensions do not add blocks do they?
*******Edited***********
Tested and I guess they do


Quote
When a newly created dimension entity is first closed, an anonymous block (an BlockTableRecord that contains all the appropriate line, arc, arrowhead solids, text, etc. and with *D as the block name prefix) is automatically created for it to reference for display.

If the dimension has been set to use the text position value rather than the default text position (that is, Dimension.UsingDefaultTextPosition has been called) and the DIMFIT system variable is not set to 4, then the text position takes precedence over the dimLine setting in placing the dimension line so that it lines up with the text position.