明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2606|回复: 0

程序自动加载cui文件成功但没有显示(kean的例子)

[复制链接]
发表于 2011-12-2 17:41:29 | 显示全部楼层 |阅读模式
问题如题,加载后没显示,手工卸掉后,再运行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()
    {
    }
    [CommandMethod("bm")]
    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  );
    }
  }
}

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-29 02:37 , Processed in 0.152379 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表