防止Revit窗口打开

时间:2015-03-24 21:44:06

标签: c# revit revit-api

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

3 个答案:

答案 0 :(得分:0)

你可以随时删除warrnings: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;
    }
}

我希望它会有所帮助

答案 1 :(得分:0)

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

    [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(窗口名称)和ButtonName设置为单击。

将其称为计时器事件,该事件等待窗口弹出。

  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("","")
    }

尝试一下,让我知道。

答案 2 :(得分:0)

好吧,因为有一个新评论,我将这作为正式答复。我想出的最好的办法是即使您不能取消对话框,也可以在对话框上调用OverrideResult()。窗台上闪烁着不理想的对话框,但是比以前要好。。。如果有人有更好的方法,我想听听:)

相关问题