• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Contributor
    Posts: 48
    Registered: ‎07-22-2012
    Accepted Solution

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

    257 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.

    Please use plain text.
    Valued Mentor
    Posts: 310
    Registered: ‎05-06-2012

    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.

    Please use plain text.
    Active Contributor
    Posts: 48
    Registered: ‎07-22-2012

    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.

    Please use plain text.
    Valued Mentor
    Posts: 310
    Registered: ‎05-06-2012

    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.

    Please use plain text.
    Active Contributor
    Posts: 48
    Registered: ‎07-22-2012

    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.

    Please use plain text.