.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plugin with custom ribbon on startup (works with netload, but not otherwise)

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
andrew_demerchant
1807 Views, 5 Replies

Plugin with custom ribbon on startup (works with netload, but not otherwise)

I've got a plugin that I made using VB.NET, and it's got a custom ribbon tab. Everything works fine when debugging, and also when I load the plugin using netload. When I try to load the plugin automatically though, it doesn't seem to be adding the ribbon tab (my commands work fine though, so the plugin is definitely loading). I'm trying to load it via the registry, for what it's worth...for my environment, that's the best way.

 

I'm guessing it's not able to run the init function because there's no ribbon object yet. I've looked at some forum posts and it seems the solution is to check Autodesk.Windows.ComponentManager.ItemInitialized and use a handler....the problem is that all the exmaples are in C#. I translated them to the best of my abaility, and things are compiling just fine, but I'm still not seeing the ribbon tab.

 

Here's some of my code:

        Public Sub Initialize() Implements IExtensionApplication.Initialize

            If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then
                AddHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized
            Else
                MyRibbon()
            End If
        End Sub

        Public Sub ComponentManager_ItemInitialized(sender As Object, e As RibbonItemEventArgs)
            If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then
                'create Ribbon
                MyRibbon()

                'and remove the event handler
                RemoveHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized
            End If
        End Sub

 

5 REPLIES 5
Message 2 of 6

Perhaps I am way off course here but I added a ribbon as well in my application. In order for my ribbon to always be available, I had to create a partial CUI menu. Like so:

 

partialCui.png

 

My menu is "LayoutCreator" and I added a couple commands to it. Is this what you're looking for?

 

Message 3 of 6

Turns out that all that was wrong was a stupid typo!!

In "ComponentManager_ItemInitialized", I had:
If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then

Which should have been the opposite:
If Autodesk.Windows.ComponentManager.Ribbon IsNot Nothing Then

Definitely don't need a cui to get a ribbon....I've now got mine working fine, and autoloading using the registry (which lets me have the plugin in a common location).
Message 4 of 6

Possibly what Alex was referring to was creating a partial CUI and adding it to the Autoloader.  I switched over to doing it that way as it makes it easier to create the finished product.  I just create my commands and then using a partial cui add the commands to a ribbon.

Message 5 of 6

Maybe - but like I said, for me, the registry method's the way to go....much easier for me to distribute and manage the plugin that way. Thanks for the help from both of you, though!
Message 6 of 6

This fix worked like a champ for me.  If anyone is interested in the C# equivalent, see below.

 

public class Initialization : IExtensionApplication
    {
        void IExtensionApplication.Initialize()
        {
            if (Autodesk.Windows.ComponentManager.Ribbon == null)
                Autodesk.Windows.ComponentManager.ItemInitialized += ComponentManager_ItemInitialized;
            else
                LoadRibbon();
        }

        private void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
        {
            if (Autodesk.Windows.ComponentManager.Ribbon != null) {
                //Create Ribbon
                LoadRibbon();

                Autodesk.Windows.ComponentManager.ItemInitialized -= ComponentManager_ItemInitialized;
            }
        }

        void IExtensionApplication.Terminate()
        {

        }
    }

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost