CUI加载问题
《 VBA & VB.net 第二版》的例子做的CUI,调试状态下加载问题,做成安装包在同一台机器上不能加载代码呢?。。。。。。
程序启动自动加载不了,但是运行命令就可以加载
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Customization;
using System.Collections.Specialized;
using Autodesk.AutoCAD.Windows;
using System;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
//using System.Windows.Forms;
using Autodesk.AutoCAD.Customization;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Geometry;
using System.Drawing;
//
namespace SLCAD
{
public class cadAuto : IExtensionApplication
{
public static string spath = @"E:\6CAD开发\DWG\123.dwg";
public static string outSpath = @"E:\6CAD开发\OUT";
//public static string startpath =Left(Assembly.GetExecutingAssembly.Location, Len
(Reflection.Assembly.GetExecutingAssembly.Location) - 11) ;
//public static DateTime dateTime = DateTime.Now;
public static string dateTimeStr = DateTime.Now.ToString("yyyyMMdd");
//public static string myCuiFile = CUITOOLS.GetCurrentPath() + "\\SLCUI.cui";
//public static string menuGroupName = "SLCUI";//菜单组名
public static CustomizationSection cs = new CustomizationSection();
public void Initialize()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
//在AutoCAD命令行上显示一些信息,它们会在程序载入时被显示
ed.WriteMessage("程序开始初始化。");
m_Palette.showPalette();
comShow.cadShow.ton();
AddMenu();
methodDatabase.getSetValue();
}
public void Terminate()
{
// 在Visual Studio 2010的输出窗口上显示程序结束的信息
System.Diagnostics.Debug.WriteLine(
"程序结束,你可以在里做一些程序的清理工作,如关闭AutoCAD文档");
}
public void openMainDwg()
{
//CloseAllDwgs();
string mainOut = outSpath + dateTimeStr;
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
DocumentCollection docs = AcadApp.DocumentManager;
Document doc = docs.Open(spath, false);
AcadApp.DocumentManager.MdiActiveDocument = doc;
}
//
public static void AddMenu()
{
const string cuiFile = "d:\\slzj.cui";
const string menuGroupName = "Slzj";//菜单组名
const string cuitosend = "d:/slzj.cui";
string path = CUITOOLS.GetCurrentPath();
AcadApp.MainWindow.Text = "XX设计系统";
Autodesk.AutoCAD.Windows.Window mw = Autodesk.AutoCAD.ApplicationServices.Application.MainWindow;
mw.Icon = new Icon(path + "\\images\\2.ico");
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
//CustomizationSection cs = new CustomizationSection();
try
{
//装载局部CUI文件,若不存在,则创建
cs = doc.AddCui(cuiFile, menuGroupName);
//数据图形管理
cs.AddMacro("打开工作底图", "^C^C_openMainDwg ", "ID_openMainDwg", "打开工作底图: openMainDwg", path + "\
\ICO\\open.bmp");
cs.AddMacro("加载地形数据", "^C^C_readall ", "ID_readall", "加载地形数据:readalldwg", path + "\\ICO\
\open1.bmp");
cs.AddMacro("加载城市规划图", "^C^C_readall2 ", "ID_readall2", "加载城市规划图:readalldwg", path + "\\ICO
\\open2.bmp");
cs.AddMacro("加载城市管线图", "^C^C_readall3 ", "ID_readall3", "加载城市管线图:readalldwg", path + "\\ICO
\\open3.bmp");
cs.AddMacro("加载其他图形", "^C^C_readall4 ", "ID_readall4", "加载城市管线图:readdwg", path + "\\ICO\
\open4.bmp");
StringCollection sc1 = new StringCollection();
sc1.Add("图形管理");
//添加名为“我的菜单”的下拉菜单,如果已经存在,则返回null
PopMenu myMenu1 = cs.MenuGroup.AddPopMenu("图形管理", sc1, "ID_MyMenu1");
if (myMenu1 != null)//如果“我的菜单”还没有被添加,则添加菜单项
{
//从上到下为“我的菜单”添加绘制直线、多段线、矩形和圆的菜单项
myMenu1.AddMenuItem(-1, "打开工作底图", "ID_openMainDwg");
myMenu1.AddSeparator(-1);
myMenu1.AddMenuItem(-1, "加载地形数据", "ID_readall");
myMenu1.AddMenuItem(-1, "加载城市规划图", "ID_readall2");
myMenu1.AddMenuItem(-1, "加载城市管线图", "ID_readall3");
myMenu1.AddSeparator(-1);
myMenu1.AddMenuItem(-1, "加载其他图形", "ID_readall4");
}
cs.SaveAs(cuiFile);
//装载CUI文件,注意文件名必须是带路径的
//cs.LoadCui(cuitosend);
}
catch (System.Exception ex)
{
System.Windows .Forms . MessageBox.Show(ex.Message);
}
}
}
} 你可以看看这里
直接调用Com库加载定义好的局部Cui文件
好的,谢谢
页:
[1]