Prevent Modeless Multiple Instance

Prevent Modeless Multiple Instance

revitaddins
Contributor Contributor
821 Views
4 Replies
Message 1 of 5

Prevent Modeless Multiple Instance

revitaddins
Contributor
Contributor

Hi All,

 

I'm submitting application to Autodesk app store and one of their comment about my application is it's opening multiple instances every time you click its button. I've search on forums and found out same question here , Jeremy's answer was to change it from "Show" to Showdialog, however i'd like to keep my application as modeless form as much as possible. Is there anyway to do this or do i really need to make it modal form? Thanks in advance.

0 Likes
Accepted solutions (1)
822 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

Yes you track if the window is open or not.

 

If you put the window on a static variable then upon window closed event you set this variable to nothing. When you activate your command you always first check if static variable is not nothing (window already open). If static variable is nothing the window can't already be open so you assign a new instance of the window to the variable and show it.

0 Likes
Message 3 of 5

revitaddins
Contributor
Contributor

Thanks @RPTHOMAS108  would you mind giving an example? Please, Thank you.

0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

 

Slightly different from suggested using Boolean to check if window is open or not: 

public class xx : IExternalCommand
{
	private static LocatePointWindow CoordWind = new LocatePointWindow();
		//Public so can be set to false from Window closed event
	public static bool WindowActive = false;

	public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
	{

		if (WindowActive == false) {
			CoordWind = new LocatePointWindow();
			CoordWind.Show();
			WindowActive = true;
		}

		return Autodesk.Revit.UI.Result.Succeeded;
	}

}

 

Message 5 of 5

revitaddins
Contributor
Contributor

Thank you @RPTHOMAS108  🙂

0 Likes