Code Red > .NET

MY TAB/Ribbon not Show Permanent In Autocad

(1/1)

daboho:
this code is run as well but problem while closed autocad ,my tab not permanent in autocad must every open autocad run TAB,Panel, and Button
how to edit for permanent tab in Autocad without every time open Run This Code to make TAB
thanks for attention

--- Code: ---        [CommandMethod("testmyRibbon")]
        public void Testme()
        {
            RibbonControl ribbon = ComponentManager.Ribbon;
            if (ribbon != null)
            {
                RibbonTab rtab = ribbon.FindTab("TEST ME");
                if (rtab != null)
                {
                    ribbon.Tabs.Remove(rtab);     
                }
                rtab = new RibbonTab();
                rtab.Title = "TEST  ME";
                rtab.Id = "Testing";
                //Add the Tab
                ribbon.Tabs.Add(rtab);
                addContent(rtab);
            }
        }

        static void addContent(RibbonTab rtab)
        {
            rtab.Panels.Add(AddOnePanel());
        }

        static RibbonPanel AddOnePanel()
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            RibbonButton rb;
            RibbonPanelSource rps = new RibbonPanelSource();
            rps.Title = "Test One";
            RibbonPanel rp = new RibbonPanel();
            rp.Source = rps;

            //Create a Command Item that the Dialog Launcher can use,
            // for this test it is just a place holder.
            RibbonButton rci = new RibbonButton();
            rci.Name = "TestCommand";

            //assign the Command Item to the DialgLauncher which auto-enables
            // the little button at the lower right of a Panel
            rps.DialogLauncher = rci;

            rb = new RibbonButton();
            rb.Name = "Test Button";
            rb.ShowText = true;
            rb.ShowImage = true;
            rb.Width = 250;
            rb.Text = "Test Button";
            rb.CommandHandler = new MyRibbonCommandHandler();
            rb.CommandParameter = "CF";
          //  dwg.SendStringToExecute((string)rb.CommandParameter + " ", true, false, true);
            //Add the Button to the Tab
            rps.Items.Add(rb);
            return rp;
        }

   

    }

    internal class MyRibbonCommandHandler : System.Windows.Input.ICommand
    {
        public event EventHandler CanExecuteChanged;

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

        public void Execute(object parameter)
        {
            RibbonCommandItem btn = parameter as RibbonCommandItem;
            if (btn != null)
            {
                //execute an AutoCAD command, or your custom command defined by [CommandMethod]
                Document dwg = acApp.DocumentManager.MdiActiveDocument;
                dwg.SendStringToExecute((string)btn.CommandParameter + " ", true, false, true);



            }
        }






    }
--- End code ---

Keith™:
In your main class instantiation

--- Code - C#: ---public class MyAppClass{     ribbonClass myribbon = new ribbonClass(); //instantiate your ribbon class as necessary}
When you load your application into AutoCAD (netload) let that application load the ribbon for you.

Now, if you are loading the application and having it run when you load it, change that behavior such that you register commands in AutoCAD that execute your program as needed, but have the main class when loaded, instantiate your ribbon so it will always be available when AutoCAD is open.

You can auto netload an application by adding a setting in the registry:
Open the registry and browse to the relevant HKLM registry key ...
HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R19.1\ACAD-D000:407\Applications\ (this may be different in your installation)
Add the following keys and values:
LOADER (string) "path_to_your_dll"
DESCRIPTION (string) "Description of your application"
LOADCTRLS (dword) 0000000e
MANAGED (dword) 00000001

Once you do this, you need to restart AutoCAD.

You may need to netload the DLL at least once before the settings work, or they may work right away.

There are other ways to do this. For more information about automatically loading your .net assembly see this:
https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/How-to-autoload-DLLs-with-AutoCAD.html

daboho:
@keith thanks

Keith™:
No problem. This is how I solved my issue with the same.

Navigation

[0] Message Index

Go to full version