Call the m_ExEvent.Raise() from another class

Call the m_ExEvent.Raise() from another class

Anonymous
Not applicable
507 Views
1 Reply
Message 1 of 2

Call the m_ExEvent.Raise() from another class

Anonymous
Not applicable

I'm working on a family-browser project. I have written a code where I'm binding the family property with the UI. I've used the  Modeless dialog but I don't want to raise  m_exEvent.Raise() in any event, instead, I want to run the m_exEvent.Raise() from an external class.

 

Here's how I'm currently calling the m_exEvent.Raise() method but when I run the script it does not run the Execute() method that is associated with the Raise(), instead, it skips the method and starts the program from next line of code. Please help, how I can run the m_exEvent.Raise() successfully from another class. Thank you.

 

 

    public class DirectoryItemViewModel 
    {
        

        public ObservableCollection<FamilyType> _subfamilies;
        public ObservableCollection<FamilyType> SubFamilies
        {
            get
            {
                if (_subfamilies != null) return _subfamilies;


                if (Type == DirectoryItemType.File)
                {
                    //Here's how I'm calling the Raise() 
                    UserControls.DefaultControl.Instance.Execute();
                }


                return SubFamilies;
            }
            set
            {
                if (_subfamilies == null)
                {
                    _subfamilies = value;
                    //OnPropertyChanged("SubFamilies");

                }
            }
        }


    }


    public partial class DefaultControl : UserControl
    {
        public static DefaultControl Instance = null;

        public ExternalEvent m_ExEvent;
        public ExternalRevitFileSelecter m_Handler;

        public DefaultControl(ExternalEvent exEvent, ExternalRevitFileSelecter handler)
        {
            Instance = this;
            InitializeComponent();
            this.DataContext = new DirectoryStructureViewModel();

            this.m_ExEvent = exEvent;
            this.m_Handler = handler;
        }


        public void Execute()
        {
            m_ExEvent.Raise();
        }
       

     }

 

0 Likes
Accepted solutions (1)
508 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor
Accepted solution

Can't see how you have registered the event. Typically you should register the event during OnStartup and assign it to a static variable within the class Implementing OnStartUp. If this static variable is public then it can be raised from anywhere (any other class), so I don't understand the requirement to pass the variable around from class to class?

 

Note also that when you raise the event in some situations Revit will not be in a state to execute it i.e. the raise method will return a status to check:

 

ExternalEventRequest.Accepted
ExternalEventRequest.Pending
ExternalEventRequest.Denied
ExternalEventRequest.TimedOut

 

The enum above has xml attached to describe each state. Raising an external event is asynchronous it will not block continuation of your code raising the event it just requests that something be done as soon as Revit can.