.NET

Reply
Valued Contributor
ButterFlyShame
Posts: 77
Registered: ‎07-02-2010
Message 1 of 4 (229 Views)
Accepted Solution

How override ange programatically in PrompPointOptions

229 Views, 3 Replies
06-27-2011 09:21 PM

Hope somebody could help me with this.

I need to lock user to a certain angle when prompting ot pick points. in PrompPointOptions. Right now I am faking and useing

SendStringToexecute . But I really like to use a way to do in net. Here is My Code. Thanks In Advance.

 

 

 

 Function vns_Getpoint_with_Base_Angle_Given(ByVal msg As String, ByVal baseP As Point3d, ByVal angle As Double, ByRef P As Point3d) As Integer
        Dim Mydwg As Document = Application.DocumentManager.MdiActiveDocument
        Dim Myed As Editor = Mydwg.Editor
        Dim ppo As PromptPointOptions = New PromptPointOptions("")
        Mydwg.SendStringToExecute("<" & Trim(angle * 180 / Math.PI.ToString) & " ", False, False, False)
        ppo.Message = msg
        ppo.UseBasePoint = True
        ppo.UseDashedLine = True
        ppo.BasePoint = baseP
        ppo.AllowNone = True
        Dim ppr As PromptPointResult = Myed.GetPoint(ppo)
        P = ppr.Value
        If ppr.Status = PromptStatus.OK Then
            Return 1
        End If
    End Function

 

 

 

*Expert Elite*
chiefbraincloud
Posts: 752
Registered: ‎02-13-2008
Message 2 of 4 (197 Views)

Re: How override ange programatically in PrompPointOptions

07-05-2011 10:13 AM in reply to: ButterFlyShame

I have used a variety of methods to accomplish this on different tasks.  Most of them won't work with GetPoint though, so the simplest way I can suggest is to set the cursor angle (the SNAPANG system variable) to the angle you want and set ORTHOMODE to 1.  Of course the user can turn ortho off during the getpoint.

 

If you really want to force the angle, without the user having any way to stop you, then you'll need to create your own jig and override the point in the Update routine.

Dave O.                                                                  Sig-Logos32.png
Valued Contributor
ButterFlyShame
Posts: 77
Registered: ‎07-02-2010
Message 3 of 4 (180 Views)

Re: How override ange programatically in PrompPointOptions

07-05-2011 05:28 PM in reply to: chiefbraincloud

Chief , Again you saved me . I don't know how to thank you. Your solution is better than mine. and I am not gonna mess with

Jig which I never understand it. But now I am fine and take your way.

Cheers,

 

Valued Contributor
ButterFlyShame
Posts: 77
Registered: ‎07-02-2010
Message 4 of 4 (155 Views)

Re: How override ange programatically in PrompPointOptions

07-23-2011 11:43 AM in reply to: chiefbraincloud

Chief , Noram wrote this. it is working . But too long. Anyways I am using yours in my codes. Just for your info and all help I got from you. Thanks.

