阻止 Revit window 打开

Prevent Revit window from opening

我正在尝试拦截 Revit 并阻止 window 打开。具体来说,我正在尝试将基调应用于一个对象,然后让用户创建一个基调标签,但是我这样做的任何方式都会让他们放置基调,然后立即给他们对话框 select 一个基调,但我不希望出现该对话框,因为我已经知道 selection 应该是什么。但是,我能想到的每一种方法都无法在用户获得对话框之前中断应用主题演讲的过程。是否可以监视 window 出现然后通过 Windows API 关闭它?甚至更好地拦截它要显示的时间并阻止它显示?

您可以随时删除警告 with:failuresAccessor.DeleteWarning(fma);

这就是我用于我的代码的内容

    public class FloorPreProcessor : IFailuresPreprocessor
{
    FailureProcessingResult
      IFailuresPreprocessor.PreprocessFailures(
        FailuresAccessor failuresAccessor)
    {

        IList<FailureMessageAccessor> fmas
          = failuresAccessor.GetFailureMessages();

        if (fmas.Count == 0)
        {
            return FailureProcessingResult.Continue;
        }

        // We already know the transaction name.

        if (fmas.Count != 0)
        {
            foreach (FailureMessageAccessor fma in fmas)
            {
                // DeleteWarning mimics clicking 'Ok' button.
                failuresAccessor.DeleteWarning(fma);
            }

            return FailureProcessingResult
              .ProceedWithCommit;
        }
        return FailureProcessingResult.Continue;
    }
}

希望对你有所帮助

尝试以下操作,它会搜索 window 名称、按钮名称,然后单击此按钮:

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

    private const uint BM_CLICK = 0x00F5;


    public static bool clickButton (string popUpTitle, string ButtonName)
    {
        // Get the handle of the window
        IntPtr windowHandle = FindWindow((string)null, popUpTitle);
        if (windowHandle.ToInt32() == 0)
        {
            return false;
        }

        // Get button handle
        IntPtr buttonHandle = FindWindowEx(windowHandle, IntPtr.Zero, (string)null, ButtonName);
        if (buttonHandle.ToInt32() == 0) 
        {
            return false;
        }
        // Send click to the button
        SendMessage(buttonHandle, BM_CLICK, 0, 0);
        return true;
    }

您应该设置 popUpTitle(window 名称)和要单击的 ButtonName。

将此调用到等待 window 弹出的计时器事件中。

  Timer timer = new Timer();
                timer.Start();
                timer.Tick += new EventHandler(timer_Tick);
  //when done call timer.Stop();

  private void timer_Tick(object sender, EventArgs e)
    {
       //set your code to clickButton("","")
    }

试试看然后告诉我。

好的,既然有新的评论,我会把它作为一个正式的回答。我想出的最好办法是,即使您无法取消它,您也可以在对话框中调用 OverrideResult()。它仍然会闪烁对话框,虽然不是很理想,但比以前好多了……如果有人有更好的方法,我很想听听:)