.NET

Reply
Contributor
h.sezenn
Posts: 18
Registered: ‎03-27-2013
Message 1 of 3 (258 Views)
Accepted Solution

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

258 Views, 2 Replies
11-04-2013 09:58 AM

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
*Expert Elite*
norman.yuan
Posts: 968
Registered: ‎04-27-2009
Message 2 of 3 (200 Views)

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

11-05-2013 08:18 AM 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.

 

Contributor
h.sezenn
Posts: 18
Registered: ‎03-27-2013
Message 3 of 3 (177 Views)

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

11-06-2013 11:48 AM in reply to: norman.yuan

Thank you your answer :smileyhappy:

İ did it. itworked. :smileyhappy:

when I press ESC programme stopped.

 

_____________________________________________________________________________________
Everything For Duct

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