Transfer data to ExternalEvent

Transfer data to ExternalEvent

Extraneous
Advisor Advisor
886 Views
1 Reply
Message 1 of 2

Transfer data to ExternalEvent

Extraneous
Advisor
Advisor

Hi everyone.

I learn an ExternalEvent mechanism by this page. Everything ok, event is work succesfully.

 

But I want to transfer data in my event. For example, I want to crop 3dview by element after click row in table on form. I want to transfer ElementId in my event, but Raise() method have no arguments.

 

I solved a problem with public static class: save data to static class in form, and get data from static class in event. 

But it is not beautiful, I think it must be another way. Please help.

 

 

 

public static class StaticSelection
{
  public static List<ElementId> Ids;
  public static string DocTitle = "";
  public static double CropSize = 10;
}
private void dataGrid_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
...
  StaticSelection.Ids = selectedIds;
  StaticSelection.DocTitle = "Document.rvt";
  StaticSelection.CropSize = trackBarCropZise.Value;
  m_ExEvent.Raise();
}

public class MyEvent : IExternalEventHandler
{
  void IExternalEventHandler.Execute(UIApplication app)
  {
    Document doc = app.ActiveUIDocument.Document;
    List<ElementId> ids = StaticSelection.Ids;
    app.ActiveUIDocument.Selection.SetElementIds(StaticSelection.Ids);
  }
...
}

 

 

 

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

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

GonçaloFeio1321
Enthusiast
Enthusiast
Accepted solution

Your StaticSelection class  does not need to be static, only its members. static classes are usually for extensions.

Those members in your StaticSelection should be on your MyEvent, or at least you should be able to pass them. In the example code next I used a property, but you can use a method instead.

 

 

 

    public class MyUI
    {
        ExternalEvent m_ExEvent;
        private MyEvent myEvent;
        private List<ElementId> selectedIds;

        public void OnowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            myEvent.Ids = selectedIds
m_ExEvent.Raise(); } } public class MyEvent : IExternalEventHandler { public List<ElementId> Ids { get; set; } void IExternalEventHandler.Execute(UIApplication app) { //check for ids == null ? app.ActiveUIDocument.Selection.SetElementIds(ids); } }

 

 

And, you can remove the LinkedIn link from your signature and get ready to very soon remove facebook one 😄