Hi, im new with vb.net and i made some commands that runs well when i loaded with NETLOAD command.
The problem is that i want to improve it making a button (i found that is called a ribbon button)to each command in a toolbar; also i need to know hoy to make that toolbar that loads when y load the .dll file. i read a lot of related topics in this forum and also in another pages but i cant find an a definitve answer or procedure, which assemblies or libraries i need to import.
Thanks for your help
Hi,
You have two options:
1. Create standard cuix file
2. Create custom ribbon using code (without cuix)
The second option perfect work for me.
The first you need create ribbon. My ribbon class:
public class Ribbon
{
public Ribbon()
{
}
public static void CreateMyRibbon()
{
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();
}
}
private static 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);
}
}
public static void CreateRibbon()
{
Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
List<string> tabs = new List<string>();
foreach (Autodesk.Windows.RibbonTab tab in ribbonControl.Tabs)
{
tabs.Add(tab.Title);
}
if (tabs.Contains("My Ribbon") == false)
{
RibbonTab Tab = new RibbonTab();
Tab.Title = "My Ribbon";
Tab.Id = "My_Ribbon_TAB_ID";
ribbonControl.Tabs.Add(Tab);
// create Ribbon panels
Autodesk.Windows.RibbonPanelSource visibilityPanel = new RibbonPanelSource();
visibilityPanel.Title = "Visibility";
RibbonPanel VisibilityPanel = new RibbonPanel();
VisibilityPanel.Source = visibilityPanel;
Tab.Panels.Add(VisibilityPanel);
RibbonButton UpdateDrawingTable = new RibbonButton();
UpdateDrawingTable.Text = "Update Drawing Table";
UpdateDrawingTable.Description = "Update Drawing Table";
UpdateDrawingTable.ShowText = true;
UpdateDrawingTable.ShowImage = true;
UpdateDrawingTable.Image = Images.getBitmap(Properties.Resources.Small);
UpdateDrawingTable.LargeImage = Images.getBitmap(Properties.Resources.large);
UpdateDrawingTable.Orientation = System.Windows.Controls.Orientation.Vertical;
UpdateDrawingTable.Size = RibbonItemSize.Large;
UpdateDrawingTable.CommandHandler = new RibbonCommandHandler();
UpdateDrawingTable.CommandParameter = "KCT_UpdatedrawingTable";
RibbonButton ShowGroundFloorButton = new RibbonButton();
ShowGroundFloorButton.Text = "Ground Floor";
ShowGroundFloorButton.Description = "Show Ground Floor Level";
ShowGroundFloorButton.ShowText = true;
ShowGroundFloorButton.ShowImage = false;
ShowGroundFloorButton.CommandHandler = new SplitButtonCommandHandler();
ShowGroundFloorButton.CommandParameter = "KTC_ShowGroundFloorLevel";
RibbonButton ShowFirstFloorButton = new RibbonButton();
ShowFirstFloorButton.Text = "First Floor";
ShowFirstFloorButton.Description = "Show First Floor Level";
ShowFirstFloorButton.ShowText = true;
ShowFirstFloorButton.ShowImage = false;
ShowFirstFloorButton.CommandHandler = new SplitButtonCommandHandler();
ShowFirstFloorButton.CommandParameter = "KTC_ShowFirstFloorLevel";
RibbonButton ShowAllLevelsButton = new RibbonButton();
ShowAllLevelsButton.Text = "All Levels";
ShowAllLevelsButton.Description = "Show All Levels";
ShowAllLevelsButton.ShowText = true;
ShowAllLevelsButton.ShowImage = false;
ShowAllLevelsButton.CommandHandler = new SplitButtonCommandHandler();
ShowAllLevelsButton.CommandParameter = "KTC_ShowAllLevels";
RibbonSplitButton showLevelCombo = new RibbonSplitButton();
showLevelCombo.Text = "RibbonSplitButton";
showLevelCombo.ShowText = true;
showLevelCombo.Items.Add(ShowAllLevelsButton);
showLevelCombo.Items.Add(ShowGroundFloorButton);
showLevelCombo.Items.Add(ShowFirstFloorButton);
showLevelCombo.Current = ShowAllLevelsButton;
RibbonRowPanel VisibilityPanelRow = new RibbonRowPanel();
VisibilityPanelRow.Items.Add(showLevelCombo);
//visibilityPanel.Items.Add(UpdateDynamicBlocks);
visibilityPanel.Items.Add(UpdateDrawingTable);
visibilityPanel.Items.Add(VisibilityPanelRow);
Tab.IsActive = false;
}
}
public class RibbonCommandHandler : System.Windows.Input.ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
if (parameter is RibbonButton)
{
RibbonButton button = parameter as RibbonButton;
Document dwg = Application.DocumentManager.MdiActiveDocument;
dwg.SendStringToExecute((string)button.CommandParameter + " ", true, false, true);
}
}
}
public class SplitButtonCommandHandler : System.Windows.Input.ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (parameter is RibbonButton)
{
RibbonButton button = parameter as RibbonButton;
Type type = typeof(ClassWithCommand);
MethodInfo method = type.GetMethod((string)button.CommandParameter);
ClassWithCommand classWithCommand= new ClassWithCommand();
string result = (string)method.Invoke(kingspanCADTools, null);
Console.WriteLine(result);
}
}
}
public class Images
{
public static BitmapImage getBitmap(Bitmap image)
{
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = stream;
bmp.EndInit();
return bmp;
}
}
}
to load when the dllis loaded you can add to initialize:
public void Initialize()
{
CreateMyRibbon();
}
Can't find what you're looking for? Ask the community or share your knowledge.