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

how can I cancel my sub when I press right click or escape?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
h.sezenn
698 Views, 2 Replies

how can I cancel my sub when I press right click or escape?

Hello friends;

I have 4 question actually.

1 quesiton:

 

I have program with do...loop while

I draw line(they are also block) but, when I press right click it doesnt exit sub?

how can I exit sub when I press escape or right click?

 

2 question:

 

When I press escape my programme add a new line. but I dont want it to add my draw. how Can I solved this issue?

 

3. question

 

I want to draw a line with temporary dimention( as you see picture) is it possible?

 

04-11-13SORU01.jpg

 

4 question

 

is appear any icon when I get on my line block ?( **** yo see on picture )( green plus)

 

picture02

04-11-13soru02.jpg

 

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports System.Windows.Input
Imports System.Windows.Forms


Public Class Class4
    <CommandMethod("deneme")> _
    Public Sub cizgiciz()
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim x As Integer

        x = 0

        Dim pPtRes As PromptPointResult
        Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
        pPtOpts.Message = vbLf & "NOKTA SEÇ:  "
        pPtRes = doc.Editor.GetPoint(pPtOpts)
        Dim ptStart As Point3d = pPtRes.Value
        Do
            x = x + 1
            Dim blockName As String = "CİZGİ" & x
            pPtOpts.Message = vbLf & "2.NOKTAYI SEÇ : "
            pPtOpts.UseBasePoint = True
            pPtOpts.BasePoint = ptStart
            pPtRes = doc.Editor.GetPoint(pPtOpts)
            Dim ptEnd As Point3d = pPtRes.Value
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                If Not bt.Has(blockName) Then
                    Dim btr As New BlockTableRecord()
                    btr.Name = blockName
                    btr.Origin = ptStart
                    bt.UpgradeOpen()
                    Dim btrId As ObjectId = bt.Add(btr)
                    tr.AddNewlyCreatedDBObject(btr, True)

                    Dim line As New Line(ptStart, ptEnd)
                    line.ColorIndex = x
                    line.LineWeight = LineWeight.LineWeight050
                    btr.AppendEntity(line)
                    tr.AddNewlyCreatedDBObject(line, True)
                    If btrId <> ObjectId.Null Then
                        Using acBlkRef As New BlockReference(ptStart, btrId)
                            Dim acCurSpaceBlkTblRec As BlockTableRecord
                            acCurSpaceBlkTblRec = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
                            acCurSpaceBlkTblRec.AppendEntity(acBlkRef)
                            tr.AddNewlyCreatedDBObject(acBlkRef, True)
                        End Using
                    End If

                    tr.Commit()
                End If
            End Using
            ptStart = ptEnd

        Loop While pPtRes.Status = PromptStatus.OK

    End Sub
End Class

 

_____________________________________________________________________________________
Everything For Duct
2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: h.sezenn

There are reasons that all the Editor.GetXXX() method return an PromptXXXXResult object instead of directly returniong the value the GetXXXX(0 is supposed to get (Point, Entity, Integer, String....), because user can press Esc to cancel the method, or enter wrong type of data. You need ALWAYS to test the status of PromptXXXResult before reaching the value inside. So, after your this line of code:

 

pPtRes = doc.Editor.GetPoint(pPtOpts)

 

You MUST do

 

If pPtRes.Status=PromptStatus.OK Then

   ''You only know at this moment that a point is picked

   Dim ptEnd As Point3d = pPtRes.Value

   ....

Else

   ''You quit the loop here

   Exit Do

End If

 

Once you understand you need to test PromptStatus of the returned PromptXXXXResult object, you probably be able to answer the questions you asked.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
h.sezenn
in reply to: norman.yuan

Thank you your answer 🙂

İ did it. itworked. 🙂

when I press ESC programme stopped.

 

_____________________________________________________________________________________
Everything For Duct

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