2016-06-30 9 views
0

私はAutoCADプラグインを作成して距離を測定しています。作成したプラグインを読み込むWindowsフォームアプリケーションを作成しました。私は窓に私のAutoCADのプラグインでコマンドを用いて測定した値を返すようにしようとしたアプリケーションを形成するが、すべて私が行う方法のvain.Someに行ってきましたが、次のとおりです。autocadコマンドからwindowsフォームアプリケーションに値を返す

私は、AutoCADで得られた結果を挿入していることをretriveしてみてください。 私はインターフェイス技術を試してみます。

答えて

0

距離をUSERR1 to USERR5システム変数に格納してから、外部プロセスからDocument.GetVariable COM APIで読み取ることができます。

EndCommandイベントにハンドラをインストールして、コマンドの終了を検出できます。ここで

はいくつかのコードです:

using Autodesk.AutoCAD.Interop; 

[..] 

void button1_Click(object sender, EventArgs e) 
{ 
    const uint MK_E_UNAVAILABLE = 0x800401e3; 

    AcadApplication acad; 
    try 
    { 
     // Try to get a running instance of AutoCAD 2016 
     acad = (AcadApplication) Marshal.GetActiveObject("AutoCAD.Application.20.1"); 
    } 
    catch (COMException ex) when ((uint) ex.ErrorCode == MK_E_UNAVAILABLE) 
    { 
     // AutoCAD is not running, we start it 
     acad = (AcadApplication) Activator.CreateInstance(Type.GetTypeFromProgID("AutoCAD.Application.20.1")); 
    } 
    activeDocument = acad.ActiveDocument; 
    activeDocument.EndCommand += ActiveDocument_EndCommand; 
    activeDocument.SendCommand("YOURCOMMAND "); 
} 

void ActiveDocument_EndCommand(string CommandName) 
{ 
    if (CommandName != "YOURCOMMAND") return; 
    try 
    { 
     double value = activeDocument.GetVariable("USERR1"); 
     // Process the value 
     MessageBox.Show(value.ToString()); 
    } 
    finally 
    { 
     // Remove the handler 
     activeDocument.EndCommand -= ActiveDocument_EndCommand; 
    } 
} 
+0

どのようにあなたの窓からAutoCADであなたのプラグインをロードしているアプリケーションを形成しますか?そして、あなたはどのようにコマンドを起動していますか? – Maxence

+0

あなたは次のものを追加するだけです:(コマンド "+(char)34 +" NETLOAD "+(char)34 +" "+ (char)34 +(あなたのDllパス)+(char)34 +") "; atボタンのクリックイベントです。ちょうどSendCommandを使用してlauchコマンドを使用して –

+0

私はthis.soで新しく私はEndCommandイベントにハンドラをインストールする方法を尋ねている。あなたが私に例を提供することができれば素晴らしいだろう –

関連する問題