Hi everyone. I defined a command class that considers Execute method and some other defined methods by me to call in Execute method or other classes. I tend to call my method with name of " LoadFamily" and its first parameter is UIApplication of my command class. The point is that I don't know how should I call that parameter when I'm in a form button.(In other word, how should I call the UIApplication of my command class somewhere out of command class?) .see the codes below.
// my button in my Form
private void btn1_Click(object sender, EventArgs e)
{
AddFamilies addFamilies1 = new AddFamilies();
addFamilies1.LoadFamily(--!!???????!!--,@"E:\","HazardSign");
}
below is my method in command class
//My command class
public class AddFamilies : IExternalCommand
{
public Document MyDoc;
public UIApplication MyApplication;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
using (System.Windows.Forms.Form form = new LoadFamilies(doc))
{
if (form.ShowDialog() == DialogResult.OK)
{
return Result.Succeeded;
}
else
{
return Result.Cancelled;
}
}
return Result.Succeeded;
}
public void LoadFamily(UIApplication uiApplication, string FamiliesAddress, string FamilyName)
{
Document document = uiApplication.ActiveUIDocument.Document;
Application application = uiApplication.Application;
...codes...
}
}
Solved! Go to Solution.
Solved by moturi.magati.george. Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Make the UIApplication instance a member variable of your form class. Store the value you receive in the constructor in the member variable. Use it in the button click handler method.
Here is a tutorial that explains step by step on creating WPF forms and calling methods outside your command class. https://www.youtube.com/watch?v=vHsqxRAqQOg
@moturi.magati.george thanks for your help. That was a great tutorial in this case and helped me a lot.
Thanks @jeremy_tammik .
That worked. Thank you for your guidance. You are great as always.
Can't find what you're looking for? Ask the community or share your knowledge.