Author Topic: MY TAB/Ribbon not Show Permanent In Autocad  (Read 234 times)

0 Members and 1 Guest are viewing this topic.

daboho

  • Mosquito
  • Posts: 15
MY TAB/Ribbon not Show Permanent In Autocad
« on: August 28, 2021, 01:46:44 PM »
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: [Select]
        [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);



            }
        }






    }

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16872
  • Superior Stupidity at its best
Re: MY TAB/Ribbon not Show Permanent In Autocad
« Reply #1 on: August 29, 2021, 10:49:40 PM »
In your main class instantiation
Code - C#: [Select]
  1. public class MyAppClass{
  2.      ribbonClass myribbon = new ribbonClass(); //instantiate your ribbon class as necessary
  3. }

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

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie