Unable to add Ribbon by AutoCAD startup

Unable to add Ribbon by AutoCAD startup

kite15
Advocate Advocate
635 Views
2 Replies
Message 1 of 3

Unable to add Ribbon by AutoCAD startup

kite15
Advocate
Advocate

Hi,

I have tried to create the Ribbon by AutoCAD startup. Previously, was created a CUIX file and enter CUIX detail to load through the xml. Now, trying to create a Ribbon dynamically through stratup while its chosen by the user to load.

Issue is: While, executing the netload command its works as expected. However, its not working by startup (by xml).

 

Here is my code for your reference.. Please, help...

Xml file content

 

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage SchemaVersion="1.0" AutodeskProduct="AutoCAD" ProductType="Addins" Name="NewCADTools" AppVersion="0.0.0" 
                    Description="NewCADTools" Author="Kite15" 
                    AppNameSpace="a" 
ProductCode="{95891FA5-7CD2-495E-A68D-138FF2475085}" UpgradeCode="{88989D32-522F-440F-85D8-0EB7EFD0BAD4}">
  <Components>
    <RuntimeRequirements OS="Win64" Platform="AutoCAD*" SeriesMin="R24.2" SeriesMax="R24.2" />
    <ComponentEntry AppName="NewAutoCADTestTool" Version="1.0.0" ModuleName="./Contents/2023/NewAutoCADRibbon.dll" AppDescription="test." LoadOnAutoCADStartup="True">
	</ComponentEntry>
  </Components>
  
</ApplicationPackage>

Extension Application initialization code:

 

		 public class NewAutoCADlugin : IExtensionApplication
        {
            void IExtensionApplication.Initialize()
            {
                try
                {
                    
                    #region Adding new toolButtons
                    NewAutoCADTools addAutoCADToolButton = new NewAutoCADTools();
                    addAutoCADToolButton.CreateRibbon();
                    #endregion
                }
                catch (System.Exception ex)
                {
                    var error=ex.Message;
                }
            }

            void IExtensionApplication.Terminate()
            {
                // Do plug-in application clean up here if required
                // throw new NotImplementedException();
            }
        }

 

Code for Ribbon creation:

 

 public void CreateRibbon()
        {
            RibbonControl ribbon = ComponentManager.Ribbon;
            if (ribbon != null)
            {
                RibbonTab rtab = ribbon.FindTab(RibbonTabName);
                if (rtab != null)
                {
                    ribbon.Tabs.Remove(rtab);
                }
                rtab = new RibbonTab();
                rtab.Title = RibbonTabTitle;
                rtab.Id = RibbonTabId;
                //Add the Tab
                AddRibbonPanelContent(rtab);
            }
        }

 

0 Likes
Accepted solutions (1)
636 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

That is because when your DLL is loaded automatically, AutoCAD may not has finished its ribbon system loading. That is, in your code, the ComponentManager.Ribbon property is still null, thus, nothing loaded.

 

The better approach would be that you add Application.Idle event handler in the Initialize(), and move your code in the Initialize() to the Applicaion_Idle handler. (Of course, once your code in Idle event handler is called, you then remove the Idle event handler).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

kite15
Advocate
Advocate

Thank you its works ... 

0 Likes