.NET

.NET

Reply
Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 1 of 5 (316 Views)
Accepted Solution

Commands didn't work if I open file by double click

316 Views, 4 Replies
10-20-2012 10:59 PM

I made my plug-in for Autocad 2012.

I register my plug-in in registry and so it's autoloaded.

 

If I open Autocad I saw my toolbar, my message from IExtensionApplication.Initialize and all my commands (marked as [assembly: CommandClass) works fine. No problem.


BUT! If I open autocad file by double click - autocad opened. Now I saw my toolbar, saw my message from Initialize!
But any commands didn't work. Autocad said that command is unknown. What can be a problem? My be in Autocad version? I have student version and startup message about it.

 

Thanks,

Pavel.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 5 (302 Views)

Re: Commands didn't work if I open file by double click

10-21-2012 07:26 AM in reply to: pva75

This is one of the most frustrating aspects of AutoCAD's managed API. There are quite a few reasons why commands are not registered, but usually it is due to an exception being thrown in IExtensionApplication.Initialize().

 

You should always wrap all of the code in that method inside a try/catch block, and in the latter show a message on the command line or via some other means, to let you know what happened.

Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 3 of 5 (297 Views)

Re: Commands didn't work if I open file by double click

10-21-2012 08:29 AM in reply to: DiningPhilosopher

Dear DiningPhilosopher,

 

You are absolutely right. I had exception in Init because in first case Acad execute RIBBON command before open file, but in second Init was before RIBBON. So no RIBBON in Init and exception in this block.

 

Now all works fine!

 

Thank you!

Pavel.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 5 (272 Views)

Re: Commands didn't work if I open file by double click

10-21-2012 04:13 PM in reply to: pva75

pva75 wrote:

Dear DiningPhilosopher,

 

You are absolutely right. I had exception in Init because in first case Acad execute RIBBON command before open file, but in second Init was before RIBBON. So no RIBBON in Init and exception in this block.

 

Now all works fine!

 

Thank you!

Pavel.


When working with the ribbon, I don't assume that it will appear when AutoCAD starts. The user might not have it visible, and can show it at any time. What I usually do is first check to see if the Ribbon is created using RibbonServices.RibbonPaletteSet. If it is null, the ribbon isn't visible, so I add a handler to the RibbonServices.RibbonPaletteSetCreated event. In the handler of that event, the ribbon has not been initialized yet, so I add another handler to the RibbonPaletteSet's Loaded event, which will fire after the ribbon has been fully initialized.

Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 5 of 5 (213 Views)

Re: Commands didn't work if I open file by double click

10-26-2012 12:20 PM in reply to: DiningPhilosopher

DiningPhilosopher wrote:

When working with the ribbon, I don't assume that it will appear when AutoCAD starts. The user might not have it visible, and can show it at any time. What I usually do is first check to see if the Ribbon is created using RibbonServices.RibbonPaletteSet. If it is null, the ribbon isn't visible, so I add a handler to the RibbonServices.RibbonPaletteSetCreated event. In the handler of that event, the ribbon has not been initialized yet, so I add another handler to the RibbonPaletteSet's Loaded event, which will fire after the ribbon has been fully initialized.



Sorry, but I can't find RibbonServices class and events.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.