Author Topic: opening temporary a ribbon  (Read 1566 times)

0 Members and 1 Guest are viewing this topic.

arnaudalp

  • Guest
opening temporary a ribbon
« on: June 13, 2019, 09:16:11 AM »
Hi.
I'm a new user of this forum. I'm searching to create a ribbon who do the same action like Hatch command in the Autocad Ribbon.

I make a ribbon, when I click on my icone, my new ribbon is create. I choose a command with a new icone ( circle for exemple ) and when I finished my command, I want close this ribbon for find my first ribbon.

In an other time, i would like active a command and display a new ribbon during my command....

Code: [Select]
namespace RibbonSample
{
    public class Ribbon
    {
       

        [CommandMethod("MyRibbon")]
        public void MyRibbon()
        {           
            Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
            RibbonTab Tab = new RibbonTab();
            Tab.Title = "Autodesk .NET forum Ribbon Sample";
            Tab.Id = "RibbonSample_TAB_ID";
            Tab.IsContextualTab = false;

            ribbonControl.Tabs.Add(Tab);

           // create Ribbon panels
           Autodesk.Windows.RibbonPanelSource panel1Panel = new RibbonPanelSource();
           panel1Panel.Title = "Panel1";
           RibbonPanel Panel1 = new RibbonPanel();
           Panel1.Source = panel1Panel;
           Tab.Panels.Add(Panel1);

            RibbonButton pan1button1 = new RibbonButton();
            pan1button1.Text = "Button1";
            pan1button1.ShowText = true;
            pan1button1.ShowImage = true;
            pan1button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan1button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan1button1.Size = RibbonItemSize.Large;
            panel1Panel.Items.Add(pan1button1);
            Tab.IsActive = true;
            pan1button1.CommandHandler = new RibbonCommandHandler();
            pan1button1.CommandParameter = "Test ";     
                           
        }


        [CommandMethod("Test")]
        public void MyRibbon2()
        {

            Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
            RibbonTab Tab1 = new RibbonTab();
            Tab1.Title = "Autodesk test";
            Tab1.Id = "RibbonSample_TAB_ID";
            Tab1.IsContextualTab = false;

            ribbonControl.Tabs.Add(Tab1);
           

            // create Ribbon panels
            Autodesk.Windows.RibbonPanelSource panelPanel = new RibbonPanelSource();
            panelPanel.Title = "Panel test";
            RibbonPanel Panel = new RibbonPanel();
            Panel.Source = panelPanel;
            Tab1.Panels.Add(Panel);

            RibbonButton pan1button1 = new RibbonButton();
            pan1button1.Text = "Button test";
            pan1button1.ShowText = true;
            pan1button1.ShowImage = true;
            pan1button1.Image = Images.getBitmap(Properties.Resources.Small);
            pan1button1.LargeImage = Images.getBitmap(Properties.Resources.large);
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical;
            pan1button1.Size = RibbonItemSize.Standard;
            panelPanel.Items.Add(pan1button1);
            Tab1.IsActive = true;
           
            pan1button1.CommandHandler = new RibbonCommandHandler();
            pan1button1.CommandParameter = "_Circle "; 
           
           
                     

        }


        public class RibbonCommandHandler : System.Windows.Input.ICommand
        {
            public RibbonTab Getstatus(RibbonTab tab)
            {

                return tab;
            }
            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                Document doc = acadApp.DocumentManager.MdiActiveDocument;
                RibbonCommandItem cmd = parameter as RibbonCommandItem;
                doc.SendStringToExecute((string)cmd.CommandParameter, true, false, true);             
             

            }



        }




        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;
            }
        }
    }
}
« Last Edit: June 13, 2019, 09:43:23 AM by arnaudalp »