.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hide last command

5 REPLIES 5
Reply
Message 1 of 6
jdsmit
299 Views, 5 Replies

Hide last command

Hi,

 

What I need is: start my own command "like _drawline"

Then the user needs to draw a polyline.

After finishing that command i need to change something about the polyline.

And when i recall the last command it need to be '_drawline'

 

The most things i can do, but when i starts (with SendStringToExecute) the command '_pline', then the last command is '_pline' and it need to be '_drawline'

 

Is there a simple solution for this in vb.net?

 

Greetings Jacco

5 REPLIES 5
Message 2 of 6
Keith.Brown
in reply to: jdsmit

The first and most obvious thing that comes to mind is to not use sendtostringexecute to draw a pline but instead draw the pline programatically.  There are many articles on the web on how to do this including the help file.  Below are a few links to get you started.

 

http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-EC036F5A-1F02-40D3-B348-4193BA58CF0C...

 

http://www.theswamp.org/index.php?topic=29216.0

 

I hope this helps.

 

Message 3 of 6
jdsmit
in reply to: Keith.Brown

It is a possability to do this.

But what i can't do is using the function ortho on/off

I really need that.

 

Message 4 of 6
jdsmit
in reply to: jdsmit

It works !!

The only thing now i can't is exit after the close command.

Can you help me with this?

 

This is my code:

 

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

Class JigUtils

    ' Custom ArcTangent method, as the Math.Atan
    ' doesn't handle specific cases

    Public Shared Function Atan(y As Double, x As Double) As Double

        If x > 0 Then
            Return Math.Atan(y / x)
        ElseIf x < 0 Then
            Return Math.Atan(y / x) - Math.PI
        Else
            ' x == 0
            If y > 0 Then
                Return Math.PI
            ElseIf y < 0 Then
                Return -Math.PI
            Else
                ' if (y == 0) theta is undefined
                Return 0.0
            End If
        End If

    End Function

    ' Computes Angle between current direction
    ' (vector from last vertex to current vertex)
    ' and the last pline segment

    Public Shared Function ComputeAngle(startPoint As Point3d, endPoint As Point3d, xdir As Vector3d, ucs As Matrix3d) As Double

        Dim v As New Vector3d((endPoint.X - startPoint.X) / 2, (endPoint.Y - startPoint.Y) / 2, (endPoint.Z - startPoint.Z) / 2)
        Dim cos As Double = v.DotProduct(xdir)
        Dim sin As Double = v.DotProduct(Vector3d.ZAxis.TransformBy(ucs).CrossProduct(xdir))
        Return Atan(sin, cos)

    End Function

End Class

