<?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: Create a custom tab in menu with Cui c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779090#M21947</link>
    <description>&lt;P&gt;awesome resource, thanks for posting this!!&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2024 22:40:34 GMT</pubDate>
    <dc:creator>Scott_FergusonPVMNH</dc:creator>
    <dc:date>2024-05-16T22:40:34Z</dc:date>
    <item>
      <title>Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/8882553#M21945</link>
      <description>&lt;P&gt;Hello, i have created a dll with several different commands to use in Autocad Mechanical 2018, now i would like, instead of have to write every time the command, have a custom tab in the menu where i can use buttons to call the functions i have implemented.&lt;/P&gt;&lt;P&gt;I have already read the documentation about CUI with c#, and followed several tutorials but i can't make appear anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code i use:&lt;/P&gt;&lt;PRE&gt;[CommandMethod("CreateRibbonTabAndPanel")]
        public static void CreateRibbonTabAndPanel_Method()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                CustomizationSection cs = new CustomizationSection((string)Application.GetSystemVariable("MENUNAME"));
                string curWorkspace = (string)Application.GetSystemVariable("WSCURRENT");

                CreateRibbonTabAndPanel(cs, curWorkspace, "ANAW", "AcadNetAddinWizard");
                cs.Save();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(Environment.NewLine + ex.Message);
            }
        }

        public static void CreateRibbonTabAndPanel(CustomizationSection cs, string toWorkspace, string tabName, string panelName)
        {
            RibbonRoot root = cs.MenuGroup.RibbonRoot;
            RibbonPanelSourceCollection panels = root.RibbonPanelSources;

            //Create the ribbon panel source and add it to the ribbon panel source collection
            RibbonPanelSource panelsrc=new RibbonPanelSource(root);
            panelSrc.Text = panelSrc.Name = panelName;
            panelSrc.ElementID = panelSrc.Id = panelName + "_PanelSourceID";
            panels.Add(panelSrc);

            //Create the ribbon tab source and add it to the ribbon tab source collection
            RibbonTabSource tabsrc=new RibbonTabSource(root);
            tabSrc.Name = tabSrc.Text = tabName;
            tabSrc.ElementID = tabSrc.Id = tabName + "_TabSourceID";
            root.RibbonTabSources.Add(tabSrc);

            //Create the ribbon panel source reference and add it to the ribbon panel source reference collection
            RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(tabSrc);
            ribPanelSourceRef.PanelId = panelSrc.ElementID;
            tabSrc.Items.Add(ribPanelSourceRef);

            //Create the workspace ribbon tab source reference
            WSRibbonTabSourceReference tabSrcRef = WSRibbonTabSourceReference.Create(tabSrc);

            //Get the ribbon root of the workspace
            int curWsIndex = cs.Workspaces.IndexOfWorkspaceName(toWorkspace);
            WSRibbonRoot wsRibbonRoot = cs.Workspaces[curWsIndex].WorkspaceRibbonRoot;
            var wsToolbarcollection = cs.Workspaces[curWsIndex].WorkspaceToolbars;

            //Set the owner of the ribbon tab source reference and add it to the workspace ribbon tab collection
            tabSrcRef.SetParent(wsRibbonRoot);
            wsRibbonRoot.WorkspaceTabs.Add(tabSrcRef);
        }&lt;/PRE&gt;&lt;P&gt;This code is from a tutorial, so i dont mind to change it completely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 12:01:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/8882553#M21945</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-01T12:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/8884255#M21946</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bellow have some links that you can follow to take an ideia about how to do this:&lt;/P&gt;&lt;P&gt;1) Generate .cuix file: &lt;A href="https://through-the-interface.typepad.com/through_the_interface/2007/05/creating_a_part.html" target="_blank" rel="noopener"&gt;Creating a partial CUI file using .NET and loading it inside AutoCAD&lt;/A&gt;, by Kean Walmsley;&lt;/P&gt;&lt;P&gt;2) Changing the AutoCAD Ribbon:&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2012/07/modify-ribbon.html" target="_blank" rel="noopener"&gt;Modify Ribbon&lt;/A&gt;, by Adan Nagy;&lt;/P&gt;&lt;P&gt;3) A complete tutorial:&amp;nbsp;&lt;A href="https://spiderinnet1.typepad.com/blog/2012/06/autocad-cui-ribbon-net-create-ribbon-split-buttons-into-ribbon-panel.html" target="_blank" rel="noopener"&gt;AutoCAD CUI Ribbon .NET: Create Ribbon Split Buttons into Ribbon Panel&lt;/A&gt;, by Spiderinnet;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;- - - - - -&amp;nbsp;- - - - - -&amp;nbsp;- - - - - -&amp;nbsp;- - - - - -&amp;nbsp;- - - - - -&amp;nbsp;- - - - - -&lt;/P&gt;&lt;P&gt;These codes bellow contains an example for Custom Menu Generation defined only by objects approach, not generates ".cuix" file, you can test this approach, it's stable:&lt;/P&gt;&lt;PRE&gt;[CommandMethod("CustomMenuGeneration")]
