Removing buttons from QuickAccessToolbar crashes AutoCAD

<?xml encoding=”UTF-8″>By Balaji Ramamoorthy

If you are adding ribbon buttons to the AutoCAD QuickAccessToobar (QAT), please ensure that you have provided a unique Id to the ribbon button. If the ribbon button is not provided an Id, AutoCAD can crash when hiding / removing any other standard QAT button.

Here is a code snippet :

 Autodesk.Windows.ToolBars.<span>QuickAccessToolBarSource</span><span>  qat </span>
     = Autodesk.Windows.<span>ComponentManager</span><span> .QuickAccessToolBar;</span>
 
 <span>if</span><span>  (qat != <span>null</span><span> )</span></span>
 <span>{</span>
     <span>RibbonButton</span><span>  rbButton = <span>new</span><span>  <span>RibbonButton</span><span> ();</span></span></span>
 
     <span>// Important to provide a unique id</span><span> </span>
     <span>// to avoid the crash</span><span> </span>
     rbButton.Id = <span>"MYBUTTON"</span><span> ;</span>
 
     rbButton.Text = <span>"Circle"</span><span> ;</span>
     rbButton.Description = <span>"Circle"</span><span> ;</span>
 
     rbButton.Image = GetIcon(<span>"Circle_16.ico"</span><span> );</span>
     rbButton.LargeImage = GetIcon(<span>"Circle_32.ico"</span><span> );</span>
 
     <span>// Attach the handler to fire out command</span><span> </span>
     rbButton.CommandHandler
         = <span>new</span><span>  <span>AutoCADCommandHandler</span><span> (<span>"_.Circle"</span><span> );</span></span></span>
 
     <span>// Add it to the Quick Access Toolbar</span><span> </span>
     qat.AddStandardItem(rbButton);
 <span>}</span>
 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading