Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to call UIApplication of my current Document

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Ali.sadeghi.h1994
853 Views, 4 Replies

How to call UIApplication of my current Document

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

 

 

4 REPLIES 4
Message 2 of 5

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

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

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

Message 5 of 5

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.

Post to forums  

Rail Community


Autodesk Design & Make Report