.NET

Reply
Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 1 of 5 (164 Views)

Leader with annotation take long time to create

164 Views, 4 Replies
06-21-2013 06:07 AM

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

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 5 (150 Views)

Re: Leader with annotation take long time to create

06-21-2013 10:35 AM 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

Developer Technical Services

Autodesk Developer Network


*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (136 Views)

Re: Leader with annotation take long time to create

06-21-2013 12:57 PM 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
Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 4 of 5 (116 Views)

Re: Leader with annotation take long time to create

06-24-2013 01:18 AM 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.

 

Mentor
mzakiralam
Posts: 230
Registered: ‎11-09-2012
Message 5 of 5 (115 Views)

Re: Leader with annotation take long time to create

06-24-2013 01:19 AM in reply to: Hallex

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community