【问题标题】:Editor.GetEntity does not wait for user input (click)Editor.GetEntity 不等待用户输入(点击)
【发布时间】:2019-03-09 11:42:28
【问题描述】:

我有两个 dwg 文件:PID.dwg 和 3D.dwg

用例是在 PID.dwg 上运行一个函数,然后在 3D.dwg 上运行——尤其是按照这个顺序。

下面 SendCommand 中使用的命令来自一个单独的 DLL 文件,我在执行此函数之前使用 NETLOAD 加载该文件。

Dim app As AcadApplication = CType(Application.AcadApplication, AcadApplication)
' Ctype( Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, 
'        Autodesk.AutoCAD.Interop.AcadApplication )

If isPidAnd3dOpened() Then
    ' Activate PID document
    app.ActiveDocument = acDocPid
    'acDocPid.Activate()
    acDocPid.SendCommand("DOSOMETHINGONPID" & vbCrLf)

    ' Activate 3D document
    app.ActiveDocument = acDoc3d
    'acDoc3d.Activate()
    acDoc3d.SendCommand("DOSOMETHINGON3D" & vbCrLf)
End If

"DOSOMETINGON3D" 的功能需要用户使用Editor.GetEntity 输入。

但是,当acDoc3d.SendCommand("DOSOMETHINGON3D" & vbCrLf) 执行时,它不会暂停等待用户输入。

我错过了什么?

【问题讨论】:

    标签: vb.net autocad autocad-plugin


    【解决方案1】:

    可能您必须等到命令DOSOMETHINGONPID 完成。

    在 ARX 中会是这样的:

    CString activeCMDName = _T("DOSOMETHINGONPID");
    bool EOL = false;
    while (!EOL)
    {
        CString cmds = Variable::Get(_T("CMDNAMES") );      
        if (cmds.Find( activeCMDName ) > 0 )    {
            Command::Wait();
        }
        else    {
            EOL = true;
        }
    }
    

    在哪里

    CString Variable::Get( CString name )
    {
        CString OutVal;
        resbuf rb ;
        acedGetVar(name, &rb);
        OutVal.SetString(rb.resval.rstring);
        acutDelString(rb.resval.rstring);   
        return OutVal ;
    }
    
    void Command::Wait()
    {
        ResBuf rb;
        rb.Add(RTSTR , _T("\\"));
        int ret = acedCmd(rb.GetFirst());
    }
    

    抱歉,.net 中没有此代码。希望你能处理好。

    【讨论】:

    • 我尝试删除 DOSOMETHINGONPID 但从 PID 文档中调用了这个函数,它仍然不等待用户输入。
    【解决方案2】:

    第一个答案是正确的,SendCommand 无法处理异步命令。 Here 是 .Net 中的建议解决方案:

    //Create AutoCAD instance, then...
    
    acadApp.ActiveDocument.SendCommand("(command \"NETLOAD\""+@"""C:\\acad\\networkdll\\SecondAssembly.dll"") ");
    acadApp.ActiveDocument.SendCommand("#MYCOMMAND 0 ");
    
    //Register EndCommand handler.
    _DAcadApplicationEvents_EndCommandEventHandler handler = new  
        _DAcadApplicationEvents_EndCommandEventHandler(CommandEnded);
    
    acadApp.EndCommand += handler;
    waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
    waitHandle.WaitOne();
    acadApp.EndCommand -= handler;
    
    //Close the startup drawing (this requires waiting @ SendCommand) because
    //Drawing will cause a COMException otherwise.  'Drawing is busy'
    //Mostly likely since the ActiceDocument is the startup drawing.
    

    事件处理程序:

    public void CommandEnded(string globalCommandName)
    {
        System.Windows.MessageBox.Show(globalCommandName + " just ended.");
        waitHandle.Set();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 2021-03-05
      • 2018-09-28
      • 1970-01-01
      相关资源
      最近更新 更多