.NET

Reply
Active Contributor
thenndral
Posts: 48
Registered: ‎04-01-2013
Message 1 of 4 (256 Views)
Accepted Solution

Create Partial Menu and load C# dll.

256 Views, 3 Replies
04-29-2014 08:48 PM

Hi,

I'm using AutoCAD 2013 with C#.

I need to create a menu after Help Menu in Autocad2013.


for ex.
Top Menu Name: Thenndral
submenu1: Empty Layout
submenu2: Check ID

1. when the user click Empty Layout, then call "emptylayout.dll"
2. as well click Check ID, then call "checkid.dll"

 

I tried this code with the help of Kean's code. I have no problem in adding menu. but click event not working. I don't know how to add dll name in the "MenuMacro" code.

 

[CommandMethod("CreateMenu")]
    public void BuildMenuCUI()
    {
      const string myCuiFile = "c:\\thenndral.cuix";
      const string myCuiFileToSend = "c:\\thenndral.cuix";
      const string myCuiSectionName = "Thenndral";

      Editor ed =
        Application.DocumentManager.MdiActiveDocument.Editor;

      string mainCui =
        Application.GetSystemVariable("MENUNAME") + ".cuix";
      CustomizationSection cs =
        new CustomizationSection(mainCui);
      PartialCuiFileCollection pcfc = cs.PartialCuiFiles;

      if (pcfc.Contains(myCuiFile))
      {
        ed.WriteMessage("\nCustomization file \""+ myCuiFile + "\" already loaded.");
      }
      else{
        if (System.IO.File.Exists(myCuiFile))
        {
          ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" exists - loading it.");
          LoadMyCui(myCuiFileToSend);
        }
        else
        {
          ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" does not exist - building it." );

          // Create a customization section for our partial menu
          CustomizationSection pcs = new CustomizationSection();
          pcs.MenuGroupName = myCuiSectionName;

          // Let's add a menu group, with two commands
          MacroGroup mg = new MacroGroup(myCuiSectionName, pcs.MenuGroup);
          MenuMacro mm1 = new MenuMacro(mg, "Cmd 1", "^C^CCmd1", "ID_MyCmd1");
          MenuMacro mm2 = new MenuMacro(mg, "Cmd 2", "^C^CCmd2", "ID_MyCmd2");

          // Now let's add a pull-down menu, with two items
          StringCollection sc = new StringCollection();
          sc.Add("POP15");
          PopMenu pm = new PopMenu(myCuiSectionName,sc,"ID_MyPop1", pcs.MenuGroup);
          PopMenuItem pmi1 = new PopMenuItem(mm1, "Empty Layout", pm, -1);
          PopMenuItem pmi2 = new PopMenuItem(mm2, "Check ID", pm, -1);

          // Finally we save the file and load it
          pcs.SaveAs(myCuiFile);
          LoadMyCui(myCuiFileToSend);
        }
      }
    }

    private void LoadMyCui(string cuiFile)
    {
        Document doc =Application.DocumentManager.MdiActiveDocument;

        object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
        object oldFileDia = Application.GetSystemVariable("FILEDIA");

        Application.SetSystemVariable("CMDECHO", 0);
        Application.SetSystemVariable("FILEDIA", 0);

        doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
        doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString()+ ")(princ) ",false, false, false);
        doc.SendStringToExecute("(setvar \"CMDECHO\" "+ oldCmdEcho.ToString()+ ")(princ) ",false, false, false);
    }

 

Could you please suggest me to solve this process or other solution to create partial menu also appreciated.

 

Thanks in advance,
thenndral

Valued Mentor
Ajilal.Vijayan
Posts: 433
Registered: ‎01-12-2008
Message 2 of 4 (240 Views)

Re: Create Partial Menu and load C# dll.

04-29-2014 10:07 PM in reply to: thenndral

Try changing this line

After NETLOAD , Your dll file name and dll command name.

 

new MenuMacro(mg, "Cmd 1", "^C^C._NETLOAD;MYDLL;MYCOMMAND", "ID_MyCmd1");

 Make sure the dll file path is within the autocad search path.

 

Active Contributor
thenndral
Posts: 48
Registered: ‎04-01-2013
Message 3 of 4 (225 Views)

Re: Create Partial Menu and load C# dll.

04-29-2014 11:50 PM in reply to: Ajilal.Vijayan

Hi,

 

Thanks Ajilal.Vijayan.

Its Works like charm.

 

Thanks again.

Thenndral

Valued Mentor
Ajilal.Vijayan
Posts: 433
Registered: ‎01-12-2008
Message 4 of 4 (166 Views)

Re: Create Partial Menu and load C# dll.

05-01-2014 11:34 AM in reply to: thenndral

thenndral wrote:

Hi,

 

Thanks Ajilal.Vijayan.

Its Works like charm.

 

Thanks again.

Thenndral


You're Welcome !

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.