Form in application

Form in application

Anonymous
Not applicable
635 Views
4 Replies
Message 1 of 5

Form in application

Anonymous
Not applicable

I am new at Revit API (and I don't know english very well), so I don`t know if the words that I use are correct. But...

 

I have a class (in Transaction.Mode) and a form.
When I press a button in the form my code catch points written in the form and put beams in its place (I am using delegate to do this). The problem is that it's not working. There`s no errors when I execute the code, but the beams are not being placed. Below there is a summary of the code.
Can anyone help me? Besides I have searched about calling forms in applications and the best solution was use 'delegate'. Is there another solution? 

 

 

[Transaction(TransactionMode.Manual)]
public class Estrutura : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
Autodesk.Revit.DB.View view = doc.ActiveView;
Autodesk.Revit.ApplicationServices.Application application = doc.Application;


var dados = new RevitAddin1.Form2();


dados.Show();


dados.button3.Click += delegate
{

double[][] matriz = dados.AtribuiValores(); //It's the method used to catch the points.

. //I hid this part of the code to let it cleaner.
.
.
.
.

instance = doc.Create.NewFamilyInstance(line, gotSymbol, l, StructuralType.Beam);

dados.Close();
};


\\I have already tried to place the beams with another Transaction, but the code stops in dados.Close();


using (Transaction tx = new Transaction(doc, "Viga"))

{
tx.Start("v");
foreach (Line linha in lista)
{
instance = doc.Create.NewFamilyInstance(linha, gotSymbol, l, StructuralType.Beam);

}
tx.Commit();

}


return Result.Succeeded;
}
}

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

augusto.goncalves
Alumni
Alumni
When you open a form inside a command, you cannot move the button handle to a different location (unless you really need)

Try something like: change your OK button to DialogResult.OK, then use like

if (dados.Show()==OK)
{
/// add your family instances here
}

And avoid that delegate...
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 5

arnostlobel
Alumni
Alumni
Accepted solution

Hello carolinalm:

 

The problem is more severe than it appears. THe most important information for you at this moment is that You may not call directly to the Revit API from a form that you invoked using the Form.Show method. It is because such dialog then is modeless and operates on a different thread than the external command Revit called. Revit does not allow calling to the API from threads other than the main thread. There is a solution to this problem, however, even though I am not sure if it is really what you need. Please search the SDK samples and look for the two samples documenting a ModelessDIalog. Two possible approaches to use when calling from a modeless dialog are illustrated in the two examples.

 

However, if you do not need a the dialog to be modeless, then use the Form.ShowDialog method. It shows the form as a modal dialog (executing on the main thread), and calling from that to the API is fine.

Arnošt Löbel
Message 4 of 5

augusto.goncalves
Alumni
Alumni
Nice catch Arnost! Indeed if is a modeless dialog, then it's a different deal...
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 5 of 5

Anonymous
Not applicable

Thank you Arnost and Augusto. 

I will try to understand this Modeless Dialog... I believe this is what I need.

0 Likes