How to wait for modeless form to finish before running postcommand

How to wait for modeless form to finish before running postcommand

Anonymous
Not applicable
1,982 Views
4 Replies
Message 1 of 5

How to wait for modeless form to finish before running postcommand

Anonymous
Not applicable

So I want to run postcommand twice after the modeless form however i need to tell the postcommand that the modeless form is closed otherwise they open simultaneously. The only method i can think of is to call a child command from my modeless dialog however that uses an external event handler so is that violating the requirement to not call a post command in this situation?

 

 

 

//SHOW MODELESS FORM - Do stuff, close form and then run post command twice
ribbonapp.thisApp.ShowModelessForm(commandData.Application);

 

 

//Subscribe
uiApp.DialogBoxShowing += new EventHandler<DialogBoxShowingEventArgs>(OnDialogShowing);

 

     //Call the post commmand

    uiApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused));

 

//unsubscribe

uiApp.DialogBoxShowing -= new EventHandler<DialogBoxShowingEventArgs>(OnDialogShowing);

 

 

//get the confirmation that the post command dialog has been shown, to call the command twice or thrice...

private void OnDialogShowing(object sender, DialogBoxShowingEventArgs e)
{
bool isConfirm = e.DialogId.Equals("Dialog_Revit_PurgeUnusedTree");

if (isConfirm)
 {
  Dialog_count++;
 }
}

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

Anonymous
Not applicable

Note I have tried dialogresult = ok and it has no affect with the modeless form

 

if (ModelessForm_ExtEventDialog.ActiveForm.DialogResult == System.Windows.Forms.DialogResult.OK)
{

 

//do the post commands here after modeless form has finished working

 

}

0 Likes
Message 3 of 5

jaboone
Advocate
Advocate

Can you put a close button or look for a close event on this form or send a global bool variable for a close switch.  You can put a timer or while to check its state.

Learning as I go
0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution

Why does the form have to be modeless if you want to prevent continued execution until form is closed?

 

Why not use OnClosed event to post command?

 

When I have modeless forms I generally declare them on a static variable and set this to nothing during the OnClosed event. If form is opened by IExternalCommand I check if static variable is nothing and set it to a new form then show it. If variable is not nothing I assume form is already open and exit without showing another one. If you need continued access to the information on the form (can't set it to nothing) then you can achieve the same with a static boolean instead. This prevents form appearing more than once but I don't know if that is your issue here.

Message 5 of 5

Anonymous
Not applicable

Hi Thomas,

I am trying to get this to work however when I put a static boolean variable in the modeless form and it's boolean value never gets swapped to true until after the modeless form is closed and the addin is run again, it seems to remember its boolean value after the addin is run again. 

Further how can i set this "RibbonApp.thisApp.ShowShareForm()" to a static variable as it has no return?

 

 

 

 

 

//Main externalcommand, invokes FORM - Modeless
RibbonApp.thisApp.ShowShareForm(commandData.Application);

 

//in form

protected override void OnFormClosed(FormClosedEventArgs e)
{

            blModelessFormClosed = true;
}

 

 

//then check again, here doesnt work as it hasnt been flagged as true and just opens at the same time

//Main external command
if (SM_ExtEventDialog.blModelessFormClosed == true)
{
TaskDialog.Show("Purge...", "Dialog_count.ToString()");
uiApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused));
}

 

 

 

0 Likes