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: 

ShowDialog WPF

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
BrentBurgess1980
2510 Views, 4 Replies

ShowDialog WPF

Hi all,

 

I am writing my first Revit addin after years of doing AutoCAD.

 

Is there an equivalent of Application.ShowDialog() in Revit? All I can do so far is 

frmMyWjndow window = new frmMyWindow;

Window.ShowDialog();

 

Which still allows the user to access the model (which I don't want), but also loses focus after task dialogs are shown.

 

I apologise if this has been answered, still finding my feet with Revit.

 

Thanks,

 

Brent

 

 

 

 

 

 

 

 

 

 

4 REPLIES 4
Message 2 of 5

Window should be modal if it is shown that way from IExternalCommand context.

 

How are you showing this window in order that you can still interact with Revit and get TaskDialogs pushing it out of focus? i.e. you should be implementing IExternalCommand, IExternalApplication or IExternalDBApplication. You can't access Revit via it's API from outside of Revit unless you are using Forge to do so (where Revit runs in Forge).

 

 

Message 3 of 5

I made a tutorial on how to make modeless WPF. Tutorial. 

Message 4 of 5

@RPTHOMAS108 My apologies. I probably should have pasted the code to show what I have done. I posted late at night.

public class RebarMarking : IExternalCommand
        {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
            if (Reinforcement.RebarColList != null)
                Reinforcement.RebarColList.Clear();

            Dialogs.RebarMarking rmDialog = new Dialogs.RebarMarking(commandData);
            
            rmDialog.ShowDialog();

            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
    
            return Result.Succeeded;
            }
        }
Message 5 of 5

That looks ok, where is the Taskdialog you mentioned showing from?

 

Essentially the design pattern I use for modal windows/forms is:

Show the window modal (ShowDialog) this window would be sparse of code essentially just containing controls for data binding of options etc. Whilst this window is showing you should not be able to access Revit (as a user) and would not show TaskDialogs whilst your addin window is showing.

After closing the window you read the control values from it to run your routine calling API members

After that finishes you return status as you have done (end of IExternalCommand Context).

You can reshow modal windows within the context but should close them when calling API members.

 

So I don't see anything wrong with what you've done except perhaps you may be trying to interact with Revit within the window code behind rather than after you hide the window or before you show it modal? 

 

In principle you should avoid putting API code into window code behind as separation from UI will make it easier to convert to Forge in the future (where you can't show UI).

 

Often the only code I have in window code behind is handler for ok button that sets a OkPressed boolean to true and closes the window. I check this OKPressed from outside the window after it closes to check if I continue or not i.e. any other form of closing the window (X button/escape etc.) should Return Result.Cancelled from the IExternalCommand.

 

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

Post to forums  

Forma Design Contest


Rail Community