2016-06-30 1 views
0

선의 거리를 측정하기 위해 AutoCAD 플러그인을 만들었습니다. 내가 만든 플러그인을로드하는 Windows 양식 응용 프로그램을 작성했습니다. 나는 창문 양식 응용 프로그램 내 AutoCAD를 플러그인에서 명령을 사용하여 측정 된 값을 반환하려고하지만, 모두가 내가 할 방법의 vain.Some에 갔다하는 것은 다음과 같습니다AutoCAD 명령에서 Windows 양식 응용 프로그램으로 값 반환

내가 AutoCAD에서 얻은 결과를 삽입하고를 가져 오지하려고 . 인터페이스 기술을 사용해 봅니다.

답변

0

그런 다음 외부 프로세스에서 Document.GetVariable COM API를 읽을의 USERR1 to USERR5 시스템 변수에 거리를 저장할 수 있습니다.

EndCommand 이벤트에 처리기를 설치하여 명령 완료 시점을 감지 할 수 있습니다. 당신이 당신의 창 형태의 응용 프로그램에서 AutoCAD에서 플러그인을로드하는 방법

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

: 여기

몇 가지 코드? 어떻게 명령을 내리고 있니? – Maxence

+0

다음과 같이 추가하면됩니다 : (명령 "+ (char) 34 +"NETLOAD "+ (char) 34 +" "+ (char) 34 + (Dll 경로) + (char) 34 +") "; 버튼을 클릭 이벤트. 그냥 명령을 사용하여 lauch SendCommand –

+0

나는 this.So에 새로운 오전 EndCommand 이벤트 처리기를 설치하는 방법을 묻는 오전. 예를 들어 제공 할 수 있다면 위대한 것입니다. –