How to call UIApplication of my current Document

How to call UIApplication of my current Document

Ali.sadeghi.h1994
Enthusiast Enthusiast
2,243 Views
4 Replies
Message 1 of 5

How to call UIApplication of my current Document

Ali.sadeghi.h1994
Enthusiast
Enthusiast

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...
        }
    }

 

 

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

jeremy_tammik
Alumni
Alumni
Accepted 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.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

moturi.magati.george
Autodesk
Autodesk
Accepted solution

Hi @Ali.sadeghi.h1994,

 

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 George,     Developer Advocacy and Support,  ADN Open
Message 4 of 5

Ali.sadeghi.h1994
Enthusiast
Enthusiast

@moturi.magati.george  thanks for your help. That was a great tutorial in this case and helped me a lot.

0 Likes
Message 5 of 5

Ali.sadeghi.h1994
Enthusiast
Enthusiast

Thanks @jeremy_tammik  .

That worked. Thank you for your guidance. You are great as always.

0 Likes