Author Topic: Create Partial Menu and load dll when user click menu.  (Read 1507 times)

0 Members and 1 Guest are viewing this topic.

thenndral

  • Guest
Create Partial Menu and load dll when user click menu.
« on: April 29, 2014, 03:33:49 AM »
Hi,

I have a question.
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.I guess to modify in this area
MenuMacro mm1 = new MenuMacro(mg, "Cmd 1", "^C^CCmd1", "ID_MyCmd1");
 MenuMacro mm2 = new MenuMacro(mg, "Cmd 2", "^C^CCmd2", "ID_MyCmd2");

Code - C#: [Select]
  1.  [CommandMethod("CreateMenu")]
  2.     public void BuildMenuCUI()
  3.     {
  4.       const string myCuiFile = "c:\\thenndral.cuix";
  5.       const string myCuiFileToSend = "c:\\thenndral.cuix";
  6.       const string myCuiSectionName = "Thenndral";
  7.  
  8.       Editor ed =
  9.         Application.DocumentManager.MdiActiveDocument.Editor;
  10.  
  11.       string mainCui =
  12.         Application.GetSystemVariable("MENUNAME") + ".cuix";
  13.       CustomizationSection cs =
  14.         new CustomizationSection(mainCui);
  15.       PartialCuiFileCollection pcfc = cs.PartialCuiFiles;
  16.  
  17.       if (pcfc.Contains(myCuiFile))
  18.       {
  19.         ed.WriteMessage("\nCustomization file \""+ myCuiFile + "\" already loaded.");
  20.       }
  21.       else{
  22.         if (System.IO.File.Exists(myCuiFile))
  23.         {
  24.           ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" exists - loading it.");
  25.           LoadMyCui(myCuiFileToSend);
  26.         }
  27.         else
  28.         {
  29.           ed.WriteMessage("\nCustomization file \"" + myCuiFile + "\" does not exist - building it." );
  30.  
  31.           // Create a customization section for our partial menu
  32.           CustomizationSection pcs = new CustomizationSection();
  33.           pcs.MenuGroupName = myCuiSectionName;
  34.  
  35.           // Let's add a menu group, with two commands
  36.           MacroGroup mg = new MacroGroup(myCuiSectionName, pcs.MenuGroup);
  37.           MenuMacro mm1 = new MenuMacro(mg, "Cmd 1", "^C^CCmd1", "ID_MyCmd1");
  38.           MenuMacro mm2 = new MenuMacro(mg, "Cmd 2", "^C^CCmd2", "ID_MyCmd2");
  39.  
  40.           // Now let's add a pull-down menu, with two items
  41.           StringCollection sc = new StringCollection();
  42.           sc.Add("POP15");
  43.           PopMenu pm = new PopMenu(myCuiSectionName,sc,"ID_MyPop1", pcs.MenuGroup);
  44.           PopMenuItem pmi1 = new PopMenuItem(mm1, "Empty Layout", pm, -1);
  45.           PopMenuItem pmi2 = new PopMenuItem(mm2, "Check ID", pm, -1);
  46.  
  47.           // Finally we save the file and load it
  48.           pcs.SaveAs(myCuiFile);
  49.           LoadMyCui(myCuiFileToSend);
  50.         }
  51.       }
  52.     }
  53.  
  54.     private void LoadMyCui(string cuiFile)
  55.     {
  56.         Document doc =Application.DocumentManager.MdiActiveDocument;
  57.  
  58.         object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
  59.         object oldFileDia = Application.GetSystemVariable("FILEDIA");
  60.  
  61.         Application.SetSystemVariable("CMDECHO", 0);
  62.         Application.SetSystemVariable("FILEDIA", 0);
  63.  
  64.         doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
  65.         doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString()+ ")(princ) ",false, false, false);
  66.         doc.SendStringToExecute("(setvar \"CMDECHO\" "+ oldCmdEcho.ToString()+ ")(princ) ",false, false, false);
  67.     }
  68.  
  69.  


Reference  link:
http://through-the-interface.typepad.com/through_the_interface/2007/05/creating_a_part.html
http://www.theswamp.org/index.php?topic=16024.msg194243#msg194243

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

Thanks in advance,
thenndral


edit:kdub => code=csharp formatting
« Last Edit: April 30, 2014, 04:41:02 AM by Kerry »

thenndral

  • Guest
Re: Create Partial Menu and load dll when user click menu.
« Reply #1 on: April 30, 2014, 03:03:09 AM »
Hi,

Done. Thanks Ajilal.Vijayan. May be it will help for someone.

After NETLOAD , Your dll file name and dll command name.
Make sure the dll file path is within the autocad search path.

Modified code:
Code: [Select]
new MenuMacro(mg, "Cmd 1", "^C^C._NETLOAD;MYDLL;MYCOMMAND", "ID_MyCmd1");

Thanks,
thenndral