<?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 Assembly reference in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10309452#M16433</link>
    <description>&lt;P&gt;Hi friends, in &lt;A href="https://adndevblog.typepad.com/autocad/2014/01/how-to-ensure-your-ribbon-runtime-items-remain-visible.html" target="_blank" rel="noopener"&gt;this&lt;/A&gt; post, what assembly reference do I need to get rid of the missing assembly reference issue. I am getting red squiggly lines for Properties and BitmapImage. I tried all the assemblies I could think of, including System.Drawing and System.Windows. Thanks in advance for your help. Following is an image of the issue.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="References.png" style="width: 858px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918203iF43BABAFB3D704A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="References.png" alt="References.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 May 2021 22:56:44 GMT</pubDate>
    <dc:creator>karl.sch1983</dc:creator>
    <dc:date>2021-05-12T22:56:44Z</dc:date>
    <item>
      <title>Assembly reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10309452#M16433</link>
      <description>&lt;P&gt;Hi friends, in &lt;A href="https://adndevblog.typepad.com/autocad/2014/01/how-to-ensure-your-ribbon-runtime-items-remain-visible.html" target="_blank" rel="noopener"&gt;this&lt;/A&gt; post, what assembly reference do I need to get rid of the missing assembly reference issue. I am getting red squiggly lines for Properties and BitmapImage. I tried all the assemblies I could think of, including System.Drawing and System.Windows. Thanks in advance for your help. Following is an image of the issue.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="References.png" style="width: 858px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/918203iF43BABAFB3D704A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="References.png" alt="References.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 22:56:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10309452#M16433</guid>
      <dc:creator>karl.sch1983</dc:creator>
      <dc:date>2021-05-12T22:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Assembly reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10309710#M16434</link>
      <description>&lt;P&gt;Did you copy-pasted the code from outside of the project? it looks like you are doing ribbon stuff, which required references to WPF related system assemblies:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PresentationFramework&lt;/P&gt;
&lt;P&gt;PresentationCore&lt;/P&gt;
&lt;P&gt;System.Xaml&lt;/P&gt;
&lt;P&gt;WindowsBase&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you also need&lt;/P&gt;
&lt;P&gt;acWindows.dll&lt;/P&gt;
&lt;P&gt;adWindows.dll&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have these referenced, simply right click the squiggly "BitmapImage" Visual Stuido should suggests adding&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"using System.Windows.Media.Imageing;" namespace.&lt;/P&gt;
&lt;P&gt;As for "Properties.Resources...", it would only be available if you created Resources in your project: go to "Project-&amp;gt;Properties-&amp;gt;Resources tab" and create needed image resources, in your case, they are a bunch of image files to be read into the resources.&lt;/P&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;</description>
      <pubDate>Thu, 13 May 2021 02:07:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10309710#M16434</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-05-13T02:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Assembly reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311627#M16435</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;, this did the trick. I was able to load the ribbon. A new problem arises. The ribbon keeps loading a new instance every time I call&amp;nbsp;&lt;EM&gt;simplebutton&lt;/EM&gt;. Based on the post that is not the behavior I expected. Following is my code which is exactly from the previously posted link. Can you please check if it does the same for you.&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;using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Windows;
using System.Media;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Diagnostics;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: ExtensionApplication(typeof(ManagedApplication.Initialization))]
[assembly: CommandClass(typeof(ManagedApplication.Commands))]


namespace ManagedApplication
{
    public class Initialization : Autodesk.AutoCAD.Runtime.IExtensionApplication
    {
        public void Initialize()
        {
            Active.Ed.WriteMessage("Initializing - do something useful.");
        }

        public void Terminate()
        {
            Debug.WriteLine("Cleaning up...");
        }
    }

    public class Commands
    {
        [CommandMethod("SimpleButton")]
        public void SimpleButton()
        {
            Autodesk.AutoCAD.ApplicationServices.Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(Application_SystemVariableChanged);
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.CommandEnded += new CommandEventHandler(MdiActiveDocument_CommandEnded);

            CreateSimpleButton();
        }

        void MdiActiveDocument_CommandEnded(object sender, CommandEventArgs e)
        {
            if (e.GlobalCommandName == "QUICKCUI" || e.GlobalCommandName == "CUI")
                Autodesk.AutoCAD.ApplicationServices.Application.Idle += new EventHandler(Application_Idle);
        }

        void Application_Idle(object sender, EventArgs e)
        {
            if (Autodesk.Windows.ComponentManager.Ribbon != null)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.Idle -= new EventHandler(Application_Idle);
                CreateSimpleButton();
            }
        }

        void Application_SystemVariableChanged(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
        {
            if (e.Name == "WSCURRENT")
            {
                string cmdNames = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CMDNAMES");
                if (cmdNames.ToUpper().IndexOf("QUICKCUI") &amp;gt;= 0 || cmdNames.ToUpper().IndexOf("CUI") &amp;gt;= 0)
                    return;

                CreateSimpleButton();
            }
        }

        public void CreateSimpleButton()
        {
            Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
            RibbonTab Tab = new RibbonTab();
            Tab.Title = "Test Ribbon";
            Tab.Id = "TESTRIBBON_TAB_ID";

            ribbonControl.Tabs.Add(Tab);

            Autodesk.Windows.RibbonPanelSource srcPanel = new RibbonPanelSource();
            srcPanel.Title = "Panel1";
            RibbonPanel Panel = new RibbonPanel();
            Panel.Source = srcPanel;
            Tab.Panels.Add(Panel);

            Autodesk.Windows.RibbonButton button1 = new RibbonButton();
            button1.Text = "Button";
            button1.Size = RibbonItemSize.Large;
            button1.Image = getBitmap(EnsureRibbon.Properties.Resources.Apps, 32, 32);
            button1.LargeImage = getBitmap(EnsureRibbon.Properties.Resources.Apps, 32, 32);

            button1.ShowText = true;
            button1.CommandParameter = "._LINE ";
            button1.CommandHandler = new SimpleButtonCmdHandler();

            srcPanel.Items.Add(button1);
            Tab.IsActive = true;
        }

        BitmapImage getBitmap(Bitmap bitmap, int height, int width)
        {
            MemoryStream stream = new MemoryStream();
            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            BitmapImage bmp = new BitmapImage();
            bmp.BeginInit();

            bmp.StreamSource = new MemoryStream(stream.ToArray());
            bmp.DecodePixelHeight = height;
            bmp.DecodePixelWidth = width;
            bmp.EndInit();

            return bmp;
        }

        public class SimpleButtonCmdHandler : System.Windows.Input.ICommand
        {
            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                if (parameter is RibbonButton)
                {
                    string esc = "";
                    string cmds = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CMDNAMES");

                    if (cmds.Length &amp;gt; 0)
                    {
                        int cmdNum = cmds.Split(new char[] { '\'' }).Length;
                        for (int i = 0; i &amp;lt; cmdNum; i++)
                            esc += '\x03';
                    }

                    RibbonButton button = parameter as RibbonButton;
                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                    doc.SendStringToExecute(esc + button.CommandParameter,true, false, false);
                }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can probably move the code to a startup reactor or something and eliminate the multiple command issue. But I am not sure why calling cui loads a new ribbon each time. I will be grateful for any insight. The following &lt;A href="https://autode.sk/3ogGakF" target="_blank" rel="noopener"&gt;screencast&lt;/A&gt; shows the issue.&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 20:43:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311627#M16435</guid>
      <dc:creator>karl.sch1983</dc:creator>
      <dc:date>2021-05-13T20:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assembly reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311721#M16436</link>
      <description>&lt;P&gt;When your ribbon tab building code CreateSimpleButton() method starts run, it should first check if there is a ribbon tab with the same Title and/or Id exist. If yes, the code either no need to go further, or remove it and rebuild a new one.&amp;nbsp; Although each tab in ribbon has a property "Id", but there is no measure in AutoCAD to prevent tabs have duplicated Id. So, your code would look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;public void CreateSimpleButton()&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; var ribbonControl = Autodesk.AutoCAD.Componentanager.Ribbon;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;// loop through all tabs to compare its name, if found, stop ribbon tab building&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; If (FindExistingTab(ribbonControl, "Test Ribbon") return;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; // start building new tab here&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; var tab= new RibbonTab();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ... ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;private bool FindExistingTab(RibbonControl control, string tabName)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ... ....&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 21:27:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311721#M16436</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-05-13T21:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assembly reference</title>
      <link>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311907#M16437</link>
      <description>&lt;P&gt;Thanks! I will give that a shot.&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 23:54:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assembly-reference/m-p/10311907#M16437</guid>
      <dc:creator>karl.sch1983</dc:creator>
      <dc:date>2021-05-13T23:54:35Z</dc:date>
    </item>
  </channel>
</rss>

