Author Topic: Content of loaded CUIX is not displayed in the current Workspace  (Read 1998 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
AutoCAD 2009-2011 x64 Enu.

I load my CUI\CUIX menu, but its content is not displayed until I regenerate the current Workspace (read my comment in the code, please). I try to do it through the CustomizationSection.UpdateWorkspaceComplete() method, but it doesn't help me. How can I fix it?

Code - C#: [Select]
  1.     // Since of AutoCAD 2010 it is CUIX files (menu) are used instead of CUI.
  2.     static readonly System.Version acad_2010_version = new System.Version(18, 0);
  3.      
  4.     static readonly string menuFilesExtension = cad.Version <
  5.         acad_2010_version ? ".cui" : ".cuix";
  6.      
  7.     static readonly string extensionMenuDir = Path.Combine(
  8.         Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
  9.         @"..\Resources\");
  10.      
  11.     static readonly string extensionMenuFileName = (
  12.         cad.Version < acad_2010_version ? "Proxy_Tools_2009" : "Proxy_Tools_2010")
  13.         + menuFilesExtension;
  14.      
  15.     static readonly string extensionMenuFullName = Path.GetFullPath(
  16.         Path.Combine(extensionMenuDir, extensionMenuFileName));
  17.      
  18.     const string menuGroupName = "PROXY_TOOLS";
  19.      
  20.     // Since AutoCAD 2011 the `CustomizationSection.RemovePartialMenu()`
  21.     // method has other signature.
  22.     // Also, the BUNDLE-package autoloader have appeared since AutoCAD 2012.
  23.     static readonly System.Version acad_2011_version = new System.Version(18, 1);
  24.      
  25.     void LoadMenu()
  26.     {
  27.         string mainCuiFile = string.Format("{0}{1}",
  28.         (string)cad.GetSystemVariable("MENUNAME"), menuFilesExtension);
  29.      
  30.         try
  31.         {
  32.             CustomizationSection csMain = new CustomizationSection(mainCuiFile);
  33.      
  34.             if (!csMain.PartialCuiFiles.Contains(extensionMenuFullName))
  35.             {
  36.                 Type csType = typeof(CustomizationSection);
  37.                 bool menuloadingResult = false;
  38.      
  39.                 if (cad.Version < acad_2011_version)
  40.                 {
  41.                     CustomizationSection csExtension = new CustomizationSection(
  42.                 extensionMenuFullName);
  43.                     menuloadingResult = (bool)csType.InvokeMember("AddPartialMenu",
  44.                         BindingFlags.Public | BindingFlags.InvokeMethod |
  45.                         BindingFlags.Instance, null, csMain, new object[] {
  46.                     csExtension });
  47.                 }
  48.                 else
  49.                 {
  50.                     menuloadingResult = (bool)csType.InvokeMember("AddPartialMenu",
  51.                         BindingFlags.Public | BindingFlags.InvokeMethod |
  52.                     BindingFlags.Instance, null, csMain, new object[] {
  53.                         extensionMenuFullName });
  54.                 }
  55.      
  56.                 if (csMain.IsModified == true)
  57.                 {
  58.                     // Display our menu
  59.                     // TODO: The problem is here. My Partial CUI\CUIX menu loaded and exists
  60.                     // in the current Workspace (I see it in the "Customize user interface" dialog),
  61.                     // but it is not displayed until I do any change in the "Customize user interface"
  62.                     // dialog (for example edit the `Description` property of the current Workspace) and
  63.                     // press "Apply" key.
  64.                     CustomizationSection csExtension = new CustomizationSection(
  65.                 extensionMenuFullName);
  66.      
  67.                     // TODO: I don't see any info about these functions in the AutoCAD 2016 SDK
  68.                     // documentations, but I had a hope that they can help me...
  69.                     // But they didn't help me.
  70.                     csMain.addToolbarsMenusAndPanelsToWorkspace(csExtension);
  71.                     csMain.UpdateWorkspaceComplete();
  72.      
  73.                     // Save all changes
  74.                     csMain.Save();
  75.                 }
  76.             }
  77.         }
  78.         catch (System.Exception ex)
  79.         {
  80.             Document doc = cad.DocumentManager.MdiActiveDocument;
  81.             if (null == doc)
  82.             {
  83.                 cad.ShowAlertDialog(ex.Message);
  84.             }
  85.             else
  86.             {
  87.                 doc.Editor.WriteMessage("\nAttempt of `{0}` file loading...\nERROR: {0}\n",
  88.                     extensionMenuFullName, ex.Message);
  89.             }
  90.         }
  91.     }

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Content of loaded CUIX is not displayed in the current Workspace
« Reply #1 on: May 20, 2016, 06:33:56 PM »
The same thing happens to me.
Code: [Select]
AcadApplication ap = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                AcadMenuGroups menus = ap.MenuGroups;
                try
                {
                    menus.Item(sMenu);
                }
                catch
                {
                    menus.Load(sDest, false);
                    AcadMenuBar mnuBar = ap.MenuBar;
                    if (sMenu == "BRYCO2011") return bCopy;
                    if (sMenu == "Lex-C#")
                        menus.Item(sMenu).Menus.Item("Hardware").InsertInMenuBar(mnuBar.Count);
                    menus.Item(sMenu).Menus.Item(sMenubarName).InsertInMenuBar(mnuBar.Count);
                }
I use the acadapplication method (not the best)  and on a new install I have to manually do what you do to the cui to get it to show.
After that I can replace the partial cuix any time and no problem.
Sorry I can't help

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Content of loaded CUIX is not displayed in the current Workspace
« Reply #2 on: May 21, 2016, 05:13:11 PM »
Alexander Rivilis  answered to me that I edited the file, but not the loaded menu of current AutoCAD session. Ok, now I try to do it through the late binding:
Code - C#: [Select]
  1. // AutoCAD 2009
  2. var mg = cad.MenuGroups.GetType().InvokeMember("Load",
  3.     BindingFlags.Public | BindingFlags.InvokeMethod |
  4.     BindingFlags.Instance, null, cad.MenuGroups, new object[] { extensionMenuFullName });

This code through the Load method successfully loads the Toolbars, but not the Ribbons (they are not displayed). But if I switch the Workspace and again switch it back then my ribbons are appearing...

Code - C#: [Select]
  1. string ws = (string)cad.GetSystemVariable("WSCURRENT");
  2. cad.SetSystemVariable("WSCURRENT", ws);
  3.  

But I would not like to show my ribbons through the Workspace switching... This is bad way. If each my extension will do it, then it can take many time.
« Last Edit: May 21, 2016, 05:18:34 PM by Andrey Bushman »