プロンプト ラインまたは画面上の点の選択セットからの距離を取得します。
サポートされているプラットフォーム: Windows のみ
VBA:
RetVal = object.GetDistance([Point [, Prompt]])
タイプ: Utility
このメソッドが適用されるオブジェクト。
アクセス: 入力のみ; オプション
タイプ: バリアント型(3 要素の倍精度浮動小数点数型配列)
基点を指定する 3D WCS 座標この点が与えられていない場合は、2 点を入力する必要があります。
アクセス: 入力のみ; オプション
タイプ: バリアント型(文字列)
ユーザに入力を求めるときに表示される文字列。
タイプ: バリアント型(倍精度浮動小数点数または倍精度浮動小数点数型配列)
プロンプト ラインおよび図面上で選択された点の集合からの距離
AutoCAD は、ユーザが直線距離を入力するのを待って、選択された距離の値に対する戻り値を設定します。パラメータ Point は、基点の WCS 座標を指定します。パラメータ Prompt は、ユーザ入力を求める際に AutoCAD が表示する文字列を指定します。Point および Prompt はオプションです。
現在の単位で数値を入力すれば、距離を指定することができます。また、グラフィックス画面上の 2 点を指定して、距離を設定することもできます。AutoCAD は距離を視覚的に確認できるように、最初の点から現在のクロスヘア カーソルの位置までのラバーバンド線を描きます。パラメータ Point が与えられている場合は、その値が 2 点の内の最初の点として使用されます。
既定では、GetDistance メソッドはパラメータ Point と戻り値を 3 次元の点として処理します。あらかじめ InitializeUserInput メソッドを呼び出して、Point を 2 次元の値として処理するよう設定すれば、このメソッドで平面上の距離を得ることができます。
使用する方法や現在の距離の単位(例、フィートとインチ)に関係なく、GetDistance メソッドは常に倍精度浮動小数点数型の戻り値を返します。
VBA:
Sub Example_GetDistance()
' This example returns the distance entered by the user.
AppActivate ThisDrawing.Application.Caption
Dim returnDist As Double
Dim basePnt(0 To 2) As Double
basePnt(0) = 0#: basePnt(1) = 0#: basePnt(2) = 0#
' Return the value entered by user. A prompt is provided.
returnDist = ThisDrawing.Utility.GetDistance(, "Enter distance: ")
MsgBox "The distance entered was " & returnDist & vbCrLf & _
"(Enter the next value without prompting.)", , "GetDistance Example"
' Return the value entered by user. No prompt is provided.
returnDist = ThisDrawing.Utility.GetDistance()
MsgBox "The distance entered was " & returnDist, , "GetDistance Example"
' Return the value entered by user. A base point and prompt are provided.
returnDist = ThisDrawing.Utility.GetDistance(basePnt, "Enter a distance: ")
MsgBox "The distance entered was " & returnDist, , "GetDistance Example"
End Sub
Visual LISP:
(vl-load-com)
(defun c:Example_GetDistance()
;; This example returns the distance entered by the user.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Return the value entered by user. A prompt is provided.
(setq returnDist (vla-GetDistance (vla-get-Utility doc) nil "Enter distance: "))
(alert (strcat "The distance entered was " (rtos returnDist 2) "\n"
"(Enter the next value without prompting.)"))
;; Return the value entered by user. No prompt is provided.
(setq returnDist (vla-GetDistance (vla-get-Utility doc)))
(alert (strcat "The distance entered was " (rtos returnDist 2)))
;; Return the value entered by user. A base point and prompt are provided.
(setq basePnt (vlax-3d-point 0 0 0))
(setq returnDist (vla-GetDistance (vla-get-Utility doc) basePnt "Enter a distance: "))
(alert (strcat "The distance entered was " (rtos returnDist 2)))
)