3

I'm trying to intercept Revit and keep a window from opening. Specifically, I'm trying to apply a keynote to an object and then let the user create a keynote tag, however any way I do it it lets them place the keynote but then immediately gives them the dialog to select a keynote, but I don't want that dialog to come up because I already know what the selection should be. However every way I can think of isn't able to interrupt the process to apply the keynote before the user gets the dialog. Is it possible to perhaps monitor for the window to appear then close it via Windows API? or even better intercept when it's going to be shown and stop it from showing?

sfaust
  • 2,089
  • 28
  • 54
  • p.s. I did try handling the dialog showing event and I can get notified when the dialog is about to show but the event can't be cancelled... – sfaust Mar 24 '15 at 21:48
  • Sorry after posting that last comment I looked into it more and You can call OverrideResult() on the dialog even though you can't cancel it. It sill flashes the dialog which isn't ideal but it's better than it was... If anyone has a better way I'd love to hear it :) – sfaust Mar 24 '15 at 21:55

3 Answers3

0

you can always delete warrnings with:failuresAccessor.DeleteWarning(fma);

this is what i use for my code

    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;
    }
}

I hope it will help

  • Right, but this isn't a failure processing event. It's just popping up the keynote selection dialog for the user to select, which is what I want to suppress... – sfaust Jul 05 '17 at 15:47
  • O so, you what to dismiss Dialog, I saw this here: https://boostyourbim.wordpress.com/2013/02/01/how-to-automatically-dismiss-a-revit-dialog/ but i didn't test this yet, but maby it will help you – Mikołaj Frankiewicz Jul 06 '17 at 10:12
  • yes per my last comment on the original question that's what I ended up doing. It does still flash the dialog for a second which I was hoping to avoid, but it's a lot better than it was and does the job. – sfaust Jul 06 '17 at 14:36
0

Try the following, it searches for a window name, button name, then clicks this button:

    [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;
    }

You should set the popUpTitle (window name) and the ButtonName to click.

Call this into a timer event that waits for a window to pop-up.

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

Try it and let me know.

  • 3 year old question... but again this waits for the dialog to open and then simulates a click which is one step less direct and reliable than the 'OverrideResult' option I ended up with and still would have the dialog flash. What I was hoping for was a way to keep the dialog from ever appearing. – sfaust Jul 11 '18 at 19:30
0

Ok well since there was a new comment I will make this an official answer. The best I came up with is that you can call OverrideResult() on the dialog even though you can't cancel it. It sill flashes the dialog which isn't ideal but it's better than it was... If anyone has a better way I'd love to hear it :)

sfaust
  • 2,089
  • 28
  • 54