Hi All,
To create a leader with annotation , I am using below code. Leader and annotation create without any problem. But one disgusting thing is that it took very long time if I use the command first time after opening ACAD. But afterwards when I use the command it execute very quickly. Can any body help me to optimize this code?
<CommandMethod("leadertest")> PublicSubleadertest()
Application.SetSystemVariable("dimldrblk", "_dot")
Dim acDoc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim acCurDb AsDatabase= acDoc.Database
Using acTrans AsTransaction= acCurDb.TransactionManager.StartTransaction()
Dim acBlkTbl AsBlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)
Dim acBlkTblRec AsBlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(
BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim mtextId AsObjectIdDim mtxt AsMText = NewMText()
mtxt.SetDatabaseDefaults()
mtxt.Contents =
"first line/sencond line"
mtxt.Location =
NewPoint3d(4, 4, 0)
mtxt.TextHeight = 0.25
mtxt.Attachment =
AttachmentPoint.MiddleLeft
mtxt.SetAttachmentMovingLocation(mtxt.Attachment)
mtextId = acBlkTblRec.AppendEntity(mtxt)
acTrans.AddNewlyCreatedDBObject(mtxt,
True)
Dim acLdr AsLeader = NewLeader()
acLdr.SetDatabaseDefaults()
acLdr.AppendVertex(
NewPoint3d(2, 2, 0))
acLdr.AppendVertex(
NewPoint3d(4, 4, 0))
acLdr.Dimasz = 0.25
acBlkTblRec.AppendEntity(acLdr)
acTrans.AddNewlyCreatedDBObject(acLdr,
True)
acLdr.Annotation = mtextId
acLdr.Dimsah =
False
acLdr.Dimtad = 0
acLdr.Dimgap = 0.25
acLdr.EvaluateLeader()
acTrans.Commit()
EndUsingApplication.ShowAlertDialog("finish")EndSub
Thanks in advance.
Regards
Zakir
The only thing i can think is, use StartOpenCloseTransaction and do you really need to call the Evaluate at the end?
I see nothing wrong with your code,
seems it working godd with EvaluateLeader methoud
and without it, see small changes:
Public Sub leadertest() Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimldrblk", ".") '"_dot" Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim arrId As ObjectId = acCurDb.Dimldrblk Dim mtextId As ObjectId Dim mtxt As MText = New MText() mtxt.SetDatabaseDefaults() mtxt.Contents = "first line\Psecond line" mtxt.Location = New Point3d(4, 4, 0) mtxt.TextHeight = 0.25 mtxt.Attachment = AttachmentPoint.MiddleLeft mtxt.SetAttachmentMovingLocation(mtxt.Attachment) mtextId = acBlkTblRec.AppendEntity(mtxt) acTrans.AddNewlyCreatedDBObject(mtxt, True) Dim acLdr As Leader = New Leader() acLdr.SetDatabaseDefaults() acLdr.AppendVertex(New Point3d(2, 2, 0)) acLdr.AppendVertex(New Point3d(4, 4, 0)) acLdr.Dimasz = 0.25 acLdr.Dimldrblk = arrId acBlkTblRec.AppendEntity(acLdr) acTrans.AddNewlyCreatedDBObject(acLdr, True) acLdr.Annotation = mtextId acLdr.Dimsah = False acLdr.Dimtad = 0 acLdr.Dimgap = 0.25 acTrans.Commit() End Using acDoc.Editor.WriteMessage(vbLf + "finish") ' for debug only 'acDoc.SendStringToExecute("_ZOOM E ", True, False, False) End Sub
@Fenton: Thanks for your suggestion. I have tried with openclosetransaction , but does not work well. Without evaluate leader it also works well.
Can't find what you're looking for? Ask the community or share your knowledge.