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

Equivalent of VBAs getdistance in .NET

4 REPLIES 4
Reply
Message 1 of 5
iwtblj
759 Views, 4 Replies

Equivalent of VBAs getdistance in .NET

I'm converting from VBA to VB.NET and I've run into a snag converting some of the utility.getxxx methods, for instance the getDistance method. Everything I've been able to find says that Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDistance in .NET is the equivalent of AutoCAD.Application.ActiveDocument.Utility.GetDistance in VBA, but the VBA command takes two optional parameters, a starting point and a prompt whereas VB.NET only takes one, a prompt. Every reference I've found so far assumes that you're not using the optional first parameter, but most of time, I am using it. Is there a way to specify the starting point so that the user only needs to input 1?
4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: iwtblj

There are TWO overloaded Editor.GetDistance() methods! One has a "String" argument, while the other one has an argument of "PromptDistanceOptions" type.

PromptDistanceOptions class is what you want.

Sometimes when being too focused, one could easily not see the obvious.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5
iwtblj
in reply to: iwtblj

I actually saw that, but it didn't seem to be what I needed. Apparently, I just didn't look at it closely enough. I tried creating a PromptDistanceOptions object, but since the constructor only asked for strings, I assumed that I needed something else. Now that I looked at it closer, I saw that it has a basepoint property that I have to set after creation. That's for point out the obvious 🙂
Message 4 of 5
Anonymous
in reply to: iwtblj

In this area, there's not much equivalence between the ActiveX and .NET
APIs.

Most of the Editor's GetXxxxx() methods accept a type derived from
PromptOptions, with methods and properties that can be used to govern how
input is obtained, and do things that require a call to the
InitializeUserInput() method in ActiveX (e.g. option keywords;
allowing/disallowing zero, negative, or null reponses; etc.).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6287864@discussion.autodesk.com...
I'm converting from VBA to VB.NET and I've run into a snag converting some
of the utility.getxxx methods, for instance the getDistance method.
Everything I've been able to find says that
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDistance
in .NET is the equivalent of
AutoCAD.Application.ActiveDocument.Utility.GetDistance in VBA, but the VBA
command takes two optional parameters, a starting point and a prompt whereas
VB.NET only takes one, a prompt. Every reference I've found so far assumes
that you're not using the optional first parameter, but most of time, I am
using it. Is there a way to specify the starting point so that the user
only needs to input 1?
Message 5 of 5
jerrywinters
in reply to: iwtblj

Tony's correct that there is no equivalent call in .NET We can get the same result as VBA by providing a BasePoint in a PromptDistanceOptions object as shown below.

It is also sometimes useful when migrating from VBA is to recreate the VBA call in .NET using the same basic parameters. This shown in the vbaGetDistance Function below.

{code}
Public Sub TryDistance()
Dim PtA As Autodesk.AutoCAD.Geometry.Point3d
Dim selDistance As Double
Dim myEditor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
PtA = myEditor.GetPoint("Select first point:").Value
Dim myPDO As New PromptDistanceOptions("Select second point:")
myPDO.BasePoint = PtA
myPDO.UseBasePoint = True
selDistance = myEditor.GetDistance(myPDO).Value

Dim vbaDist As Double = vbaGetDistance(New Point3d(2, 3, 4), "Select a point:")
MsgBox("The distance is " & vbaDist.ToString)

End Sub

Function vbaGetDistance(ByVal BasePt As Point3d, ByVal Prompt As String) As Double
Dim myEditor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim myPDO As New PromptDistanceOptions(Prompt)
myPDO.BasePoint = BasePt
myPDO.UseBasePoint = True
Return myEditor.GetDistance(myPDO).Value
End Function

{code}
I hope this is helpful.

Jerry

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