public static void CustomMenuGeneration
{
  RibbonSubPanelSource srcSubPanel = new RibbonSubPanelSource();
  srcSubPanel.Id = "customMenuRibbonSubPanelSource";
  srcSubPanel.Tag = "customMenu RibbonSubPanelSource";
  
  foreach (CustomRibbonToggleButton btn in CustomRibbonToggleButton.GetTabPanelButtons())
  {
    srcSubPanel.Items.Add(btn);
  }
  
  RibbonRowPanel rowPanel = new RibbonRowPanel();
  rowPanel.Id = "customMenuRibbonRowPanel";
  rowPanel.Tag = "customMenu RibbonRowPanel";
  rowPanel.Size = RibbonItemSize.Large;
  rowPanel.Source = srcSubPanel;
  
  RibbonPanelSource srcPanel = new RibbonPanelSource();
  srcPanel.Id = "customMenuRibbonPanelSource";
  srcPanel.Tag = "customMenu RibbonPanelSource";
  srcPanel.Title = "Tag Operations";
  srcPanel.Items.Add(rowPanel);
  
  RibbonPanel Panel = new RibbonPanel();
  Panel.Id = "customMenuRibbonPanel";
  Panel.Source = srcPanel;
  
  RibbonTab Tab = new RibbonTab();
  Tab.Id = "customMenuRibbonTab";
  Tab.Title = "customMenu";
  Tab.Tag = "customMenu RibbonTab";
  Tab.Panels.Add(Panel);
  
  RibbonControl ribbonControl = ComponentManager.Ribbon;
  ribbonControl.Tag = "customMenu RibbonControl";
  ribbonControl.Tabs.Add(Tab);
}&lt;/PRE&gt;&lt;P&gt;The other classes to auxiliar the&amp;nbsp;CustomMenuGeneration Command:&lt;/P&gt;&lt;PRE&gt;public class CustomRibbonToggleButton : RibbonToggleButton
{
  public CustomRibbonToggleButton(string btnText, string description,
      System.Windows.Media.ImageSource image, CommandHandler commandHandler)
  {
    this.Tag = btnText;
    this.Text = btnText;
    this.ShowText = true;
    this.ShowImage = true;
    this.LargeImage = image;
    this.Description = description;
    this.Size = RibbonItemSize.Large;
    this.CommandHandler = commandHandler;
    this.Id = btnText.Replace(" ", "").Replace("-", "");
    this.Orientation = System.Windows.Controls.Orientation.Vertical;
  }
  
  public static IEnumerable&amp;lt;CustomRibbonToggleButton&amp;gt; GetTabPanelButtons()
  {
    yield return new CustomRibbonToggleButton("Button 01",
      "Button 01 - Description",
      ToImageSource(Properties.Resources.BitMap01_32x32),
      new CommandHandler("COMMAND_01"));
    
    yield return new CustomRibbonToggleButton("Button 02",
      "Button 02 - Description",
      ToImageSource(Properties.Resources.BitMap02_32x32),
      new CommandHandler("COMMAND_02"));
    
    yield return new CustomRibbonToggleButton("Button 03",
      "Button 03 - Description",
      ToImageSource(Properties.Resources.BitMap03_32x32),
      new CommandHandler("COMMAND_03"));
  }
  
  public static BitmapImage ToImageSource(Bitmap bitMap)
  {
    BitmapImage bImg = new BitmapImage();
    using (MemoryStream ms = bitMap.GetStreamImage())
    {
       bImg.BeginInit();
       bImg.StreamSource = new MemoryStream(ms.ToArray());
       bImg.EndInit();
    }
    return bImg;
  }
}

