Comunication between WindowsForm and Revit Add-In

Comunication between WindowsForm and Revit Add-In

jjesusdelpino
Advocate Advocate
627 Views
4 Replies
Message 1 of 5

Comunication between WindowsForm and Revit Add-In

jjesusdelpino
Advocate
Advocate

Hi there. I have some troubles comunicating between my form and Revit Add-In. What Im trying to do is closing the form without raising a Revit error. It works properly if I cancel the form or if the plugins runs completely, but I want to consider scenarios when I cancel the plugin based on some previous conditions that the document has to meet.

 

This is what I have in MiForm.cs:

duda1 revit api.jpg

 

And this is what I have in command.cs:

duda2 revit api.jpg

 

Any tips about how to proceed or what am I missing? Thanks!

 

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

Moustafa_K
Collaborator
Collaborator

a quick thought,

can you validate the document before starting to initialize the winform.

somethinglike:

If(myapp is not supposed to run) then TaskDialog

else (start my winform)

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 5

jjesusdelpino
Advocate
Advocate

Seems like a good approach to the problem. In fact it works, I can do the validation and it works properly. But the thing now is. In the form I use addtional info that I get in the validation method.

 

What I do is, I validate a view, and if its ok, retrieves a class validation which is composed by (bool, the view, other parameters). If I take this method to command.cs then I have to pass all these parameters to the form when creating it (i´m not a programmer but it doesn´t seem very clean to me), or recall to this method again, eg, make the validation again which also dont seem to be best way to do this.

 

duda3 revit api.jpg

 

Thanks you so much for your anwser. Regards.

0 Likes
Message 4 of 5

Moustafa_K
Collaborator
Collaborator

but generally why do you need to revalidate after you open the winform??!!

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 5 of 5

jjesusdelpino
Advocate
Advocate
Accepted solution

This was cause in the validation process I dont only check if the document is ok. But also got some parameters from the document. (eg. check if a view exist, and also get that view). I managed to solve this like this:

 

FORM.CS

public class ProcesoValidacion
{
public Document doc;
public bool validez;
public int parámetro1;
public int parámetro2;
public int parámetro3;

public ProcesoValidacion(Document doc)
{
//CODE: "this.validez = false, this.parametro1 = 88", etc.

}

public bool getValidez()
{
return validez;
}
public int getParametro1()
{
return Parametro1;
}
public int getParametro2()
{
return Parametro2;
}

public int getParametro3()
{
return Parametro3;
}

}


And then COMMAND.CS:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

using (MiForm Form = new MiForm(commandData))
{
MiForm.ProcesoValidacion ProcesoInicio = new MiForm.ProcesoValidacion(doc);
if (ProcesoInicio.getValidez() == true)
{
Form.ShowDialog();

if (Form.DialogResult == System.Windows.Forms.DialogResult.Cancel)
{
return Result.Cancelled;
}
}
else
{
return Result.Cancelled;
}
}
return Result.Succeeded;
}


Then I can handle cancelations directly in command.cs and not in form.cs.

 

Thanks for your help. Regards.

0 Likes