Quantcast
Channel: Autodesk AutoCAD forums
Viewing all articles
Browse latest Browse all 14319

Jig polyline and rotation keyword

$
0
0

Hallo,

 

I want to create jig to insert hallow slab (polyline) everything works fine until I am trying to use an added keyword for rotation then Autocad crashes really bad (no error inforamtion). Can anyone tell me what I am doing wrong? Here is a code, in comment place where program crashes.

 

Thanks

 

Ps: I've already been on through the interface and tried to use text jig but no result in my case :(

 

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

Namespace AutoCAD_VB_plug_in1

    Public Class MyCommands

        Inherits Autodesk.AutoCAD.EditorInput.DrawJig

        Dim BasePt As Point3d

        Dim angle As Double

        Dim myPR As PromptPointResult


        Function StartJig() As PromptPointResult

            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

            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

        End Function

        Protected Overrides Function Sampler(ByVal prompts As Autodesk.AutoCAD.EditorInput.JigPrompts) As Autodesk.AutoCAD.EditorInput.SamplerStatus

            Dim po As New JigPromptPointOptions(vbLf & "Position of slab")

            po.SetMessageAndKeywords(vbLf & "Specify position of slab or " & "[Rotate]", "R")

            myPR = prompts.AcquirePoint(po)

            If myPR.Status = PromptStatus.Keyword Then


                Select Case myPR.StringResult

                    Case "R"

                        angle = angle + 90 * Math.PI / 180

                        'Program crash here

                        Exit Select

                End Select

                Return SamplerStatus.OK

            ElseIf myPR.Status = PromptStatus.OK Then

                If myPR.Value.IsEqualTo(BasePt) Then

                    Return SamplerStatus.NoChange

                End If

                BasePt = myPR.Value

                Return SamplerStatus.OK

            End If

            Return SamplerStatus.Cancel

        End Function

        Protected Overrides Function WorldDraw(ByVal draw As Autodesk.AutoCAD.GraphicsInterface.WorldDraw) As Boolean

            Dim x As Integer = BasePt.X
            Dim y As Integer = BasePt.Y

            Dim c As Integer = 2
            Dim l As Integer = 600
            Dim b As Integer = 150
            Dim bk As Integer = 26
            Dim lk1 As Integer = 100
            Dim so As Integer = 10

            Dim acPoly As Polyline = New Polyline()

            acPoly.SetDatabaseDefaults()
            acPoly.AddVertexAt(0, New Point2d(x, y - c), 0, 0, 0)
            acPoly.AddVertexAt(1, New Point2d(x + bk / 2 + c, y - c), 0, 0, 0)
            acPoly.AddVertexAt(2, New Point2d(x + bk / 2 + c, y + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(3, New Point2d(x + b / 2, y + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(4, New Point2d(x + b / 2, y - l + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(5, New Point2d(x - b / 2, y - l + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(6, New Point2d(x - b / 2, y + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(7, New Point2d(x - bk / 2 - c, y + lk1 + so), 0, 0, 0)
            acPoly.AddVertexAt(8, New Point2d(x - bk / 2 - c, y - c), 0, 0, 0)

            acPoly.Closed = True

            Dim curUCSMatrix As Matrix3d = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem
            Dim curUCS As CoordinateSystem3d = curUCSMatrix.CoordinateSystem3d

            acPoly.TransformBy(Matrix3d.Rotation(angle, curUCS.Zaxis, BasePt))

            draw.Geometry.Polyline(acPoly, 1, 8)

        End Function

        <CommandMethod("DoJigA")> Sub DoJigA()

            StartJig()

        End Sub

    End Class

End Namespace

 

 

 


Viewing all articles
Browse latest Browse all 14319

Trending Articles