.NET

Reply
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 1 of 8 (290 Views)
Accepted Solution

Leader arrowhead is not created

290 Views, 7 Replies
05-07-2013 08:17 AM

Hi All,

 

I have tried to create a leader with simple code like below. After invoking the command, Leader line is there but I can not see the arrowhead. Can any body help me in this regard that why arrowhead is not created?

 

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.EditorInput

Imports Autodesk.AutoCAD.Geometry

 

<CommandMethod("CreateLeader")> _

 

PublicSubCreateleader()

 

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 acLdr AsLeader = NewLeader()

acLdr.AppendVertex(NewPoint3d(2, 2, 0))

acLdr.AppendVertex(NewPoint3d(4, 4, 0))

acLdr.AppendVertex(NewPoint3d(4, 5, 0))

acLdr.HasArrowHead = True

acBlkTblRec.AppendEntity(acLdr)

acTrans.AddNewlyCreatedDBObject(acLdr, True)

acTrans.Commit()

End Using

End Sub

 

After creating the line, I have tried to see the properties of the leader. In Misc,'Type' is always 'Line with no arrow' and I cannot force it 'Line with arrow'. I am using VS 2010, ACAD 2011 and framework 3.5.

 

 

 

Capture.JPG

 

Please help me in this regard.

 

Zakir

Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 2 of 8 (283 Views)

Re: Leader arrowhead is not created

05-07-2013 09:10 AM in reply to: mzakiralam

Hi,

 

this code works for me well:

 

 

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        'start a transaction
        Using tr As Transaction = db.TransactionManager.StartTransaction()


            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False), BlockTableRecord)
            Try

                Dim pts As New Point3dCollection()

                Dim opts As New PromptPointOptions(vbLf & "Pick leader arrow point: ")
                opts.AllowArbitraryInput = True
                opts.AllowNone = True
                opts.UseBasePoint = False
                opts.UseDashedLine = True

                Dim dp As New Point3d(Double.NegativeInfinity, 0, 0)

                While True

                    If Not Double.IsNegativeInfinity(dp.X) Then
                        opts.UseBasePoint = True
                        opts.BasePoint = dp
                    End If

                    Dim res As PromptPointResult = ed.GetPoint(opts)
                    If res.Status = PromptStatus.OK Then
                        pts.Add(res.Value)
                        dp = res.Value
                    Else


                        Exit While
                    End If
                    opts.Message = vbLf & "Next leader point or (Enter to exit): "
                End While


                Dim leader As New Leader()

                leader.SetDatabaseDefaults()

                'take the current annotative scale
                leader.Annotative = AnnotativeStates.True


                ' Get the current UCS, for different ucs
                Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem

                For Each p As Point3d In pts
                    Dim transformedPt As Point3d = p.TransformBy(ucs)
                    leader.AppendVertex(transformedPt)
                Next

                Dim leaderId As ObjectId = btr.AppendEntity(leader)

                tr.AddNewlyCreatedDBObject(leader, True)
                tr.Commit()
            Catch ex As System.Exception
                ed.WriteMessage(Environment.NewLine & ex.ToString())

            End Try
        End Using

 

 

 

e.g.

 

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

Re: Leader arrowhead is not created

05-07-2013 11:13 AM in reply to: mzakiralam

I 've added some settings to your code,

see my poor comments:

        <CommandMethod("CreateLeader")> _
        Public Sub Createleader()
            Application.SetSystemVariable("dimldrblk", ".") '"." comma means closed filled it also may be _dot,_dotsmall etc
            Dim acDoc As Document = 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 mtextId As ObjectId
                Dim mtx As MText = New MText()
                mtx.SetDatabaseDefaults()
                mtx.Contents = "FIRST LINE\PSECOND LINE"
                mtx.Location = New Point3d(4, 4, 0)
                mtx.TextHeight = 0.25
                mtx.Attachment = AttachmentPoint.MiddleLeft
                mtx.SetAttachmentMovingLocation(mtx.Attachment)
                mtextId = acBlkTblRec.AppendEntity(mtx)
                acTrans.AddNewlyCreatedDBObject(mtx, True)

                Dim acLdr As Leader = New Leader()
                acLdr.SetDatabaseDefaults()
                acLdr.AppendVertex(New Point3d(2, 2, 0))
                acLdr.AppendVertex(New Point3d(4, 4, 0))
                '______________________________________'
                'problem with arrow size, fix it here:
                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() 'just in case if annotation is added then evaluate leader
                acTrans.Commit()
            End Using
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 4 of 8 (237 Views)

Re: Leader arrowhead is not created

05-08-2013 01:56 AM in reply to: e.g.
Thanks e.g. for your code
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 5 of 8 (235 Views)

Re: Leader arrowhead is not created

05-08-2013 01:58 AM in reply to: mzakiralam

Hi Hallex,

 

Thanks for your code. It is working great as I wanted. I want to ask you another question. Can I put leader and annotation in one block. If yes how? Can you help me in this regard?

 

Zakir

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 8 (230 Views)

Re: Leader arrowhead is not created

05-08-2013 02:37 AM in reply to: mzakiralam
Shortly you have do following insert block and use it as annotation object
here is example with using same way but for mleader:
http://www.acadnetwork.com/topic-210.0.html
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 7 of 8 (222 Views)

Re: Leader arrowhead is not created

05-08-2013 04:49 AM in reply to: Hallex
Thanks for a perfect example!
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 8 of 8 (218 Views)

Re: Leader arrowhead is not created

05-08-2013 05:20 AM in reply to: mzakiralam
You're welcome
Cheers :smileyhappy:
_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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