SendStringToExecute メソッドを使用してコマンドを直接コマンド ラインに送ることができます。SendStringToExecute メソッドでは、単一の文字列をコマンド ラインに送ります。文字列には、実行されたコマンドが予期するプロンプト シーケンス順に、引数がリストされていなければなりません。
文字列中の空白や ASCII コードでキャリッジ リターンに対応するものは、キーボードで[Enter]を押すのと同じです。AutoLISP 環境と違い、引数のない SendStringToExecute メソッドの呼び出しは無効です。
SendStringToExecute で実行されるコマンドは非同期であり、.NET コマンドが終了するまで実行されません。コマンドを即座に(同期的に)実行する必要がある場合は、次の方法を使用します。
次の例は、中心が (2, 2, 0) で半径が 4 の円を作成します。次に、図面は図面内のすべてのジオメトリに拡大ズームされます。文字列の最後には、コマンドの実行を開始するため、[Enter]を示す空白があることに注意してください。
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("SendACommandToAutoCAD")> _
Public Sub SendACommandToAutoCAD()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
'' Draws a circle and zooms to the extents or
'' limits of the drawing
acDoc.SendStringToExecute("._circle 2,2,0 4 ", True, False, False)
acDoc.SendStringToExecute("._zoom _all ", True, False, False)
End Sub
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
[CommandMethod("SendACommandToAutoCAD")]
public static void SendACommandToAutoCAD()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
// Draws a circle and zooms to the extents or
// limits of the drawing
acDoc.SendStringToExecute("._circle 2,2,0 4 ", true, false, false);
acDoc.SendStringToExecute("._zoom _all ", true, false, false);
}
Sub SendACommandToAutoCAD() ' Draws a circle and zooms to the extents or ' limits of the drawing ThisDrawing.SendCommand "_Circle 2,2,0 4 " ThisDrawing.SendCommand "_zoom a " End Sub