程序自动加载cui文件成功但没有显示(kean的例子)
问题如题,加载后没显示,手工卸掉后,再运行bm有显示~~疑惑~~using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Customization;
using System;
using System.Collections.Specialized;
namespace PartialCUI
{
public class Commands : IExtensionApplication
{
public void Initialize()
{
BuildMenuCUI();
}
public void Terminate()
{
}
public void BuildMenuCUI()
{
const string myCuiFile = "c:\\kean.cui";
const string myCuiFileToSend = "c:/kean.cui";
const string myCuiSectionName = "Kean";
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
string mainCui =
Application.GetSystemVariable("MENUNAME") + ".cui";
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, "Pop Cmd 1", pm, -1);
PopMenuItem pmi2 =
new PopMenuItem(mm2, "Pop Cmd 2", 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);
}
}
}
页:
[1]