Hi all,
Within the last week this code I had been using for a year all of a sudden started to work very slowly. It flickers a lot and is slow to drag around the screen. Could this be more hardware related than the code itself? I have been using the same computer for longer than I have been using this code. Here is the class for the jig if anyone has any suggestions I would appreciate it. Thanks.
Private Class MLeaderJig
Inherits EntityJig
Private m_pts As Point3dCollection
Private m_tempPoint 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)
MyBase.New(New MLeader())
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim ucs As CoordinateSystem3d = ed.CurrentUserCoordinateSystem.CoordinateSystem3d
Dim plane As New Plane(ucs.Origin, ucs.Xaxis, ucs.Yaxis)
Dim disp As Vector3d = Point3d.Origin.GetVectorTo(ucs.Origin)
Dim transMat As Matrix3d = Matrix3d.WorldToPlane(plane)
' Store the string passed in
m_contents = contents
' Create a point collection to store our vertices
m_pts = New Point3dCollection()
' Create mleader and set defaults
Dim ml As MLeader = TryCast(Entity, MLeader)
ml.SetDatabaseDefaults()
'change some mleader properties if it is needed
ml.LeaderLineType = LeaderType.StraightLeader
ml.ContentType = ContentType.MTextContent
Dim mt As New MText()
mt.SetDatabaseDefaults()
mt.Contents = contents
mt.TextHeight = GetSettings.textHeight
mt.TextStyleId = txtId
ml.ArrowSize = GetSettings.arrowSize
ml.MText = mt
ml.EnableFrameText = False
ml.EnableLanding = True
ml.LandingGap = 0.1
ml.TextAttachmentType = TextAttachmentType.AttachmentBottomLine
ml.TextAngleType = TextAngleType.HorizontalAngle
ml.EnableDogleg = True
m_leaderIndex = ml.AddLeader()
ml.SetDoglegLength(m_leaderIndex, 0.1)
m_leaderLineIndex = 0
End Sub
Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus
Dim opts As New JigPromptPointOptions()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
' Not all options accept null response
opts.UserInputControls = (UserInputControls.Accept3dCoordinates Or UserInputControls.NoNegativeResponseAccepted)
' Get the first point
If m_pts.Count = 0 Then
Dim ppo As New PromptPointOptions(vbLf + "Leader Start Point:")
ppo.AllowNone = True
Dim ppr As PromptPointResult = ed.GetPoint(ppo)
If ppr.Status = PromptStatus.Cancel Then
Return SamplerStatus.Cancel
ElseIf ppr.Status = PromptStatus.OK Then
m_tempPoint = ppr.Value
pts.Add(ppr.Value)
End If
AddVertex()
' And the second
ElseIf m_pts.Count = 1 Then
opts.Message = vbLf & "Leader End Point: "
Else
' Should never happen
Return SamplerStatus.Cancel
End If
Dim res As PromptPointResult = prompts.AcquirePoint(opts)
If m_tempPoint = res.Value Then
Return SamplerStatus.NoChange
ElseIf res.Status = PromptStatus.OK Then
m_tempPoint = 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
Dim ucs As CoordinateSystem3d = ed.CurrentUserCoordinateSystem.CoordinateSystem3d
Dim plan As Plane = New Plane(Point3d.Origin, ucs.Zaxis)
Try
If pts.Count > 0 Then
' Set the last vertex to the new value
Dim ml As MLeader = TryCast(Entity, MLeader)
ml.SetLastVertex(m_leaderLineIndex, m_tempPoint)
'dog leg direction:
If (pts(0).X < m_tempPoint.X) Then
ml.SetDogleg(0, New Vector3d(plan, New Vector2d(1, 0)))
ml.TextAlignmentType = TextAlignmentType.LeftAlignment
Else
ml.SetDogleg(0, New Vector3d(plan, New Vector2d(-1, 0)))
ml.TextAlignmentType = TextAlignmentType.RightAlignment
End If
End If
Catch ex As System.Exception
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
doc.Editor.WriteMessage(vbLf & "Exception: " & ex.Message)
Return False
End Try
Return True
End Function
Public Sub AddVertex()
Dim ml As MLeader = TryCast(Entity, MLeader)
' For the first point...
If m_pts.Count = 0 Then
' Add a leader line
m_leaderLineIndex = ml.AddLeaderLine(m_leaderIndex)
' And a start vertex
ml.AddFirstVertex(m_leaderLineIndex, m_tempPoint)
' Add a second vertex that will be set within the jig
ml.AddLastVertex(m_leaderLineIndex, New Point3d(0, 0, 0))
Else
' For subsequent points, just add a vertex
ml.AddLastVertex(m_leaderLineIndex, m_tempPoint)
End If
' Reset the attachment point, otherwise it seems to get forgotten
ml.TextAttachmentType = TextAttachmentType.AttachmentBottomOfTopLine
' Add the latest point to our history
m_pts.Add(m_tempPoint)
'Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'ed.WriteMessage(m_pts.Count)
End Sub
Public Function GetEntity() As Entity
Return Entity
End Function
End Class