Public Class DragCommand
        <CommandMethod("AngledDrag")> _
        Public Sub RunThisMethod()
            Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim drag As New AngledDrag(dwg)
            Try
                If drag.DragAtAngle() Then
                    GenerateLine(dwg, drag.StartPoint, drag.EndPoint)
                    dwg.Editor.WriteMessage(vbLf & "MyCommand executed.")
                End If
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                dwg.Editor.WriteMessage(vbLf & "Error: {0}" & vbLf, ex.Message)
            End Try
        End Sub
        Private Shared Sub GenerateLine(ByVal dwg As Document, ByVal startPt As Point3d, ByVal endPt As Point3d)
            Using tran As Transaction = dwg.Database.TransactionManager.StartTransaction()
                Dim br As BlockTableRecord = DirectCast(tran.GetObject(dwg.Database.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                Dim line As New Line(startPt, endPt)
                line.SetDatabaseDefaults(dwg.Database)
                br.AppendEntity(line)
                tran.AddNewlyCreatedDBObject(line, True)
                tran.Commit()
            End Using
        End Sub
    End Class
    Public Class AngledDrag
        Private _dwg As Document
        Private _db As Database
        Private _editor As Editor
        Private _startPoint As New Point3d(0.0, 0.0, 0.0)
        Private _endPoint As New Point3d(0.0, 0.0, 0.0)
        Private _dragAngle As Double = 45.0
        Private _dragLine As Line = Nothing
        Private _colorIndex As Integer = 1
        Public Sub New(ByVal dwg As Document)
            _dwg = dwg
            _db = dwg.Database
            _editor = dwg.Editor
        End Sub
        Public ReadOnly Property StartPoint() As Point3d
            Get
                Return _startPoint
            End Get
        End Property
        Public ReadOnly Property EndPoint() As Point3d
            Get
                Return _endPoint
            End Get
        End Property
        Public Function DragAtAngle() As Boolean
            _endPoint = _startPoint
            AddHandler _editor.PointMonitor, New PointMonitorEventHandler(AddressOf Editor_PointMonitor)
            Try
                'Get end point
                If GetEndPoint() Then
                    Return True
                Else
                    Return False
                End If
            Finally
                ClearTransientGraphics()
                RemoveHandler _editor.PointMonitor, AddressOf Editor_PointMonitor
            End Try
        End Function
        Private Sub Editor_PointMonitor(ByVal sender As Object, ByVal e As PointMonitorEventArgs)
            DrawDragLine(e.Context.RawPoint)
            If _dragLine IsNot Nothing Then
                e.AppendToolTipText("Angle: " + _dragAngle.ToString() + vbLf & "Length: " + _dragLine.Length.ToString())
            Else
                e.AppendToolTipText("")
            End If
        End Sub
        Private Sub DrawDragLine(ByVal mousePoint As Point3d)
            ClearTransientGraphics()
            Dim pt As Point3d = CalculateEndPoint(mousePoint)
            _dragLine = New Line(_startPoint, pt)
            _dragLine.SetDatabaseDefaults(_db)
            _dragLine.ColorIndex = _colorIndex
            Dim col As New IntegerCollection()
            TransientManager.CurrentTransientManager.AddTransient(_dragLine, TransientDrawingMode.Highlight, 128, col)
            'whenever the dragged line updated, reset _endPoint
            _endPoint = pt
        End Sub
        Private Sub ClearTransientGraphics()
            If _dragLine IsNot Nothing Then
                Dim col As New IntegerCollection()
                TransientManager.CurrentTransientManager.EraseTransient(_dragLine, col)
                _dragLine.Dispose()
                _dragLine = Nothing
            End If
        End Sub
        Private Function CalculateEndPoint(ByVal mousePoint As Point3d) As Point3d
            Dim pt As Point3d = mousePoint
            If _dragAngle <= 90.0 OrElse _dragAngle >= 270.0 Then
                If mousePoint.X <= _startPoint.X Then
                    pt = _startPoint
                Else
                    If _dragAngle <= 45.0 OrElse _dragAngle >= 315.0 Then
                        Dim y As Double = (mousePoint.X - _startPoint.X) * Math.Tan(_dragAngle * Math.PI / 180)
                        pt = New Point3d(mousePoint.X, _startPoint.Y + y, 0.0)
                    Else
                        If _dragAngle > 45.0 AndAlso _dragAngle <= 90.0 Then
                            If mousePoint.Y < _startPoint.Y Then
                                pt = _startPoint
                            Else
                                Dim x As Double = (mousePoint.Y - _startPoint.Y) / Math.Tan(_dragAngle * Math.PI / 180)
                                pt = New Point3d(_startPoint.X + x, mousePoint.Y, 0.0)
                            End If
                        Else
                            If mousePoint.Y > _startPoint.Y Then
                                pt = _startPoint
                            Else
                                Dim x As Double = (mousePoint.Y - _startPoint.Y) / Math.Tan(_dragAngle * Math.PI / 180)
                                pt = New Point3d(_startPoint.X + x, mousePoint.Y, 0.0)
                            End If
                        End If
                    End If
                    Return pt
                End If
            End If
            If _dragAngle >= 90.0 AndAlso _dragAngle <= 270.0 Then
                If mousePoint.X >= _startPoint.X Then
                    pt = _startPoint
                Else
                    If _dragAngle >= 135.0 AndAlso _dragAngle <= 225.0 Then
                        Dim y As Double = (mousePoint.X - _startPoint.X) * Math.Tan(_dragAngle * Math.PI / 180)
                        pt = New Point3d(mousePoint.X, _startPoint.Y + y, 0.0)
                    Else
                        If _dragAngle >= 90.0 AndAlso _dragAngle < 135.0 Then
                            If mousePoint.Y <= _startPoint.Y Then
                                pt = _startPoint
                            Else
                                Dim x As Double = (mousePoint.Y - _startPoint.Y) / Math.Tan(_dragAngle * Math.PI / 180)
                                pt = New Point3d(_startPoint.X + x, mousePoint.Y, 0.0)
                            End If
                        Else
                            If mousePoint.Y >= _startPoint.Y Then
                                pt = _startPoint
                            Else
                                Dim x As Double = (mousePoint.Y - _startPoint.Y) / Math.Tan(_dragAngle * Math.PI / 180)
                                pt = New Point3d(_startPoint.X + x, mousePoint.Y, 0.0)
                            End If
                        End If
                    End If
                    Return pt
                End If
            End If
            Return pt
        End Function
        Private Function GetEndPoint() As Boolean
            'endPoint = new Point3d();
            Dim go As Boolean = True
            Dim picked As Boolean = False
            While go
                Dim opt As New PromptPointOptions(vbLf & "Pick point:")
                'opt.BasePoint = _startPoint;
                'opt.UseBasePoint = true;
                opt.Keywords.Add("Start point")
                opt.Keywords.Add("Angle")
                opt.Keywords.Add("End point")
                opt.Keywords.Add("eXit")
                opt.Keywords.[Default] = "End point"
                opt.AppendKeywordsToMessage = True
                opt.AllowArbitraryInput = False
                opt.AllowNone = False
                Dim res As PromptPointResult = _editor.GetPoint(opt)
                If res.Status = PromptStatus.Cancel Then
                    go = False
                Else
                    Select Case res.Status
                        Case PromptStatus.Keyword
                            '_editor.WriteMessage("\n" + res.StringResult);
                            If res.StringResult.StartsWith("Start") Then
                                SetStartPoint()
                                go = True
                            End If
                            If res.StringResult.StartsWith("Angle") Then
                                SetAngle()
                                go = True
                            End If
                            If res.StringResult.StartsWith("eXit") Then
                                go = False
                            End If
                            Exit Select
                        Case PromptStatus.OK
                            'endPoint = res.Value;
                            picked = True
                            go = False
                            Exit Select
                        Case Else
                            go = True
                            Exit Select
                    End Select
                End If
            End While
            Return picked
        End Function
        Private Sub SetStartPoint()
            ClearTransientGraphics()
            RemoveHandler _editor.PointMonitor, AddressOf Editor_PointMonitor
            Dim opt As New PromptPointOptions(vbLf & "Start point:")
            Dim res As PromptPointResult = _editor.GetPoint(opt)
            If res.Status = PromptStatus.OK Then
                _startPoint = res.Value
            End If
            AddHandler _editor.PointMonitor, New PointMonitorEventHandler(AddressOf Editor_PointMonitor)
        End Sub
        Private Sub SetAngle()
            ClearTransientGraphics()
            RemoveHandler _editor.PointMonitor, AddressOf Editor_PointMonitor
            Dim opt As New PromptDoubleOptions(vbLf & "Enter drag-angle in degree [" + _dragAngle.ToString() + "]: ")
            opt.AllowNegative = False
            opt.AllowZero = True
            opt.AllowNone = True
            Dim res As PromptDoubleResult = _editor.GetDouble(opt)
            If res.Status = PromptStatus.OK Then
                _dragAngle = res.Value
                If _dragAngle > 360.0 Then
                    _dragAngle -= 360.0
                End If
            End If
            AddHandler _editor.PointMonitor, New PointMonitorEventHandler(AddressOf Editor_PointMonitor)
        End Sub
    End Class

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community