Author Topic: Sluggish Jig  (Read 1660 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
Sluggish Jig
« on: January 23, 2013, 09:32:31 AM »
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.

Code: [Select]
        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


n.yuan

  • Bull Frog
  • Posts: 348
Re: Sluggish Jig
« Reply #1 on: January 23, 2013, 12:11:05 PM »
There are 2 system variables that have impact on the effect of dragging:

DRAGP1 and DRAGP2.

I remebered my first Moving Jig done with Acad2006 did not show a good visual effect: during dragging, the ghost entity simply not seeable and only can be seen when Istop the mouse move. Increasing DRAGP2 value solved that issue then.

You may want to examine these 2 system variables to see if they have been changed somehow. Or you can try change their values to see if your Jig's work changes.

gablackburn

  • Guest
Re: Sluggish Jig
« Reply #2 on: January 23, 2013, 12:47:07 PM »
To add to n.yuan's post, I believe the defaults for dragp1 & dragp2 are 5000 & 10 respectively.  I noticed a difference in my jig performance when I set both values to 2000.

Code: [Select]
Application.SetSystemVariable("dragp1", 2000) 'WHEN HDW ACC ON, CONTROLS HOW MANY VECTORS ARE DRAWN BEFORE IT CHECKS FOR NEW SAMPLE FROM MOUSE
Application.SetSystemVariable("dragp2", 2000)'WHEN SFW ACC ON, CONTROLS HOW MANY VECTORS ARE DRAWN BEFORE IT CHECKS FOR NEW SAMPLE FROM MOUSE

TJK44

  • Guest
Re: Sluggish Jig
« Reply #3 on: January 23, 2013, 01:58:13 PM »
I tried changing the variables to 2000, 5000, and 10000 but no visible change.

I think it has something to do with this bit of code in the Update function, but it's strange it was fine until about a week ago.

Code: [Select]
                        If (pts(0).X < m_tempPoint.X) Then
                            ml.TextAlignmentType = TextAlignmentType.LeftAlignment
                            ml.SetDogleg(0, New Vector3d(plan, New Vector2d(1, 0)))
                        Else
                            ml.TextAlignmentType = TextAlignmentType.RightAlignment
                            ml.SetDogleg(0, New Vector3d(plan, New Vector2d(-1, 0)))
                        End If