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 😄
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
Solved! Go to Solution.
Solved by StephenPreston. Go to Solution.
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.
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.
Thanks for suggesting the removal of QueForGraphicsFlush(), Stephen.
It really improved the performance a lot.
Regards,
Hassan Hafeez.