// Since of AutoCAD 2010 it is CUIX files (menu) are used instead of CUI.
static readonly System.Version acad_2010_version = new System.Version(18, 0);
static readonly string menuFilesExtension = cad.Version <
acad_2010_version ? ".cui" : ".cuix";
static readonly string extensionMenuDir = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@"..\Resources\");
static readonly string extensionMenuFileName = (
cad.Version < acad_2010_version ? "Proxy_Tools_2009" : "Proxy_Tools_2010")
+ menuFilesExtension;
static readonly string extensionMenuFullName = Path.GetFullPath(
Path.Combine(extensionMenuDir, extensionMenuFileName));
const string menuGroupName = "PROXY_TOOLS";
// Since AutoCAD 2011 the `CustomizationSection.RemovePartialMenu()`
// method has other signature.
// Also, the BUNDLE-package autoloader have appeared since AutoCAD 2012.
static readonly System.Version acad_2011_version = new System.Version(18, 1);
void LoadMenu()
{
string mainCuiFile = string.Format("{0}{1}",
(string)cad.GetSystemVariable("MENUNAME"), menuFilesExtension);
try
{
CustomizationSection csMain = new CustomizationSection(mainCuiFile);
if (!csMain.PartialCuiFiles.Contains(extensionMenuFullName))
{
Type csType = typeof(CustomizationSection);
bool menuloadingResult = false;
if (cad.Version < acad_2011_version)
{
CustomizationSection csExtension = new CustomizationSection(
extensionMenuFullName);
menuloadingResult = (bool)csType.InvokeMember("AddPartialMenu",
BindingFlags.Public | BindingFlags.InvokeMethod |
BindingFlags.Instance, null, csMain, new object[] {
csExtension });
}
else
{
menuloadingResult = (bool)csType.InvokeMember("AddPartialMenu",
BindingFlags.Public | BindingFlags.InvokeMethod |
BindingFlags.Instance, null, csMain, new object[] {
extensionMenuFullName });
}
if (csMain.IsModified == true)
{
// Display our menu
// TODO: The problem is here. My Partial CUI\CUIX menu loaded and exists
// in the current Workspace (I see it in the "Customize user interface" dialog),
// but it is not displayed until I do any change in the "Customize user interface"
// dialog (for example edit the `Description` property of the current Workspace) and
// press "Apply" key.
CustomizationSection csExtension = new CustomizationSection(
extensionMenuFullName);
// TODO: I don't see any info about these functions in the AutoCAD 2016 SDK
// documentations, but I had a hope that they can help me...
// But they didn't help me.
csMain.addToolbarsMenusAndPanelsToWorkspace(csExtension);
csMain.UpdateWorkspaceComplete();
// Save all changes
csMain.Save();
}
}
}
catch (System.Exception ex)
{
Document doc = cad.DocumentManager.MdiActiveDocument;
if (null == doc)
{
cad.ShowAlertDialog(ex.Message);
}
else
{
doc.Editor.WriteMessage("\nAttempt of `{0}` file loading...\nERROR: {0}\n",
extensionMenuFullName, ex.Message);
}
}
}