public class CommandHandler : System.Windows.Input.ICommand
{
  private readonly string _commandName;
  public CommandHandler(string commandName)
  {
    this._commandName = commandName;
  }
  public event EventHandler CanExecuteChanged;
  public bool CanExecute(object parameter)
  {
    return true;
  }
  public void Execute(object parameter)
  {
    try
    {
       Application.DocumentManager.MdiActiveDocument.Editor.Command(this._commandName);
    }
    catch(Exception ex)
    {
       Application.ShowAlertDialog("Error, message: " + ex.Message);
    }
  }
}&lt;/PRE&gt;&lt;P&gt;If do you want to make the "CustomMenuGeneration" execute on start, you need to configure a PackageContents.xml file with the&amp;nbsp;"CustomMenuGeneration" with S&lt;STRONG&gt;tartupCommand="true"&lt;/STRONG&gt; (&lt;A href="https://knowledge.autodesk.com/support/autocad/getting-started/caas/simplecontent/content/how-to-install-autocad-process-plugins-client-throw-all-network-computers.html" target="_blank" rel="noopener"&gt;vide this article&lt;/A&gt;&amp;nbsp;or &lt;A href="https://forums.autodesk.com/t5/net/does-not-load-dll-in-autocad-in-spanish/m-p/8863153#M63009" target="_blank" rel="noopener"&gt;this solution&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Att,&lt;/P&gt;&lt;P&gt;Antonio Leonardo&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="exam-483-programming-in-c.png" style="width: 125px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/644929i46D8C8A01522EF07/image-size/small?v=v2&amp;amp;px=200" role="button" title="exam-483-programming-in-c.png" alt="exam-483-programming-in-c.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 01:47:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/8884255#M21946</guid>
      <dc:creator>antonio.leonardo</dc:creator>
      <dc:date>2019-07-02T01:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779090#M21947</link>
      <description>&lt;P&gt;awesome resource, thanks for posting this!!&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 22:40:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779090#M21947</guid>
      <dc:creator>Scott_FergusonPVMNH</dc:creator>
      <dc:date>2024-05-16T22:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779092#M21948</link>
      <description>Thanks mate, awesome resource!</description>
      <pubDate>Thu, 16 May 2024 22:41:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779092#M21948</guid>
      <dc:creator>Scott_FergusonPVMNH</dc:creator>
      <dc:date>2024-05-16T22:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779244#M21949</link>
      <description>&lt;P&gt;I'm not sure that&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6990272"&gt;@antonio.leonardo&lt;/a&gt;&amp;nbsp;tested the code he posted, because AFAIK, this will not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Application.DocumentManager.MdiActiveDocument.Editor.Command(this._commandName);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's from the implementation of ICommand.Execute(), which usually runs in the application context, which Editor.Command() cannot be called from.&amp;nbsp; Also, after AutoCAD 2015, Editor.Command() must include all input needed to complete the command, or it will be cancelled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks like a job for SendStringToExecute()&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2024 01:05:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12779244#M21949</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-05-17T01:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create a custom tab in menu with Cui c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12808763#M21950</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;,&lt;BR /&gt;This code works because it's from a real-case,&amp;nbsp;at the time it was developed for plant 3d 2019/2020&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 23:37:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-a-custom-tab-in-menu-with-cui-c/m-p/12808763#M21950</guid>
      <dc:creator>antonio.leonardo</dc:creator>
      <dc:date>2024-05-30T23:37:37Z</dc:date>
    </item>
  </channel>
</rss>

