• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 19
    Registered: ‎12-04-2005

    The secret life of jigs

    181 Views, 1 Replies
    01-24-2008 05:47 AM
    Hello All,

    I have created a jig to create a jig for road design that floats a grade from a vertical curve. The user selects an existing curve and then the jigs calculates the tangent point on this curve and rubber bands a line to it.

    The Jig is a class called clsFloatPtJig.
    The jig gets called from a class called clsVerticalAlignment.

    All works well for about the first five seconds and then suddenly the rubber band and text disappears and then when the user clicks a point, AutoCAD crashes. At this point I get various errors including 'Exception attempted to read or write to protected memory.'

    I have taken all of my fancy calls out of my jig, so it is reduced to just a rubber band, and it still crashes. This has lead me to belive that the problem must be elsewhere.

    The only thing that I think could possibly cause this is perhaps .NET is Garbage collecting the VerticalAlignment class for some reason, thereby shutting down jig.


    Here is the Jig code:

    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD
    Public Class clsFloatPointJig
    Inherits DrawJig
    Dim BasePt As Point3d
    Dim myPr As PromptPointResult
    Dim TextStyle As New Autodesk.AutoCAD.GraphicsInterface.TextStyle("arial.ttf", "", 3.5, 1, 0, 0, False, False, False, False, False, "AA")
    Dim _Vertical As clsVerticalAlignment
    Dim Sol As clsVerticalAlignment.VCSolution
    Dim pt1(2) As Double
    Dim pt2 As New Point3d(100, 100, 0)
    Dim _eKey As String
    Dim _IsAfter As Boolean
    Dim Vec1 As New Vector3d(0, 1, 0)
    Public Sub New(ByVal eKey As String, ByVal IsAfter As Boolean, ByVal VA As clsVerticalAlignment)

    _eKey = eKey
    _IsAfter = IsAfter
    _Vertical = VA
    End Sub
    Function startJig() As PromptPointResult
    Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

    Try
    myPr = ed.Drag(Me)
    Do
    Select Case myPr.Status
    Case PromptStatus.OK
    Return myPr
    Exit Do
    End Select
    Loop While myPr.Status <> PromptStatus.Cancel
    Return myPr
    Catch ex As Exception
    MsgBox("Exception" & ex.Message)
    End Try
    End Function
    Protected Overrides Function Sampler(ByVal prompts As JigPrompts) As SamplerStatus

    Try
    Dim JigOpts As New JigPromptPointOptions
    JigOpts.Message = vbCrLf & "Select TP point: "
    JigOpts.UserInputControls = UserInputControls.NoZeroResponseAccepted
    myPr = prompts.AcquirePoint(JigOpts)
    If myPr.Value.IsEqualTo(BasePt) Then
    Return SamplerStatus.NoChange
    Else
    BasePt = myPr.Value
    pt1(0) = _Vertical.X2Chainage(BasePt.X)
    pt1(1) = _Vertical.Z2Level(BasePt.Y)
    Sol = _Vertical.GradeThroughPoint(pt1, _IsAfter, _eKey)
    pt2 = New Point3d(_Vertical.Chainage2X(Sol.Solution1.Chainage), _
    _Vertical.Level2Z(Sol.Solution1.Level), 0)
    End If
    Return SamplerStatus.OK
    Catch ex As Exception
    MsgBox("Exception" & ex.Message)
    End Try
    End Function
    Protected Overrides Function worlddraw(ByVal Draw As _
    Autodesk.AutoCAD.GraphicsInterface.WorldDraw) As Boolean

    Try
    If Sol.Solutions = 1 Then
    Draw.Geometry.WorldLine(pt2, BasePt)
    Draw.Geometry.Text(pt2, Geometry.Vector3d.ZAxis, _
    Vec1, "CH " & FormatNumber(Sol.Solution1.Chainage, 3) & ", Lvl " & FormatNumber(Sol.Solution1.Level, 3), False, TextStyle)
    Draw.Geometry.Text(BasePt, Geometry.Vector3d.ZAxis, _
    Vec1, "CH " & FormatNumber(pt1(0), 3) & ", Lvl " & FormatNumber(pt1(1), 3), False, TextStyle)
    End If
    Catch ex As Exception
    MsgBox("Exception" & ex.Message)
    Return False
    End Try
    Return True
    End Function
    End Class

    And here is the calling code from the VerticalAlignment class


    Public Sub FloatPoint(ByVal eKey As String, ByVal IsAfter As Boolean)
    Dim SelPt As Autodesk.AutoCAD.EditorInput.PromptPointResult
    Dim myJig As New clsFloatPointJig(eKey, IsAfter, Me)

    SelPt = myJig.startJig()
    If Not IsNothing(SelPt) Then
    MsgBox(SelPt.ToString)
    End If
    End Sub

    I am testing this class by creating a new instance of a vertical alignment and then calling the FloatPoint function.

    Is this scenario described above possible and if so are there any strategies I can employ to avoid this.

    Regards

    Martin Duke
    Please use plain text.
    Distinguished Contributor
    Posts: 524
    Registered: ‎10-25-2005

    Re: The secret life of jigs

    01-25-2008 05:56 AM in reply to: martinduke2653
    Put the try after the do
    Please use plain text.