<?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: Pass parameter value from Application to Command in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12847070#M4665</link>
    <description>&lt;P&gt;So glad you made it.... thanks for confirmation &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added that part &lt;A href="https://sharpbim.hashnode.dev/what-command-is-executed" target="_blank" rel="noopener"&gt;to my blog&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jun 2024 15:49:04 GMT</pubDate>
    <dc:creator>Moustafa_K</dc:creator>
    <dc:date>2024-06-18T15:49:04Z</dc:date>
    <item>
      <title>Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12843905#M4657</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if it is possible to set values within a button creation, and pass it onto an external command.&lt;BR /&gt;I have several buttons where each suppose to filter elements according to a specific parameter value.. however i dont want to create repetitive commands just to differentiate a single parameter value.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 10:59:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12843905#M4657</guid>
      <dc:creator>lrsmns</dc:creator>
      <dc:date>2024-06-17T10:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12843969#M4658</link>
      <description>&lt;P&gt;there could be several ways to resolve this: out of my head&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create and Read a json file that has all the settings you need and you may update on each time you initiate a IExternalCommand&lt;/LI&gt;&lt;LI&gt;store your settings i the &lt;A href="https://learn.microsoft.com/en-us/visualstudio/ide/managing-application-settings-dotnet?view=vs-2022" target="_blank" rel="noopener"&gt;Project settings&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;have a static class, name it global or something, that you can access it and store the info you need&lt;/LI&gt;&lt;LI&gt;instantiate a static object of IExternalApplication, and access the variables you need.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class Application : IExternalApplication
{
    internal static Application Instance;
    protected Application()
    {
        Instance = this;
    }

... the rest of the class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;possibly many more ways, but all depends how your data type is structured to select the best method it fits your needs&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 11:42:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12843969#M4658</guid>
      <dc:creator>Moustafa_K</dc:creator>
      <dc:date>2024-06-17T11:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844789#M4659</link>
      <description>&lt;P&gt;Let's say i'm trying to create several buttons for different categories and it supposed to filter the values of the category:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var filterPullDown = PullDownButtonUtilities.AddPulldownButton(app, TabName, filterElementName, "Filter", "Filter by Category", "Filter.png");

List&amp;lt;string&amp;gt; Kategorien = new List&amp;lt;string&amp;gt;
{
    "heating", "lighting", "sanitary"
};

foreach (string kategorie in Kategorien)
{

   PullDownButtonUtilities.AddPushButton(filterPullDown, kategorie, "MyPlugIn.Revit.FilterByCategoryCmd");
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where this is my PullDownButton Utility:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public static class PullDownButtonUtilities
 {
     public static PulldownButton AddPulldownButton(UIControlledApplication app, string tabName, string panelName, string pulldownButtonName, string pulldownButtonText, string iconPath = null)
     {
         RibbonPanel panel = app.CreateRibbonPanel(tabName, panelName);
         PulldownButtonData pulldownButtonData = new PulldownButtonData(pulldownButtonName, pulldownButtonText);
         PulldownButton pulldownButton = panel.AddItem(pulldownButtonData) as PulldownButton;

         if (!string.IsNullOrEmpty(iconPath))
         {
             pulldownButton.LargeImage = ImageUtility.LoadImage(Assembly.GetExecutingAssembly(), iconPath);
         }
         return pulldownButton;
     }

     public static void AddPushButton(PulldownButton pulldownButton, string buttonText, string className)
     {
         var assembly = Assembly.GetExecutingAssembly();
         var path = assembly.Location;
         var buttonData = new PushButtonData(buttonText, buttonText, path, className);
         pulldownButton.AddPushButton(buttonData);
     }
 }  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I pass the category values to my command class so that it can filter elements according to the values set by the buttons?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;  public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  {
      UIApplication uiApp = commandData.Application;
      UIDocument uiDoc = uiApp.ActiveUIDocument;
      Document doc = uiDoc.Document;

      try
      {
          // Get the active view
          View activeView = doc.ActiveView;

          // Collect all elements in the active view with the specified parameter value
          FilteredElementCollector collector = new FilteredElementCollector(doc, activeView.Id);
          IList&amp;lt;Element&amp;gt; elementsInView = collector.WhereElementIsNotElementType()
                                                    .Where(e =&amp;gt; e.LookupParameter("Produktkategorie") != null
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").HasValue
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").AsString() == kategorie)
                                                    .ToList();
          if (elementsInView == null || !elementsInView.Any())
          {
              message = $"No elements found in the active view with the category: {kategorie}";
              TaskDialog.Show("No Elements Found", message);
              return Result.Failed;
          }

          ICollection&amp;lt;ElementId&amp;gt; elementIds = elementsInView.Select(e =&amp;gt; e.Id).ToList();


          // Select elements
          uiDoc.Selection.SetElementIds(elementIds);

          return Result.Succeeded;
      }
      catch (Exception ex)
      {
          message = ex.Message;
          TaskDialog.Show("Error", message);
          return Result.Failed;
      }

  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 17:34:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844789#M4659</guid>
      <dc:creator>lrsmns</dc:creator>
      <dc:date>2024-06-17T17:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844877#M4660</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;oh ok now it is clearer. so you want to catch what is the button name that has executed. I recall i wrote an article about &lt;A href="https://sharpbim.hashnode.dev/what-command-is-executed" target="_blank" rel="noopener"&gt;that over here&lt;/A&gt;&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;for reference you can first register ItemExecuted from the static ComponentManager class, Then from that class you can catch what command text see this example&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;Register this at the startup&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public override Result OnStartup(UIControlledApplication application)
{
    Autodesk.Windows.ComponentManager.ItemExecuted += ComponentManager_ItemExecuted;
}

private void ComponentManager_ItemExecuted(
    object sender,
    Autodesk.Internal.Windows.RibbonItemExecutedEventArgs e
)
{
    // command is from an addin " not a built in Revit command"
    Globals.kategorie = e.Item.Text   // this is the name you used to register the button with
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;then in your command&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;IList&amp;lt;Element&amp;gt; elementsInView = collector.WhereElementIsNotElementType()
                                                    .Where(e =&amp;gt; e.LookupParameter("Produktkategorie") != null
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").HasValue
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").AsString() == Globals.kategorie)
                                                    .ToList();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;this is one of the possible solutions. of course you can also structure how to get or store this Globals static class.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;Apologies this will trigger after the command is executed and not before.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 18:50:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844877#M4660</guid>
      <dc:creator>Moustafa_K</dc:creator>
      <dc:date>2024-06-17T18:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844981#M4661</link>
      <description>&lt;P&gt;I was mistaken above thought it differently. you can catch the name before the command is executed by registering to the ComponentManager.PreviewExecute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the implementation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ComponentManager.PreviewExecute += ComponentManager_PreviewExecute;

private void ComponentManager_PreviewExecute(object sender, EventArgs e)
{
    var ButtonCaller = sender as Autodesk.Windows.RibbonButton;
    //the exucted Category name is the button name
   Globals.kategorie =  command ButtonCaller.Text;
}&lt;/LI-CODE&gt;&lt;P&gt;then form your code you can access this Global class[ a static class where you store static variable] through your command execution&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;IList&amp;lt;Element&amp;gt; elementsInView = collector.WhereElementIsNotElementType()
                                                    .Where(e =&amp;gt; e.LookupParameter("Produktkategorie") != null
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").HasValue
                                                             &amp;amp;&amp;amp; e.LookupParameter("Produktkategorie").AsString() == Globals.kategorie)
                                                    .ToList();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 19:31:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12844981#M4661</guid>
      <dc:creator>Moustafa_K</dc:creator>
      <dc:date>2024-06-17T19:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846271#M4662</link>
      <description>&lt;P&gt;I dont quiet follow with the first code in line 7.. what is Globals and why is it equal command Buttoncaller.Text; ?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 09:13:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846271#M4662</guid>
      <dc:creator>lrsmns</dc:creator>
      <dc:date>2024-06-18T09:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846376#M4663</link>
      <description>&lt;P&gt;Globals can be a static class, where you can place and assign a values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pulic static class Globals{&lt;/P&gt;&lt;P&gt;public static string kategorie;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;i couldn't formate the code style,seems not possible from phone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i did above is registering to a execution preview event, that to catch what button has executed the command. From that catch and store the value of the button.text {the value here is the pushbuttontext you registered in PulldownButtonData(pulldownButtonName, pulldownButtonText) method} in a global static class.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eventually since this is triggered before the IExternalCommand execution, {this is not documented, so this needs to be tested thouroly on different revit versions},&amp;nbsp;you now hold the value of what is triggered and you can use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope i was able to clarify enough.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 17:16:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846376#M4663</guid>
      <dc:creator>Moustafa_K</dc:creator>
      <dc:date>2024-06-18T17:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846700#M4664</link>
      <description>&lt;P&gt;Got it! i've got it working thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 12:56:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12846700#M4664</guid>
      <dc:creator>lrsmns</dc:creator>
      <dc:date>2024-06-18T12:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Pass parameter value from Application to Command</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12847070#M4665</link>
      <description>&lt;P&gt;So glad you made it.... thanks for confirmation &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added that part &lt;A href="https://sharpbim.hashnode.dev/what-command-is-executed" target="_blank" rel="noopener"&gt;to my blog&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2024 15:49:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/pass-parameter-value-from-application-to-command/m-p/12847070#M4665</guid>
      <dc:creator>Moustafa_K</dc:creator>
      <dc:date>2024-06-18T15:49:04Z</dc:date>
    </item>
  </channel>
</rss>

