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
Solved! Go to Solution.
Solved by Ajilal.Vijayan. Go to Solution.
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.
@thenndral wrote:Hi,
Thanks Ajilal.Vijayan.
Its Works like charm.
Thanks again.
Thenndral
You're Welcome !