Error when escaping GetPoint

Error when escaping GetPoint

NickBrege
Enthusiast Enthusiast
454 Views
2 Replies
Message 1 of 3

Error when escaping GetPoint

NickBrege
Enthusiast
Enthusiast

I am using the GetPoint function to prompt the user to select a point on screen.  However if the user changes their mind & presses escape, my code throws an exception.  I know I can use a Try/Catch to handle it, but I was wondering if there was a better way, as Try/Catch is not very elegant.  The pertinent code is below....

 

 

            Dim origin As Double() = CType(acadDoc.Utility.GetPoint(, "Select part origin: "), Double())
            xOrigin = origin(0)
            yOrigin = origin(1)

 

 

BTW ... I am using the COM/Interop API & VB.Net

 

Thanks...

0 Likes
455 Views
2 Replies
Replies (2)
Message 2 of 3

hippe013
Advisor
Advisor

Do you have to use the COM API for a particular reason? The following is a quick snippet for prompting the user for a point using the managed API. 

 

Dim aDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = aDoc.Editor
Dim opt As New PromptPointOptions(vbCrLf & "Select Part Origin: ")
Dim res As PromptPointResult = ed.GetPoint(opt)
If res.Status <> PromptStatus.OK Then Exit Sub
Dim selPoint As Point3d = res.Value

 

After selecting the point you can check the 'status' of the PromptPointResult.  If the status is okay you can then get the point using the result value. 

 

 

0 Likes
Message 3 of 3

norman.yuan
Mentor
Mentor

Addition to what @hippe013 said:

 

It is what the COM API was designed: press ESC with AcadUtility.GetXxxxx() method raises exception. It is your responsibility to handle it. So, yes, you need to "Try...Catch..." it. If you are doing .NET API add-in, then there is no reason to use this COM API method at all.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes