How to detect is opened preview document in type properties?

ModPlus
Enthusiast
Enthusiast

How to detect is opened preview document in type properties?

ModPlus
Enthusiast
Enthusiast

There is a "Preview" button in the type properties dialog. If you click it, then, as far as I know, a copy of the current document will be created with a new view (I could be wrong here):

Screenshot_3.png

 

The problem is that in this case IUpdater is triggered, which can lead to negative consequences.

Question - how can I detect that this Preview is open or how can I detect that the dialog for editing type properties is open?

0 Likes
Reply
Accepted solutions (1)
383 Views
6 Replies
Replies (6)

jeremy_tammik
Autodesk
Autodesk

You use the native Windows API to detect that a specific Windows form is open. Presumably, this can also be done in .NET. You can search for something like ".net detect form open" to learn more:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

nice3point
Advocate
Advocate

You can try to track the DocumentChanged event, Revit creates elements and a view with a persistent name ‘Modify type attributes’. This name is probably language dependent, but Revit does not create any other events

nice3point_0-1715548594591.png

 

0 Likes

ModPlus
Enthusiast
Enthusiast

@nice3point wrote:

This name is probably language dependent

 


Unfortunately, names are language-dependent

0 Likes

ModPlus
Enthusiast
Enthusiast
Accepted solution

@jeremy_tammik  did as you suggested. A small auxiliary class:

using System;
using System.Runtime.InteropServices;
using Autodesk.Revit.UI;

/// <summary>
/// Initializes a new instance of the <see cref="RevitWindowUtils"/> class.
/// </summary>
/// <param name="uiApplication"><see cref="UIApplication"/></param>
public class RevitWindowUtils(UIApplication uiApplication)
{
    private readonly IntPtr _mainWindowHandle = uiApplication.MainWindowHandle;

    [DllImport("user32.dll")]
    private static extern IntPtr GetActiveWindow();
    
    /// <summary>
    /// Is main Revit window active
    /// </summary>
    public bool IsMainWindowActive() => GetActiveWindow() == _mainWindowHandle;
}

 

I create and store its static instance in the application class, and check it in IUpdater as follows:

public void Execute(UpdaterData data)
{
    if (!App.RevitWindowUtils.IsMainWindowActive())
        return;

 

0 Likes

jeremy_tammik
Autodesk
Autodesk

Great! Glad to hear that it helped. Thank you for sharing your implementation. It looks nice and generic, and may be useful for other situations as well.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

jeremy_tammik
Autodesk
Autodesk

... so, I shared it on the blog for future reference:

  

https://thebuildingcoder.typepad.com/blog/2024/05/lengthen-ducts-and-highlight-links.html#4

  

Thank you again for this. 

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open