<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is it possible to obtain objects from event handlers using ref? in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7775322#M52514</link>
    <description>&lt;P&gt;You can only make use of the Revit API methods within a valid Revit API context, i.e., within the event handler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, you need to access, read and store all the required information inside that scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that, you can do anything you like, except making use of the Revit API, e.g., you cannot query Revit for any further data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;jeremy&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2018 20:57:58 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2018-02-13T20:57:58Z</dc:date>
    <item>
      <title>Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7774271#M52513</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the title says, is it possible to obtain objects from event handlers using ref?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use Revit API and WPF in order to extract a list of elements from the model (and for this I'm going to use Revit API) and then import it to WPF. However, as I use external event in order to use Revit API, all the lists and instances that are obtained &lt;STRONG&gt;in the event are not transferred to the main code&lt;/STRONG&gt; (i.e. Window and Button_Click).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is the summary of the code I'm using:&lt;/P&gt;&lt;PRE&gt;//So I'm doing a Window in WPF
public partial class Window1: Window
    {

    //create the External Events which will be read from the previous window
    public ExternalEvent Event;
//create an instance that should be readable throughout the code and that should have the same reference that the one in the EvenHander (list)
    &lt;STRONG&gt;IList&amp;lt;string&amp;gt; list;&lt;/STRONG&gt;


    public ThirdWindow(ExternalEvent exEvent)
    {
        InitializeComponent();
        Event = exEvent;
    }


//button in WPF that will raise the event and use the list
    private void button_Click(object sender, RoutedEventArgs e)
    {

        //call the event
        Event.Raise();
    //and then I want to store in List_button the list I had in the EventHandler
        &lt;STRONG&gt;ref IList&amp;lt;string&amp;gt; List_button = ref list&lt;/STRONG&gt;;

    }


public class EventRegisterHandler_IdentifyMaterialsWithoutSP : IExternalEventHandler
    {

        public bool EventRegistered { get; set; }
        public IList&amp;lt;string&amp;gt; MaterialList_W3 { get; set; }

        public void Execute(UIApplication app)
        {
            UIDocument uiDoc = app.ActiveUIDocument;
            Document doc = app.ActiveUIDocument.Document;

    //in this part I'm calling Class1 in order to use Function1
            Class1 revitFunction = new Class1();
    //Function1 will allow me to store a IList of stuff
            IList&amp;lt;string&amp;gt; List1 = revitFunction.Function1(doc);

    //and I want to be able to have access to this list OUTSIDE the event handler
            &lt;STRONG&gt;ref IList&amp;lt;string&amp;gt; list = ref List1;&lt;/STRONG&gt; 
        }

        public string GetName()
        {
            return "EventRegisterHandler";
        }
    }&lt;/PRE&gt;&lt;P&gt;So, is there a way to extract information out of the event handler? is it possible to extract a IList&amp;lt;&amp;gt; from the event handler and use it in the Window Class?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 15:02:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7774271#M52513</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-13T15:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7775322#M52514</link>
      <description>&lt;P&gt;You can only make use of the Revit API methods within a valid Revit API context, i.e., within the event handler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, you need to access, read and store all the required information inside that scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that, you can do anything you like, except making use of the Revit API, e.g., you cannot query Revit for any further data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;jeremy&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:57:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7775322#M52514</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-13T20:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7777220#M52515</link>
      <description>&lt;P&gt;Thank you jeremy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you think it is possible to extract information out of the event?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case I just want to run Revit API functions within the event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But then I also stored in a List (&lt;STRONG&gt;IList&amp;lt;string&amp;gt; list = List1;)&amp;nbsp;&lt;/STRONG&gt;the information that I want outside the event, which is basically a list of strings that represent the name of elements in the project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there no way to have access to this information outside the handler? Or copy that list to a list outside the handler during the event?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry if I'm asking stupid/obvious questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 14:22:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7777220#M52515</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-14T14:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7778269#M52516</link>
      <description>&lt;P&gt;Sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can store the strings in a ref List.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or a static class variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are .NET basics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please read about, e.g., '.net passing data between classes':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://duckduckgo.com/?q=.net+passing+data+between+classes" target="_blank"&gt;https://duckduckgo.com/?q=.net+passing+data+between+classes&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 19:29:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7778269#M52516</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-14T19:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7780260#M52517</link>
      <description>&lt;P&gt;jeremy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You've literally saved my ***!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not a great C# programmer nor do have a computer background, but I'll just share the solution that worked out for me so others can follow the same steps and adapt to their needs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I just added a class that will store "global parameters" using the 'static' modifier (&lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members" target="_blank"&gt;https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;namespace NamespaceOfYourCode
{
&lt;STRONG&gt;    public class GlobalObjects
    {
        public static string x;
        public static List&amp;lt;string&amp;gt; xList;
        //other global objects you want
    }&lt;/STRONG&gt;

//...

public ThirdWindow(ExternalEvent exEvent)
    {
        InitializeComponent();
        Event = exEvent;
        //raise the event as soon as you open the window
 &lt;STRONG&gt;       Event.Raise();&lt;/STRONG&gt;
    }

//...

public class EventRegisterHandler_IdentifyMaterialsWithoutSP : IExternalEventHandler
    {

        public bool EventRegistered { get; set; }
        public IList&amp;lt;string&amp;gt; MaterialList_W3 { get; set; }

        public void Execute(UIApplication app)
        {
            UIDocument uiDoc = app.ActiveUIDocument;
            Document doc = app.ActiveUIDocument.Document;

    //in this part I'm calling Class1 in order to use Function1
            Class1 revitFunction = new Class1();
    //Function1 will allow me to store a IList of stuff
            IList&amp;lt;string&amp;gt; List1 = revitFunction.Function1(doc);

    //and I want to be able to have access to this list OUTSIDE the event handler
&lt;STRONG&gt;            GlobalObjects.xList=List1;&lt;/STRONG&gt; 
        }

        public string GetName()
        {
            return "EventRegisterHandler";
        }
    }&lt;/PRE&gt;&lt;P&gt;It is important that the &lt;STRONG&gt;event is raised as soon as the window shows up&lt;/STRONG&gt;. As far as I know, when you click a button, and then raise a Revit event, it will only "finish" it when the button event is closed. So, if you only raise the event in the button, the List will be null and only after the button closes the List will have its values. So, raise the event in the main window and then when you need it in the button the List will already have the stuff you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this the best solution? I hardly think so, but it's working for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only thanks to you jeremy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:11:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/7780260#M52517</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-15T13:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to obtain objects from event handlers using ref?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/11161325#M52518</link>
      <description>&lt;P&gt;Hi Rubens1234,&lt;/P&gt;&lt;P&gt;Your code worked for me except you said:&lt;/P&gt;&lt;P&gt;"As far as I know, when you click a button, and then raise a Revit event, it will only "finish" it when the button event is closed."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to close button event&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 09:15:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/is-it-possible-to-obtain-objects-from-event-handlers-using-ref/m-p/11161325#M52518</guid>
      <dc:creator>halukuzuner</dc:creator>
      <dc:date>2022-05-11T09:15:05Z</dc:date>
    </item>
  </channel>
</rss>

