.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Leader with annotation take long time to create

4 REPLIES 4
Reply
Message 1 of 5
mzakiralam
388 Views, 4 Replies

Leader with annotation take long time to create

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

 

4 REPLIES 4
Message 2 of 5
fenton.webb
in reply to: mzakiralam

The only thing i can think is, use StartOpenCloseTransaction and do you really need to call the Evaluate at the end?




Fenton Webb
AutoCAD Engineering
Autodesk

Message 3 of 5
Hallex
in reply to: mzakiralam

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

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 5
mzakiralam
in reply to: fenton.webb

@Fenton: Thanks for your suggestion. I have tried with openclosetransaction , but does not work well. Without evaluate leader it also works well.

 

Message 5 of 5
mzakiralam
in reply to: Hallex

@Hallex: Thanks for your code. I have tired with your code. It reduces little bit time now.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost