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

    .NET

    Reply
    Contributor
    hassanhafeez33
    Posts: 14
    Registered: ‎09-16-2011
    Accepted Solution

    Too much CPU and Memory usage. Too slow results.

    180 Views, 3 Replies
    10-11-2011 08:33 AM

    Hello people. Its good to be back after a month of daily programming. 

    I have made a professional application for autocad from ground up. It achieves the aims of sorting crossections of roads. 

     

    The only problem with the code is inside one routine which has to take the empty graph in a drawing and make multiple copies of it.  The code is attached in the attachment. 

     

    For some reason, the routine takes almost more than 4 minutes to finish. There are almost 1600 objects that it has to copy and move for about ten times. 

     

    My question is, Is there a way to move the graph as a single object. As in, all the objects in the graph behaving as one object? 

     

    Any help would be greatly appreciated. N.B I have had quite a lot of fun developing the app, although Im an electronics engineer :smileyvery-happy: 

    acDoc.Editor.WriteMessage(vbLf & "This is time to select the main graph window")
                        Dim graphprompt As PromptSelectionResult
                        graphprompt = acDocEd.GetSelection
                        If graphprompt.Status = PromptStatus.OK Then
                            Dim Graph = graphprompt.Value
                            Dim graphobjidcoll = New ObjectIdCollection(Graph.GetObjectIds())
                            Dim count1
                            Dim x1 = 210
                            For count1 = 0 To graphsneeded
                                For Each graphobjid As ObjectId In graphobjidcoll
                                    Dim obj As DBObject = trans.GetObject(graphobjid, OpenMode.ForRead)
                                    Dim objclone As Entity
                                    objclone = obj.Clone()
                                    objclone.SetDatabaseDefaults()
                                    objclone.TransformBy(Matrix3d.Displacement(New Vector3d(x1, 0, 0)))
                                    acBlkTblRec.AppendEntity(objclone)
                                    trans.AddNewlyCreatedDBObject(objclone, True)
                                    db.TransactionManager.QueueForGraphicsFlush()
                                    obj.Dispose()
                                Next
                                x1 = x1 + 210
                            Next
                            graphobjidcoll.Clear()
                        End If

     

    Please use plain text.
    ADN Support Specialist
    Posts: 261
    Registered: ‎05-22-2006

    Re: Too much CPU and Memory usage. Too slow results.

    10-11-2011 11:22 AM in reply to: hassanhafeez33

    Skimming your code, I have two quick comments:

     

    As a general rule, it is risky to perform a shallow clone of an entity (DBObject.Clone). Its better to use the appropriate DeepClone or WblockClone methods. As you're copying a set of entities within the same database, have you tried using Database.DeepCloneObjects with your ObjectIdCollection, instead of iterating the collection and cloning one-by-one? That may be faster.

     

    And I'm not sure why you want to call QueueForGraphicsFlush for every iteration of the inner loop - that looks like an unnecesary call to me. I'm not familiar with how that method is implemented, but it could account for a lot of CPU overhead in your routine.

    Cheers,

    Stephen Preston
    Autodesk Developer Network
    Please use plain text.
    Contributor
    hassanhafeez33
    Posts: 14
    Registered: ‎09-16-2011

    Re: Too much CPU and Memory usage. Too slow results.

    10-11-2011 11:33 AM in reply to: StephenPreston

    Hi Stephen, 

    Thanks alot for ur reply. 

    I was not exactly sure earlier what is the difference between deepclone and simple object clone. I guess I am going to take a look into it now. 

    Quefor graphics flush is just to see the moved objects before the transaction is committed. Ofcourse I do not need it in every loop. Thanks for pointing that out. 

    And Ill take a look into Database.deepcloneobjects as well. 

     

    Thanks a lot for your help. I'm just an electronics engineer spending some time with my father's business doing some programming for him. 

     

    Cheers,

    Hassan.

    Please use plain text.
    Contributor
    hassanhafeez33
    Posts: 14
    Registered: ‎09-16-2011

    Re: Too much CPU and Memory usage. Too slow results.

    10-15-2011 03:58 AM in reply to: StephenPreston

    Thanks for suggesting the removal of QueForGraphicsFlush(), Stephen.

    It really improved the performance a lot. 

     

    Regards,

    Hassan Hafeez.

    Please use plain text.