Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to detect is opened preview document in type properties?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
ModPlus
365 Views, 6 Replies

How to detect is opened preview document in type properties?

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?

6 REPLIES 6
Message 2 of 7
jeremy_tammik
in reply to: ModPlus

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
Message 3 of 7
nice3point
in reply to: ModPlus

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

 

Message 4 of 7
ModPlus
in reply to: nice3point


@nice3point wrote:

This name is probably language dependent

 


Unfortunately, names are language-dependent

Message 5 of 7
ModPlus
in reply to: jeremy_tammik

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

 

Message 6 of 7
jeremy_tammik
in reply to: ModPlus

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
Message 7 of 7
jeremy_tammik
in reply to: ModPlus

... 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report