Revit View active with WPF window over

Revit View active with WPF window over

mizrachi_amir2
Advocate Advocate
1,574 Views
11 Replies
Message 1 of 12

Revit View active with WPF window over

mizrachi_amir2
Advocate
Advocate

Hello,

 

I was wondering if there is any option to interact with the Revit model while my Revit plugin is active?

In other words - once I open my Revit plugin I would still like to be able to interact with the Revit model behind (selecting elements, taking measurements etc.).

 

Is this possible?

 

Thank you!

0 Likes
1,575 Views
11 Replies
Replies (11)
Message 2 of 12

alisa_wachs_M3
Contributor
Contributor

You would add Topmost="True" to your Window .xaml

<Window x:Class="Test.Dialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Test"
        mc:Ignorable="d"
        Title="Your Title here" Height="300" Width="300"
        Topmost="True"
        .......
        ShowInTaskbar="False">
  <Grid>

 

And then interact with it through IExternalEventHandler within either of yours IExternalDBApplication, IExternalApplication, IExternalCommand class.

Dialog.Show();
/*ShowDialog() vs Show() The first opens a window and does not return until
 the newly opened window is closed. It is a modal operation, meaning it blocks
 interaction with other windows in the application until it is closed. The
 second method opens a window but immediately returns control to the caller.
 The window opened is non-modal, so other windows remain usable, and the user
 can interact with all windows concurrently.*/
handler = new PluginEvent();
ExEvent = ExternalEvent.Create(handler);
public class PluginEvent : IExternalEventHandler
{
  public void Execute(UIApplication app)
  {
    // Get the current UIDocument
    UIDocument uiDoc = app.ActiveUIDocument;
    if (uiDoc != null)
    {
      // Get the selected element from the Dialog
    }
  }

  public string GetName()
  {
    return "Plugin Event";
  }
}

 

In the .cs behind your .xaml you would use ExEvent.Raise(); thus your WPF window will give back the reins to Revit to execute Revit specific actions.

 

My recent post included the visual studio solution where I do everything you asked for above.

And another example of using IExternalEvent

Message 3 of 12

alisa_wachs_M3
Contributor
Contributor

Forum ate my response, so here's a more condensed version.

 

  • In your IExternalApplication / IExternalDBApplication / IExternalCommand class you create and initialize your IExternalEventHandler and also use WPFwindowName.Show(); instead of WPFwindowName.ShowDialog();
  • In WPF.xaml use Topmost="True" on your Window
  • In .xaml.cs you'd use Raise();

In my recent post I've shared visual studio solution employing all of the above, it might give you an idea of how to tie it all together. Also good idea to review would be this Autodesk page and this blog 

Message 4 of 12

nd8G4SB
Explorer
Explorer

Hi @mizrachi_amir2 ,

If you want to create a "live" connection so that changes you make in scripts and Revit are immediately reflected in your plugin, then you should work with events. You can read more about this here:
DocumentChanged Event (revitapidocs.com)
Ajuda | Events | Autodesk

Best regards,
Nikolai Davydov

Message 5 of 12

nice3point
Advocate
Advocate

@mizrachi_amir2 

Single-project WPF Application sample (Modeless): https://github.com/Nice3point/RevitTemplates/tree/develop/samples/SingleProjectWpfModelessApplicatio...

 

Pay attention to the ViewModel, it contains all the necessary interaction

0 Likes
Message 6 of 12

mizrachi_amir2
Advocate
Advocate
Hi @Anonymous
0 Likes
Message 7 of 12

mizrachi_amir2
Advocate
Advocate
Hi,

Actually I am not looking for this kind of interaction. Only need an option, for instance, to take measurements in my model while my plugin in open.
0 Likes
Message 8 of 12

Niko_Davydov
Advocate
Advocate

then the answer from @nice3point  is what you need. Just work with MVVM

Best regards,

Nikolai Davydov

Message 9 of 12

Niko_Davydov
Advocate
Advocate

sorry, i answer from another account. @nd8G4SB ist also my account

0 Likes
Message 10 of 12

mizrachi_amir2
Advocate
Advocate

thanks @nice3point . Will take a look at your solution!

0 Likes
Message 11 of 12

mizrachi_amir2
Advocate
Advocate

thanks @nice3point . Will take a look at your solution.

0 Likes
Message 12 of 12

mizrachi_amir2
Advocate
Advocate
Thanks for this sample app.
Where can I find some instructions on how to convert my already working addin so MVVM design pattern?
0 Likes