.NET

Reply
Valued Contributor
61 Posts
2 Kudos
Registered: ‎04-14-2010
Post 1 of 6
Accepted Solution

Autoloader problem

682 Views, 5 Replies
07-07-2011 04:28 AM

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

Hi,

 

Yes, this is correct...I forgot the second half of the solution: remove the event handler after the ribbon is created :smileyhappy:

 

>>>>

        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

ADN Support Specialist
390 Posts
46 Kudos
Registered: ‎04-30-2009
Post 2 of 6

Re: Autoloader problem

07-07-2011 07:30 AM in reply to: kob4lt

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

Regards,



Augusto Goncalves
Autodesk Developer Network
Valued Contributor
61 Posts
2 Kudos
Registered: ‎04-14-2010
Post 3 of 6

Re: Autoloader problem

07-07-2011 09:46 AM in reply to: augusto.goncalves

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();
        }

 

 

 

ADN Support Specialist
390 Posts
46 Kudos
Registered: ‎04-30-2009
Post 4 of 6

Re: Autoloader problem

07-07-2011 10:17 AM in reply to: kob4lt

Hi,

 

Yes, this is correct...I forgot the second half of the solution: remove the event handler after the ribbon is created :smileyhappy:

 

>>>>

        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

Regards,



Augusto Goncalves
Autodesk Developer Network
Valued Contributor
61 Posts
2 Kudos
Registered: ‎04-14-2010
Post 5 of 6

Re: Autoloader problem

07-07-2011 10:54 AM in reply to: augusto.goncalves

Thank you for this

 

But, can you explain why Ribbon object is more times initialized

New Member
2 Posts
0 Kudos
Registered: ‎07-18-2011
Post 6 of 6

Re: Autoloader problem

07-18-2011 02:28 PM in reply to: kob4lt

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!