Public Class BulgePolyJig
    Inherits EntityJig

    Private _tempPoint As Point3d
    Private _plane As Plane
    Private _isArcSeg As Boolean = False
    Private _isClose As Boolean = False
    Private _isUndoing As Boolean = False
    Private _ucs As Matrix3d



    Public Sub New(ucs As Matrix3d)
        MyBase.New(New Polyline())
        _ucs = ucs

        Dim normal As Vector3d = Vector3d.ZAxis.TransformBy(ucs)

        _plane = New Plane(Point3d.Origin, normal)

        Dim pline As Polyline = TryCast(Entity, Polyline)

        pline.SetDatabaseDefaults()
        pline.Normal = normal

        AddDummyVertex()
    End Sub



    Protected Overrides Function Sampler(prompts As JigPrompts) As SamplerStatus

        Dim jigOpts As New JigPromptPointOptions()

        jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates Or UserInputControls.NullResponseAccepted Or UserInputControls.NoNegativeResponseAccepted)

        _isUndoing = False

        Dim pline As Polyline = TryCast(Entity, Polyline)

        If pline.NumberOfVertices = 1 Then

            ' For the first vertex, just ask for the point

            jigOpts.Message = vbLf & "Specify start point: "

        ElseIf pline.NumberOfVertices > 1 Then

            jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates Or UserInputControls.NullResponseAccepted Or UserInputControls.NoNegativeResponseAccepted Or UserInputControls.GovernedByOrthoMode)
            Dim msgAndKwds As String = (If(_isArcSeg, vbLf & "Specify endpoint of arc or [Line/Undo/Close]: ", vbLf & "Specify next point or [Arc/Undo/Close]: "))
            Dim kwds As String = (If(_isArcSeg, "Line Undo Close", "Arc Undo Close"))
            jigOpts.SetMessageAndKeywords(msgAndKwds, kwds)
        Else
            Return SamplerStatus.Cancel
        End If
        ' Should never happen
        ' Get the point itself

        Dim res As PromptPointResult = prompts.AcquirePoint(jigOpts)

        If res.Status = PromptStatus.Keyword Then

            If res.StringResult.ToUpper() = "ARC" Then
                _isArcSeg = True
            ElseIf res.StringResult.ToUpper() = "LINE" Then
                _isArcSeg = False
            ElseIf res.StringResult.ToUpper() = "UNDO" Then
                _isUndoing = True
            ElseIf res.StringResult.ToUpper() = "CLOSE" Then
                _isClose = True
            End If

            Return SamplerStatus.OK

        ElseIf res.Status = PromptStatus.OK Then
            ' Check if it has changed or not (reduces flicker)
            If _tempPoint = res.Value Then
                Return SamplerStatus.NoChange
            Else
                _tempPoint = res.Value
                Return SamplerStatus.OK
            End If
        End If

        Return SamplerStatus.Cancel

    End Function

    Protected Overrides Function Update() As Boolean

        ' Update the dummy vertex to be our 3D point
        ' projected onto our plane

        Dim pl As Polyline = TryCast(Entity, Polyline)

        If _isArcSeg Then

            Dim lastVertex As Point3d = pl.GetPoint3dAt(pl.NumberOfVertices - 2)
            Dim refDir As Vector3d

            If pl.NumberOfVertices < 3 Then

                refDir = New Vector3d(1.0, 1.0, 0.0)
            Else
                ' Check bulge to see if last segment was an arc or a line
                If pl.GetBulgeAt(pl.NumberOfVertices - 3) <> 0 Then
                    Dim arcSegment As CircularArc3d = pl.GetArcSegmentAt(pl.NumberOfVertices - 3)
                    Dim tangent As Line3d = arcSegment.GetTangent(lastVertex)

                    ' Reference direction is the invert of the arc tangent
                    ' at last vertex
                    refDir = tangent.Direction.MultiplyBy(-1.0)
                Else
                    Dim pt As Point3d = pl.GetPoint3dAt(pl.NumberOfVertices - 3)
                    refDir = New Vector3d(lastVertex.X - pt.X, lastVertex.Y - pt.Y, lastVertex.Z - pt.Z)

                End If
            End If

            Dim angle As Double = JigUtils.ComputeAngle(lastVertex, _tempPoint, refDir, _ucs)

            ' Bulge is defined as tan of one fourth of included angle
            ' Need to double the angle since it represents the included
            ' angle of the arc
            ' So formula is: bulge = Tan(angle * 2 * 0.25)

            Dim bulge As Double = Math.Tan(angle * 0.5)
            pl.SetBulgeAt(pl.NumberOfVertices - 2, bulge)
        Else
            ' Line mode. Need to remove last bulge if there was one
            If pl.NumberOfVertices > 1 Then
                pl.SetBulgeAt(pl.NumberOfVertices - 2, 0)
            End If
        End If

        pl.SetPointAt(pl.NumberOfVertices - 1, _tempPoint.Convert2d(_plane))

        Return True

    End Function

    Public ReadOnly Property IsUndoing() As Boolean

        Get
            Return _isUndoing
        End Get

    End Property
    Public ReadOnly Property IsClose() As Boolean

        Get
            Return _isClose
        End Get

    End Property

    Public Sub AddDummyVertex()

        ' Create a new dummy vertex... can have any initial value
        Dim pline As Polyline = TryCast(Entity, Polyline)
        pline.AddVertexAt(pline.NumberOfVertices, New Point2d(0, 0), 0, 0, 0)

    End Sub

    Public Sub RemoveLastVertex()

        Dim pline As Polyline = TryCast(Entity, Polyline)

        ' Let's first remove our dummy vertex   

        If pline.NumberOfVertices > 0 Then
            pline.RemoveVertexAt(pline.NumberOfVertices - 1)
        End If

        ' And then check the type of the last segment

        If pline.NumberOfVertices >= 2 Then

            Dim blg As Double = pline.GetBulgeAt(pline.NumberOfVertices - 2)
            _isArcSeg = (blg <> 0)
        End If

    End Sub
    Public Sub CloseVertex()

        Dim pline As Polyline = TryCast(Entity, Polyline)
        pline.Closed = True

    End Sub

    Public Sub Append()

        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim tr As Transaction = db.TransactionManager.StartTransaction()

        Using tr

            Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)

            btr.AppendEntity(Me.Entity)
            tr.AddNewlyCreatedDBObject(Me.Entity, True)
            tr.Commit()

        End Using

    End Sub

    <CommandMethod("mp")> _
    Public Shared Sub RunBulgePolyJig()

        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim jig As New BulgePolyJig(ed.CurrentUserCoordinateSystem)

        While True

            Dim res As PromptResult = ed.Drag(jig)
            Select Case res.Status
                ' New point was added, keep going

                Case PromptStatus.OK

                    jig.AddDummyVertex()

                    Exit Select
                    ' Keyword was entered

                Case PromptStatus.Keyword

                    If jig.IsUndoing Then
                        jig.RemoveLastVertex()
                    End If

                    If jig.IsClose Then
                        jig.CloseVertex()

                    End If

                    Exit Select
                    ' If the jig completed successfully, add the polyline

                Case PromptStatus.None

                    jig.RemoveLastVertex()
                    jig.Append()

                    Return
                Case Else

                    ' User cancelled the command, get out of here
                    ' and don't forget to dispose the jigged entity

                    jig.Entity.Dispose()

                    Return

            End Select

        End While

    End Sub

End Class

Message 5 of 6
hgasty1001
in reply to: jdsmit

Hi,

 

As you just copied the code from Kean's blog, maybe you just try asking there for support.

 

Gaston Nunez

 

 

Message 6 of 6
jdsmit
in reply to: hgasty1001

I used the code in C#, change it it vb.net and add some features in it.

I was hoping that someone can help me with this feature close.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost