.NET

Reply
Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 1 of 6 (340 Views)
Accepted Solution

Qleader Settings

340 Views, 5 Replies
09-14-2012 07:49 AM

Hi,

 

I  need some help, I am struggling to find how to adjust the Qleader Settings(ex. to set the points number to unlimited, etc). Can someone point me in the right direction?

 

Thank you very much,

 

e.g.

You could be able to specify points dynamically

Try this quick code example

(tested on A2010 only)

 <CommandMethod("drl")> _
Public Sub DrawLeaderTest()
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 mtx As New MText()
mtx.SetDatabaseDefaults()
mtx.Contents = "Put your annotation\Ptext here."
mtx.Normal = Vector3d.ZAxis
mtx.Location = pts(pts.Count - 1)
Dim mtxId As ObjectId = btr.AppendEntity(mtx)
tr.AddNewlyCreatedDBObject(mtx, True)
Dim leader As New Leader()
leader.SetDatabaseDefaults()
For Each p As Point3d In pts
leader.AppendVertex(p)
Next
Dim leaderId As ObjectId = btr.AppendEntity(leader)
tr.AddNewlyCreatedDBObject(leader, True)
leader.Annotation = mtxId
tr.Commit()
Catch ex As System.Exception
ed.WriteMessage(Environment.NewLine & ex.ToString())
End Try
End Using
End Sub

 

~'J'~

Mentor
khoa.ho
Posts: 213
Registered: ‎09-15-2011
Message 2 of 6 (327 Views)

Re: Qleader Settings

09-14-2012 09:50 AM in reply to: e.g.

Hi e.g.

 

Like you, I still don't know how to adjust fully the QLeader Settings, some properties are still missing and do not expose on the .NET API. In fact QLeader is a composite object containing a Solid (for arrow head), a Polyline (for leader line) and an MText (for leader text). When we declare a new Leader() object with some initialized properties, there is no property said NumberOfPoints. However, this number of points is the property NumberOfVertices of Polyline class. So the API does not expose this property on Leader and MLeader classes.

 

There are also some other missing properties of QLeader Settings on Leader and MLeader classes. I think the API might not consider all properties of a composite entity like Leader/MLeader.

 

-Khoa

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

Re: Qleader Settings

09-14-2012 12:30 PM in reply to: e.g.

You could be able to specify points dynamically

Try this quick code example

(tested on A2010 only)

    <CommandMethod("drl")> _
        Public Sub DrawLeaderTest()
            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 mtx As New MText()

                    mtx.SetDatabaseDefaults()

                    mtx.Contents = "Put your annotation\Ptext here."

                    mtx.Normal = Vector3d.ZAxis

                    mtx.Location = pts(pts.Count - 1)

                    Dim mtxId As ObjectId = btr.AppendEntity(mtx)

                    tr.AddNewlyCreatedDBObject(mtx, True)

                    Dim leader As New Leader()

                    leader.SetDatabaseDefaults()

                    For Each p As Point3d In pts
                        leader.AppendVertex(p)
                    Next
                    Dim leaderId As ObjectId = btr.AppendEntity(leader)

                    tr.AddNewlyCreatedDBObject(leader, True)

                    leader.Annotation = mtxId

                    tr.Commit()
                Catch ex As System.Exception
                    ed.WriteMessage(Environment.NewLine & ex.ToString())
                End Try
            End Using
        End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 4 of 6 (280 Views)

Re: Qleader Settings

09-17-2012 07:04 AM in reply to: Hallex

Hi Hallex,

 

thank you for you answer, yes it does the trick for me, instead of trying to modify the settings, I can have a custom command to create the leader.

 

Though, I have one more question: I am using the command through a viewport that sometimes has a different annotation scale: what will be the best aproach to use the current viewport annotation scale? Just read the variable "CANNOSCALE"?

 

Thanks,

 

e.g.

Valued Contributor
e.g.
Posts: 65
Registered: ‎07-23-2008
Message 5 of 6 (279 Views)

Re: Qleader Settings

09-17-2012 07:12 AM in reply to: e.g.

Hi Hallex,

 

yes, the leader.Annotative = AnnotativeStates.True does the trick.

 

Thanks,

 

e.g.

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

Re: Qleader Settings

09-18-2012 01:23 AM in reply to: e.g.

Glad you solved it by yourself

Happy coding

Cheers :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
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 or visit the Installation and Licensing Forum to get help installing your software.