Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've modified several jig codes that I've found but I still really don't know what I'm doing.
I'd like a jig that creates a leader starting from the nearest point to a line to the last mouse position.
Needless to say it's not working.
Below is what I have fumbled together. Hope someone can help.
<CommandMethod("AA", CommandFlags.UsePickSet Or CommandFlags.Redraw Or CommandFlags.Modal Or CommandFlags.NoBlockEditor Or CommandFlags.Session)> Sub LabelJig() Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument() Using trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction : trcnt = trcnt + 1 Dim RJC As nsLabel_Range.RangeLabelJig2 = New nsLabel_Range.RangeLabelJig2 RJC.AddLabel(trans) 'LabelType supposed to be "Range" trans.Commit() : trcnt = trcnt - 1 : If trcnt > 0 Then MsgBox(Reflection.MethodBase.GetCurrentMethod.Name() + " - TRCNT>0") End Using End Using End Sub
Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry Namespace nsLabel_Range Public Class RangeLabelJig2 Public Shared mt_RotationUCS As Double, mt_Height As Integer, vector As Vector2d Public Shared ml_angleUCS As Double, ml_angleWCS As Double, ml_dogleglength As Double Public Shared myLine As Line Public Sub AddLabel(ByRef trans As Transaction) Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False) myLine = New Line(New Point3d(0, 0, 0), New Point3d(1000, 0, 0)) Dim jig As New MLeaderJig(" ", LabelTxtStyleID, trans) Dim dragres As PromptResult = ed.Drag(jig) If dragres.Status = PromptStatus.OK Then Dim bt As BlockTable = DirectCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable) Try Dim ent As Entity = jig.GetEntity btr.AppendEntity(ent) trans.AddNewlyCreatedDBObject(ent, True) Catch ex As Exception MsgBox(Reflection.MethodBase.GetCurrentMethod.Name() + " Exception: " + ex.Message) End Try End If End Sub Private Class MLeaderJig Inherits EntityJig 'Private m_pts As Point3dCollection Private lastMousePosition As Point3d Private m_contents As String Private m_leaderIndex As Integer Private m_leaderLineIndex As Integer Public Sub New(ByVal contents As String, ByVal txtId As ObjectId, ByVal Trans As Transaction) MyBase.New(New MLeader()) m_contents = contents Dim ml As MLeader = TryCast(Entity, MLeader) ml.SetDatabaseDefaults() m_leaderIndex = ml.AddLeader() m_leaderLineIndex = 0 End Sub Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus Dim jigOpt As New JigPromptPointOptions() jigOpt.UserInputControls = UserInputControls.Accept3dCoordinates Or UserInputControls.AnyBlankTerminatesInput Or UserInputControls.GovernedByOrthoMode Or UserInputControls.GovernedByUCSDetect Or UserInputControls.UseBasePointElevation Or UserInputControls.InitialBlankTerminatesInput Or UserInputControls.NullResponseAccepted Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor jigOpt.Message = vbLf & "Label End Point: " Dim res As PromptPointResult = prompts.AcquirePoint(jigOpt) If res.Value = lastMousePosition Then Return SamplerStatus.NoChange ElseIf res.Status = PromptStatus.OK Then lastMousePosition = res.Value Return SamplerStatus.OK End If Return SamplerStatus.Cancel End Function Protected Overrides Function Update() As Boolean Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor ed.WriteMessage(vbLf + "lastMousePosition=" & lastMousePosition.X & "," & lastMousePosition.Y) Try Dim AngleBetweenUCSandWCS As Double = GetAngleBetweenUCSandWCS() Dim ml As MLeader = TryCast(Entity, MLeader) m_leaderLineIndex = ml.AddLeaderLine(m_leaderIndex) Dim m_labelOrigin As Point3d = myLine.GetClosestPointTo(lastMousePosition, False) ml.AddFirstVertex(m_leaderLineIndex, m_labelOrigin) ml.AddLastVertex(m_leaderLineIndex, New Point3d(0, 0, 0)) ml.SetLastVertex(m_leaderLineIndex, lastMousePosition) Catch ex As Exception Dim doc As Document = Application.DocumentManager.MdiActiveDocument doc.Editor.WriteMessage(vbLf & "MLeader Jig Exception: " & ex.Message) Return False End Try Return True End Function Public Function GetEntity() As Entity Return Entity End Function End Class End Class End Namespace
Solved! Go to Solution.