c#.net二次開發浩辰CAD2020時候,找不到加載CUI文件相關的接口
之前在Auto Cad時候是在Acui.dll里,我試了gcui.dll,但是引用失敗,請幫忙解決下問問,萬分感謝
using GrxCAD.Customization;
using GrxCAD.ApplicationServices;
using GrxCAD.EditorInput;
using System.Collections.Specialized;
using System.IO;
namespace GstarCadTools
{
///
/// 操作CUI的類
///
public static class CUITools
{
private static Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
///
/// 獲取并打開主CUI文件
///
/// AutoCAD文檔對象
/// 返回主CUI文件
public static CustomizationSection GetMainCustomizationSection(this Document doc)
{
//獲得主CUI文件所在的位置
string mainCuiFile = Application.GetSystemVariable("MENUNAME") + ".cuix";
//打開主CUI文件
return new CustomizationSection(mainCuiFile);
}
///
/// 創建局部CUI文件
///
/// AutoCAD文檔對象
/// CUI文件名
/// 菜單組的名稱
/// 返回創建的CUI文件
public static CustomizationSection AddCui(this Document doc, string cuiFile, string menuGroupName)
{
CustomizationSection cs;//聲明CUI文件對象
if (!File.Exists(cuiFile))//如果要創建的文件不存在
{
cs = new CustomizationSection();//創建CUI文件對象
cs.MenuGroupName = menuGroupName;//指定菜單組名稱
cs.SaveAs(cuiFile);//保存CUI文件
}
//如果已經存在指定的CUI文件,則打開該文件
else cs = new CustomizationSection(cuiFile);
return cs;//返回CUI文件對象
}
///
/// 裝載指定的局部CUI文件
///
/// CUI文件
public static void LoadCui(this CustomizationSection cs)
{
//Application.SetSystemVariable("CMDECHO", 0);
//設置FILEDIA=0,禁止顯示文件對話框,這樣可以通過程序輸入文件名
Application.SetSystemVariable("FILEDIA", 0);
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
if (cs.IsModified) cs.Save();//如果CUI文件被修改,則保存
//設置CMDECHO=0,控制不在命令行上回顯提示和輸入信息
Application.SetSystemVariable("menubar", 1);
////獲取當前活動文檔
Document doc = Application.DocumentManager.MdiActiveDocument;
CustomizationSection mainCs = doc.GetMainCustomizationSection();
//如果已存在局部CUI文件,則先卸載
if (mainCs.PartialCuiFiles.Contains(cs.CUIFileName))
doc.SendStringToExecute("_.cuiunload " + cs.CUIFileBaseName + " ", false, false, false);
//裝載CUI文件,注意文件名必須是帶路徑的
doc.SendStringToExecute("_.cuiload " + cs.CUIFileName + " ", false, false, false);
//恢復CMDECHO及FILEDIA系統變量的初始值
doc.SendStringToExecute("(setvar \"FILEDIA\" " + 1 + ")(princ) ", false, false, false);
//doc.SendStringToExecute("(setvar \"CMDECHO\" " + 1 + ")(princ) ", false, false, false);
}
///
/// 添加菜單項所要執行的宏
///
/// CUI文件
/// 宏的顯示名稱
/// 宏的具體命令
/// 宏的標識符
/// 宏的狀態欄提示信息
/// 宏的圖標
/// 返回創建的宏
public static MenuMacro AddMacro(this CustomizationSection source, string name, string command, string tag, string helpString, string imagePath)
{
MenuGroup menuGroup = source.MenuGroup;//獲取CUI文件中的菜單組
//判斷菜單組中是否已經定義與菜單組名相同的宏集合
MacroGroup mg = menuGroup.FindMacroGroup(menuGroup.Name);
if (mg == null)//如果宏集合沒有定義,則創建一個與菜單組名相同的宏集合
mg = new MacroGroup(menuGroup.Name, menuGroup);
//如果已經宏已經被定義,則返回
foreach (MenuMacro macro in mg.MenuMacros)
if (macro.ElementID == tag) return null;
//在宏集合中創建一個命令宏
MenuMacro MenuMacro = new MenuMacro(mg, name, command, tag);
//指定命令宏的說明信息,在狀態欄中顯示
MenuMacro.macro.HelpString = helpString;
//指定命令宏的大小圖像的路徑
MenuMacro.macro.LargeImage = MenuMacro.macro.SmallImage = imagePath;
return MenuMacro;//返回命令宏
}
///
/// 添加下拉菜單
///
/// 包含菜單的菜單組
/// 菜單名
/// 菜單的別名
/// 菜單的標識字符串
/// 返回下拉菜單對象
public static PopMenu AddPopMenu(this MenuGroup menuGroup, string name, StringCollection aliasList, string tag)
{
PopMenu pm = null;//聲明下拉菜單對象
//如果菜單組中沒有名稱為name的下拉菜單
if (menuGroup.PopMenus.IsNameFree(name))
{
//為下拉菜單指定顯示名稱、別名、標識符和所屬的菜單組
pm = new PopMenu(name, aliasList, tag, menuGroup);
}
return pm;//返回下拉菜單對象
}
///
/// 為菜單添加菜單項
///
/// 菜單項所屬的菜單
/// 菜單項的位置
/// 菜單項的顯示名稱
/// 菜單項的命令宏的Id
/// 返回添加的菜單項
public static PopMenuItem AddMenuItem(this PopMenu parentMenu, string macroId)
{
PopMenuItem newPmi = null;
//定義一個菜單項對象,指定所屬的菜單及位置
////如果name不為空,則指定菜單項的顯示名為name,否則會使用命令宏的名稱
newPmi = new PopMenuItem(parentMenu, -1);
newPmi.MacroID = macroId;
return newPmi;//返回菜單項對象
}
///
/// 為下拉菜單添加子菜單
///
/// 下拉菜單
/// 子菜單的位置
/// 子菜單的顯示名稱
/// 子菜單的標識字符串
/// 返回添加的子菜單
public static PopMenu AddSubMenu(this PopMenu parentMenu, int index, string name, string tag)
{
PopMenu pm = null;//聲明子菜單對象(屬于下拉菜單類)
//如果菜單組中沒有名稱為name的下拉菜單
if (parentMenu.CustomizationSection.MenuGroup.PopMenus.IsNameFree(name))
{
StringCollection Str = new StringCollection();
//為子菜單指定顯示名稱、標識符和所屬的菜單組,別名設為null
pm = new PopMenu(name, Str, tag, parentMenu.CustomizationSection.MenuGroup);
//為子菜單指定其所屬的菜單
PopMenuRef menuRef = new PopMenuRef(pm, parentMenu, index);
}
return pm;//返回子菜單對象
}
///
/// 為菜單添加分隔條
///
/// 下拉菜單
/// 分隔條的位置
/// 返回添加的分隔條
public static PopMenuItem AddSeparator(this PopMenu parentMenu, int index)
{
//定義一個分隔條并返回
return new PopMenuItem(parentMenu, index);
}
///
/// 添加工具欄
///
/// 工具欄所屬的菜單組
/// 工具欄的顯示名稱
/// 返回添加的工具欄
public static Toolbar AddToolbar(this MenuGroup menuGroup, string name)
{
Toolbar tb = null;//聲明一個工具欄對象
//如果菜單組中沒有名稱為name的工具欄
if (menuGroup.Toolbars.IsNameFree(name))
{
//為工具欄指定顯示名稱和所屬的菜單組
tb = new Toolbar(name, menuGroup);
//設置工具欄為浮動工具欄
tb.ToolbarOrient = ToolbarOrient.floating;
//設置工具欄可見
tb.ToolbarVisible = ToolbarVisible.show;
}
return tb;//返回工具欄對象
}
///
/// 向工具欄添加按鈕
///
/// 按鈕所屬的工具欄
/// 按鈕在工具欄上的位置
/// 按鈕的顯示名稱
/// 按鈕的命令宏的Id
/// 返回工具欄按鈕對象
public static ToolbarButton AddToolbarButton(this Toolbar parent, int index, string name, string macroId)
{
//創建一個工具欄按鈕對象,指定其命令宏Id、顯示名稱、所屬的工具欄和位置
ToolbarButton button = new ToolbarButton(macroId, name, parent, index);
return button;//返回工具欄按鈕對象
}
///
/// 向工具欄添加彈出式工具欄
///
/// 工具欄所屬的父工具欄
/// 彈出式工具欄在父工具欄上的位置
/// 彈出式工具欄所引用的工具欄
public static void AttachToolbarToFlyout(this Toolbar parent, int index, Toolbar toolbarRef)
{
//創建一個彈出式工具欄,指定其所屬的工具欄和位置
ToolbarFlyout flyout = new ToolbarFlyout(parent, index);
//指定彈出式工具欄所引用的工具欄
flyout.ToolbarReference = toolbarRef.Name;
//引用的工具欄初始狀態不可見
toolbarRef.ToolbarVisible = ToolbarVisible.hide;
}
}
}
沒有找到相關結果
已邀請:
1 個回復
CAD小蘇 - 專注所以信賴!
贊同來自:
這個問題二次開發人員已經通過郵件回復您了