Author Topic: Custom Ribbon* Classes  (Read 4444 times)

0 Members and 1 Guest are viewing this topic.

BlackBox

  • King Gator
  • Posts: 3770
Custom Ribbon* Classes
« on: August 23, 2012, 06:20:51 PM »
Working on a Ribbon task, and am seeking some guidance on a scalable Class structure for my Solution.

The CommandMethods for adding/activating, and removing the RibbonTab are good (thanks to Jeff_M's guidance here!).

I'm specifically seeking to effectively organize my RibbonPanels and RibbonButtons into appropriate Classes, and Methods for creating said components, inheriting the base RibbonPanel, and RIbbonButton Classes, for the purpose of predefining the Custom Panel Buttons, and the Custom Button Properties.

I still get terms mixed up, so if I'm 'speaking' incorrectly, please let me know... I believe that I need a Constructor to Instantiate my custom Objects from the CommandMethod?  :?

In any event, my initial thought is to have an pseudo CustomRibbonPanel : RibbonPanel Class, and CustomRibbonButton : RibbonButton Class, which will have the appropriate Add() Method(s) (perhaps some overloads will be needed per button criteria, etc.?)... I just want to know if I'm on the right path before I go wasting hours (yes, it will probably take me hours!) of my life.

Pointing me towards any relevant posts, tutorials, or tips that I am obviously overlooking would be greatly appreciated.

TIA
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom Ribbon* Classes
« Reply #1 on: August 23, 2012, 06:27:17 PM »
I guess that I should also add that my intention is to (from the CommandMethod), define the RibbonPanelSource once, and supply that an instance of each RibbonPanel (which is in turn supplied specific Custom RibbonButtons as defined elsewhere), such that I end up simply calling <MyRibbonPanelSource>.Items.Add(HelpRibbonPanel()); where HelpRibbonPanel() returns RibbonPanel which has already created (instantiated?) a HelpRibbonButton() that already has all of the 'Help' RibbonButton's Properties set from my CustomRibbonButton : RibbonButton Class (in this case Custom = Help).

Hopefully I am not being redundant, and this all makes sense.  :lol:
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom Ribbon* Classes
« Reply #2 on: August 23, 2012, 06:37:54 PM »
Code to look at is always helpful...

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.EditorInput;
  3. using Autodesk.AutoCAD.Ribbon;
  4. using Autodesk.AutoCAD.Runtime;
  5. using Autodesk.Windows;
  6.  
  7. using System;
  8. using System.Reflection;
  9. using System.Windows.Controls;
  10. using System.Windows.Media.Imaging;
  11.  
  12. [assembly: CommandClass(typeof(FooRibbon.Commands))]
  13.  
  14. namespace FooRibbon
  15. {
  16.     public class Commands
  17.     {
  18.         private Editor ed =
  19.            Application.DocumentManager.MdiActiveDocument.Editor;
  20.        
  21.         [CommandMethod("FooRIbbon")]
  22.         public void FooRibbon()
  23.         {
  24.             try
  25.             {
  26.                 RibbonControl oRibbon = ComponentManager.Ribbon;
  27.                 if (oRibbon != null)
  28.                 {
  29.                     RibbonTab oTab = oRibbon.FindTab("FooTabId");
  30.                     if (oTab != null)
  31.                     {
  32.                         oTab.IsActive = true;
  33.                     }
  34.                     else
  35.                     {
  36.                         oTab = new RibbonTab();
  37.                         oTab.Title = "FOO";
  38.                         oTab.Id = "FOO_RIBBONTAB";
  39.                         oTab.IsVisible = true;
  40.  
  41.                         oRibbon.Tabs.Add(oTab);
  42.  
  43.                         oTab.IsActive = true;
  44.  
  45.                         // <-- Add custom ribbon panel(s) here
  46.  
  47.                     }
  48.                 }
  49.             }
  50.  
  51.             catch (Autodesk.AutoCAD.Runtime.Exception ex)
  52.             {
  53.                 ed.WriteMessage("\n** AutoCAD Error: " + ex.Message + " ** ");
  54.             }
  55.  
  56.             catch (System.Exception ex)
  57.             {
  58.                 ed.WriteMessage("\n** System Error: " + ex.Message + " ** ");
  59.             }
  60.         }
  61.  
  62.     public class HelpRibbonPanel : RibbonPanel
  63.     {
  64.         public static RibbonPanel GetItem()
  65.         {
  66.             // Define HelpRibbonPanel
  67.  
  68.             return HelpRibbonPanel;
  69.         }
  70.     }
  71.  
  72.     // Same sort of thing for HelpRibbonButton
  73. }
  74.  
« Last Edit: August 24, 2012, 11:25:18 AM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom Ribbon* Classes
« Reply #3 on: August 24, 2012, 07:01:15 AM »
I cannot seem to find this... I've already referenced in AcWindows, and AdWindows into my project, but still seem to have a missing reference for AdskCommandHandler... Am I missing a using statement?  :?

Code - C#: [Select]
  1. ribbonButton.CommandHandler = new AdskCommandHandler();
  2.  

** Edit - It must be another reference, as nothing shows up in Object Browser.
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4086
  • C3D user & customizer
Re: Custom Ribbon* Classes
« Reply #4 on: August 24, 2012, 08:59:08 AM »
It is a class you create. This AU2009 class would be good reading/watching/listening to: http://au.autodesk.com/?nd=class&session_id=5044

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom Ribbon* Classes
« Reply #5 on: August 24, 2012, 09:22:40 AM »
It is a class you create. This AU2009 class would be good reading/watching/listening to: http://au.autodesk.com/?nd=class&session_id=5044

Thank you (yet again), Jeff... I'll definitely check out the AU course online this weekend.

After more searching online this morning, I did start to see that others were posting the actual Class:

Code - C#: [Select]
  1. public class AdskCommandHandler
  2.   : System.Windows.Input.ICommand
  3.   {
  4.  
  5.   }
  6.  



If ADN developers aren't going to include such a Class Implementation in the SDK/Installation Libraries, then I don't think that it's too much to ask that they (ADN) specify that AdskCommandHandler is a user-defined Class when used in publicly posted code, as Balaji Ramamoorthy fails to do here:roll:

/vent
"How we think determines what we do, and what we do determines what we get."

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Custom Ribbon* Classes
« Reply #6 on: August 24, 2012, 09:33:05 AM »


If ADN developers aren't going to include such a Class Implementation in the SDK/Installation Libraries, then I don't think that it's too much to ask that they (ADN) specify that AdskCommandHandler is a user-defined Class when used in publicly posted code, as Balaji Ramamoorthy fails to do here:roll:

/vent

Let him know.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4086
  • C3D user & customizer
Re: Custom Ribbon* Classes
« Reply #7 on: August 24, 2012, 09:36:49 AM »
That one example you posted was just a snippet of code. I wouldn't expect any explanation for it here, as it would be assumed you already have some working code. THIS is a better example, and Adam does include everything needed for it to work.

BlackBox

  • King Gator
  • Posts: 3770
Re: Custom Ribbon* Classes
« Reply #8 on: August 24, 2012, 09:42:16 AM »


If ADN developers aren't going to include such a Class Implementation in the SDK/Installation Libraries, then I don't think that it's too much to ask that they (ADN) specify that AdskCommandHandler is a user-defined Class when used in publicly posted code, as Balaji Ramamoorthy fails to do here:roll:

/vent

Let him know.

Was typing it up when your post came in.  :lol:

That one example you posted was just a snippet of code. I wouldn't expect any explanation for it here, as it would be assumed you already have some working code. THIS is a better example, and Adam does include everything needed for it to work.

Correct... I copied that snippet from here, as that was for Revit API.

In any event, now I have something to work with... And for that, I thank you.
"How we think determines what we do, and what we do determines what we get."

TheMaster

  • Guest
Re: Custom Ribbon* Classes
« Reply #9 on: August 25, 2012, 06:11:12 AM »
It is a class you create. This AU2009 class would be good reading/watching/listening to: http://au.autodesk.com/?nd=class&session_id=5044

Thank you (yet again), Jeff... I'll definitely check out the AU course online this weekend.

After more searching online this morning, I did start to see that others were posting the actual Class:

Code - C#: [Select]
  1. public class AdskCommandHandler
  2.   : System.Windows.Input.ICommand
  3.   {
  4.  
  5.   }
  6.  



If ADN developers aren't going to include such a Class Implementation in the SDK/Installation Libraries, then I don't think that it's too much to ask that they (ADN) specify that AdskCommandHandler is a user-defined Class when used in publicly posted code, as Balaji Ramamoorthy fails to do here:roll:

/vent

They generally don't document interfaces that are part of the .NET framework.

For example, there are objects that implement System.Collections.IDictionary (DBDictionary, and Autodesk.AutoCAD.Runtime.Dictionary are two) but I think most would be surprised at how few know that.
« Last Edit: August 25, 2012, 06:44:23 AM by TT »