明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1019|回复: 4

CUI加载问题

[复制链接]
发表于 2016-1-12 08:51 | 显示全部楼层 |阅读模式
AutoCAD VBA & VB.net 第二版》的例子做的CUI,调试状态下加载问题,做成安装包在同一台机器上不能加载
发表于 2016-1-12 15:19 来自手机 | 显示全部楼层
代码呢?。。。。。。
 楼主| 发表于 2016-1-18 11:30 | 显示全部楼层
雪山飞狐_lzh 发表于 2016-1-12 15:19
代码呢?。。。。。。

程序启动自动加载不了,但是运行命令就可以加载
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.EditorInput;
  3. using Autodesk.AutoCAD.Runtime;
  4. using Autodesk.AutoCAD.Customization;
  5. using System.Collections.Specialized;
  6. using Autodesk.AutoCAD.Windows;
  7. using System;
  8. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

  9. //using System.Windows.Forms;
  10. using Autodesk.AutoCAD.Customization;
  11. using Autodesk.AutoCAD.Windows;
  12. using Autodesk.AutoCAD.Geometry;
  13. using System.Drawing;

  14. //[assembly: ExtensionApplication(typeof(SLCAD.m_auto))]
  15. [assembly: CommandClass(typeof(SLCAD.m_Palette ))]
  16. [assembly: CommandClass(typeof(SLCAD.comDwgData ))]
  17. [assembly: CommandClass(typeof(SLCAD.CadDraw.comDraw))]
  18. [assembly: CommandClass(typeof(SLCAD.comShow.cadShow ))]

  19. namespace SLCAD
  20. {
  21.     public class cadAuto : IExtensionApplication
  22.     {
  23.         public static string spath = @"E:\6CAD开发\DWG\123.dwg";
  24.         public static string outSpath = @"E:\6CAD开发\OUT";
  25.         //public static string startpath =  Left(Assembly.GetExecutingAssembly.Location, Len

  26. (Reflection.Assembly.GetExecutingAssembly.Location) - 11) ;
  27.         //public static DateTime dateTime = DateTime.Now;
  28.         public static string dateTimeStr = DateTime.Now.ToString("yyyyMMdd");
  29.         //public static string myCuiFile = CUITOOLS.GetCurrentPath() + "\\SLCUI.cui";
  30.         //public static string menuGroupName = "SLCUI";//菜单组名
  31.         public static CustomizationSection cs = new CustomizationSection();

  32.         public void Initialize()
  33.         {
  34.             Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  35.             Editor ed = doc.Editor;
  36.              //在AutoCAD命令行上显示一些信息,它们会在程序载入时被显示
  37.             ed.WriteMessage("程序开始初始化。");
  38.               
  39.             m_Palette.showPalette();
  40.             comShow.cadShow.ton();
  41.             AddMenu();
  42.             methodDatabase.getSetValue();
  43.         }

  44.         public void Terminate()
  45.         {
  46.             // 在Visual Studio 2010的输出窗口上显示程序结束的信息
  47.             System.Diagnostics.Debug.WriteLine(
  48.         "程序结束,你可以在里做一些程序的清理工作,如关闭AutoCAD文档");
  49.         }

  50.         public void openMainDwg()
  51.         {
  52.             //CloseAllDwgs();
  53.             string mainOut = outSpath + dateTimeStr;

  54.             Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  55.             DocumentCollection docs = AcadApp.DocumentManager;
  56.             Document doc = docs.Open(spath, false);
  57.             AcadApp.DocumentManager.MdiActiveDocument = doc;

  58.         }

  59.         //[CommandMethod("AddMenu")]
  60.         public static void AddMenu()
  61.         {
  62.             const string cuiFile = "d:\\slzj.cui";
  63.             const string menuGroupName = "Slzj";//菜单组名
  64.             const string cuitosend = "d:/slzj.cui";
  65.             string path = CUITOOLS.GetCurrentPath();

  66.             AcadApp.MainWindow.Text = "XX设计系统";
  67.             Autodesk.AutoCAD.Windows.Window mw = Autodesk.AutoCAD.ApplicationServices.Application.MainWindow;
  68.             mw.Icon = new Icon(path + "\\images\\2.ico");

  69.             Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  70.             //CustomizationSection cs = new CustomizationSection();

  71.             try
  72.             {
  73.                 //装载局部CUI文件,若不存在,则创建
  74.                 cs = doc.AddCui(cuiFile, menuGroupName);
  75.                 //数据图形管理         
  76.                 cs.AddMacro("打开工作底图", "^C^C_openMainDwg ", "ID_openMainDwg", "打开工作底图:   openMainDwg", path + "\

  77. \ICO\\open.bmp");
  78.                 cs.AddMacro("加载地形数据", "^C^C_readall ", "ID_readall", "加载地形数据:  readalldwg", path + "\\ICO\

  79. \open1.bmp");
  80.                 cs.AddMacro("加载城市规划图", "^C^C_readall2 ", "ID_readall2", "加载城市规划图:  readalldwg", path + "\\ICO

  81. \\open2.bmp");
  82.                 cs.AddMacro("加载城市管线图", "^C^C_readall3 ", "ID_readall3", "加载城市管线图:  readalldwg", path + "\\ICO

  83. \\open3.bmp");
  84.                 cs.AddMacro("加载其他图形", "^C^C_readall4 ", "ID_readall4", "加载城市管线图:  readdwg", path + "\\ICO\

  85. \open4.bmp");

  86.                 StringCollection sc1 = new StringCollection();
  87.                 sc1.Add("图形管理");
  88.                 //添加名为“我的菜单”的下拉菜单,如果已经存在,则返回null
  89.                 PopMenu myMenu1 = cs.MenuGroup.AddPopMenu("图形管理", sc1, "ID_MyMenu1");

  90.                 if (myMenu1 != null)//如果“我的菜单”还没有被添加,则添加菜单项
  91.                 {
  92.                     //从上到下为“我的菜单”添加绘制直线、多段线、矩形和圆的菜单项
  93.                     myMenu1.AddMenuItem(-1, "打开工作底图", "ID_openMainDwg");
  94.                     myMenu1.AddSeparator(-1);
  95.                     myMenu1.AddMenuItem(-1, "加载地形数据", "ID_readall");
  96.                     myMenu1.AddMenuItem(-1, "加载城市规划图", "ID_readall2");
  97.                     myMenu1.AddMenuItem(-1, "加载城市管线图", "ID_readall3");
  98.                     myMenu1.AddSeparator(-1);
  99.                     myMenu1.AddMenuItem(-1, "加载其他图形", "ID_readall4");
  100.                 }

  101.                
  102.                 cs.SaveAs(cuiFile);
  103.                 //装载CUI文件,注意文件名必须是带路径的
  104.                 //cs.LoadCui(cuitosend);
  105.             }
  106.             catch (System.Exception ex)
  107.             {
  108.                System.Windows .Forms . MessageBox.Show(ex.Message);
  109.             }

  110.         }

  111.     }

  112. }
发表于 2016-1-18 15:01 | 显示全部楼层
你可以看看这里
http://bbs.mjtd.com/thread-113389-1-1.html
直接调用Com库加载定义好的局部Cui文件
 楼主| 发表于 2016-1-19 09:57 | 显示全部楼层
雪山飞狐_lzh 发表于 2016-1-18 15:01
你可以看看这里
http://bbs.mjtd.com/thread-113389-1-1.html
直接调用Com库加载定义好的局部Cui文件

好的,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-3-29 08:51 , Processed in 0.264217 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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