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

Need some guidance on building a LeaderJig

2 REPLIES 2
Reply
Message 1 of 3
dwgraphics
406 Views, 2 Replies

Need some guidance on building a LeaderJig

I'm working on a building a custom leader command, and as a part of that, my first EntityJig.. In trying to figure out how they work, I ran across a "Thru the Interface Blog" the showed how to build a PlineJig. I converted that to VB, and got it working. So far, so good. Next, I replaced all the Pline references and methods with their Leader counterparts. The code kind of works, but it behaves like the sketch command, rather than like the polyline command, and it starts drawing before I even get prompted for the startpoint of the leader.

I also found a similar blog about building an MLeader jig, but so far it hasn't helped me see where I went bad in my code.

Also, I can't find any decent documentation on the Leader object. For instance, what is the difference between VertexAt and SetVertexAt. The ObjectARX just lists the methods and arguments, not why you'd use them. And I can't find anything generic on jigs either.

I've attached the code for both my LeaderJig class and the Commands class that calls it. If someone can help me zero in on where my code is flawed, or point me in the right direction to get some detailed info on jigs and/or leaders so I can figure it out myself, I'd greatly appreciate it.

Dave

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk

Public Class LeaderJig : Inherits EntityJig

Dim m_pts As Point3dCollection
Dim m_tempPoint As Point3d
Dim m_plane As Plane

Public Sub New(ByVal ucs As Matrix3d)

'Create a point collection to store our vertices
MyBase.new(New Leader())

m_pts = New Point3dCollection()



'Create a temporary plane, to help with calcs

Dim origin = New Point3d(0, 0, 0)
Dim normal = New Vector3d(0, 0, 1)

normal = normal.TransformBy(ucs)
m_plane = New Plane(origin, normal)



'Create leader, set defaults, add dummy vertex
Dim myLeader As Leader = Entity

Try
myLeader.SetDatabaseDefaults()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message.ToString)
End Try

myLeader.AppendVertex(New Point3d(0, 0, 0))

End Sub

Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus

Dim jigOpts As New JigPromptPointOptions()

jigOpts.UserInputControls = UserInputControls.Accept3dCoordinates + _
UserInputControls.NullResponseAccepted + _
UserInputControls.NoNegativeResponseAccepted

If m_pts.Count = 0 Then
'For the first vertex, just ask for the point
jigOpts.UseBasePoint = False
jigOpts.Message = "\nStart point of leader: "

ElseIf m_pts.Count > 0 Then
Dim myLeader As Leader = Entity

'For subsequent vertices, use a base point
jigOpts.BasePoint = m_pts(m_pts.Count - 1)
jigOpts.UseBasePoint = True
jigOpts.Message = "\nLeader vertex: "

Else 'should never happen
Return SamplerStatus.Cancel

End If

'Get the point itself
Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts)



'Check if it has changed or not
If (m_tempPoint = res.Value) Then
Return SamplerStatus.NoChange
ElseIf (res.Status = PromptStatus.OK) Then
m_tempPoint = res.Value
Return SamplerStatus.OK
Else
Return SamplerStatus.Cancel
End If

End Function

Protected Overrides Function Update() As Boolean


Dim myLeader As Leader = Entity


'Update the dummy vertex to be our 3D point projected onto our plane
myLeader.AppendVertex(m_tempPoint)

Return True


End Function

Friend Shadows ReadOnly Property Entity() As Entity
Get
Return MyBase.Entity
End Get
End Property

Public Sub AddLatestVertex()


'Add the latest selected point to internal list...
'This point will already be in the most recently added leader vertex
m_pts.Add(m_tempPoint)

Dim myLeader As Leader = Entity
' Create a new dummy vertex...
' can have any initial value

myLeader.AppendVertex(m_tempPoint)

End Sub

Public Sub RemoveLastVertex()

'Remove dummy vertex
Dim myLeader As Leader = Entity
'myLeader.RemoveLastVertex()

End Sub

End Class


-------------------------------------------------

_
Public Sub MyLeaderJig()

'Declarations
'============
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor


'Begin Sub
'=========
'Get the current UCS and pass it to Jig
Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem


'Create Jig object
Dim jig As LeaderJig = New LeaderJig(ucs)

'Loop to set the vertices directly on the polyline
Dim bSuccess As Boolean = True
Dim bComplete As Boolean = False

Do While (bSuccess And Not bComplete)

Dim res As PromptResult = ed.Drag(jig)

'Get results of user input
If res.Status = PromptStatus.OK Then
'New point was added
bSuccess = True
jig.AddLatestVertex()
Else
bSuccess = False
End If

'Null input terminates the command
If res.Status = PromptStatus.None Then
'Clean up polyline before adding it
bComplete = True
jig.RemoveLastVertex()
Else
bComplete = False
End If

Loop


'If the jig completed successfully, add the polyline
If bComplete Then

'Begin transaction
Dim db As Database = doc.Database
Dim tr As Transaction = db.TransactionManager.StartTransaction()

Using tr

Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)

'Append entity
btr.AppendEntity(jig.Entity)

tr.AddNewlyCreatedDBObject(jig.Entity, True)
tr.Commit()

End Using 'tr

End If 'bComplete

End Sub


End Class
2 REPLIES 2
Message 2 of 3
dwgraphics
in reply to: dwgraphics

Never mind, I finally figured it out.
Message 3 of 3

Sorry to ressurect an several year old thread, but what was your solution and can you post it here?  I am in the same boat you were in as I only came across how to make a Mleader but have the same issue in trying to make a leader jig. 

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