I have some kind of application that have local command energo and it have IExtensionApplication method to call method
that creates Ribbon for application
Now, I created my directory bundle for autoloader and if I start AutoCAD and then copy my directory to AuplicationPlugins directory it runs perfectly and correct. Then, if I restart autocad, my ribbon tab is not showing, if i type energo it's says unknown command
What am I doing wrong?
And yes, APPAUTOLOAD sys variable is set to 14
Solved! Go to Solution.
Solved by augusto.goncalves. Go to Solution.
Hi,
Are you trying to modify the ribbon during Initialize method? If so, that may not be possible as the ribbon is not yet available for modifications....the suggestion could be register for an event, then create the ribbon later.
>>>>
public void Initialize()
{
if (Autodesk.Windows.ComponentManager.Ribbon == null)
{
//load the custom Ribbon on startup, but at this point
//the Ribbon control is not available, so register for
//an event and wait
Autodesk.Windows.ComponentManager.ItemInitialized +=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
else
{
//the assembly was loaded using NETLOAD, so the ribbon
//is available and we just create the ribbon
createRibbon();
}
}
<<<<
Regards,
Augusto Goncalves
Autodesk Developer Network
You where right about ribbon inicialization BUT for some unknown reason autocad is invoking several times method "
public void Initialize()" from IExtensionApp interface. I dont know how is this posible but when I ran your code, my ribbon tab was created like 10 times.
Because of that I added this line of code
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e) { if (ComponentManager.Ribbon.FindTab("idEnergometan") == null) Pocetna.MojRibbon(); }
Hi,
Yes, this is correct...I forgot the second half of the solution: remove the event handler after the ribbon is created 🙂
>>>>
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
//now one Ribbon item is initialized, but the Ribbon control
//may not be available yet, so check if before
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
//ok, create Ribbon
createRibbon();
//and remove the event handler
Autodesk.Windows.ComponentManager.ItemInitialized -=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
}
<<<<
Regards,
Augusto Goncalves
Autodesk Developer Network
Thank you for this
But, can you explain why Ribbon object is more times initialized
ItemInitialized event is called multiple times for each ribbon item created (so it is not ribbon event, rather ribbon item initialization event)... if you have 10 ribbon tabs in your ACAD, there will be 10 calls to your handler. That's why it is so important to catch just the first one and remove event handler, as at that point you have a valid RibbonControl.