求帮助:关于用代码创建局部CUI文件
主界面就想做成这个样子目前遇到的问题是:
当CAD启动后,调用命令,上面的四个区域都可以创建成功
但当我在void IExtensionApplication.Initialize() 中调用时,②面板能够创建成功,但是①Ribbon面板和③快捷菜单 无法创建,因为
Autodesk.Windows.RibbonControl rc = Autodesk.Windows.ComponentManager.Ribbon;这里rc为null值
感觉最简单的方法,就是如果CAD主界面创建成功后,会触发一个事件,然后获取这个事件就好了。不知道有没有这种事件。
如果用局部CUI的方式做界面,我找了几天的资料,网上到时有讲菜单写入CUIX的方法,就是没有找到怎么讲Ribbon面板写入CUIX文件,并且后续的快捷菜单,和工作空间也不知道怎么搞了。
求帮助啊!
附上生成Ribbon的代码
#region 添加功能区菜单
public void AddRibbon()
{
Autodesk.Windows.RibbonControl rc = GetRibbonControl();
RibbonTab rt = GetRibbonTab("菜单标签", "1");
RibbonPanel rp = GetRibbonPanel("菜单面板");
Autodesk.Windows.RibbonButton rb = GetRibbonButton("菜单按钮", "菜单命令");
rp.Source.Items.Add(rb);
rt.Panels.Add(rp);
rc.Tabs.Add(rt);
}
/// <summary>
/// 获得菜单控制
/// </summary>
/// <returns></returns>
public static Autodesk.Windows.RibbonControl GetRibbonControl()
{
if (Autodesk.Windows.ComponentManager.Ribbon == null)
Autodesk.Windows.ComponentManager.ItemInitialized += new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
return Autodesk.Windows.ComponentManager.Ribbon; //Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl; //
}
/// <summary>
/// 创建菜单标签
/// </summary>
/// <param name="Name">标签名</param>
/// <param name="id">标签ID</param>
/// <returns></returns>
public static RibbonTab GetRibbonTab(string Name, string id)
{
RibbonTab ribTab = new Autodesk.Windows.RibbonTab();
ribTab.Title = Name;
ribTab.Id = id;
ribTab.IsActive = true;
return ribTab;
}
/// <summary>
/// 创建菜单面板
/// </summary>
/// <param name="Title">面板名</param>
/// <returns></returns>
public static RibbonPanel GetRibbonPanel(string Title)
{
Autodesk.Windows.RibbonPanelSource ribSourcePanel = new Autodesk.Windows.RibbonPanelSource(); // Autodesk.Windows
ribSourcePanel.Title = Title;//now the panel
RibbonPanel ribPanel = new RibbonPanel();
ribPanel.Source = ribSourcePanel;
return ribPanel;
}
/// <summary>
/// 创建菜单按钮
/// </summary>
/// <param name="btName">按钮名</param>
/// <param name="cmdName">命令名</param>
/// <returns></returns>
public static Autodesk.Windows.RibbonButton GetRibbonButton(string btName, string cmdName)
{
Autodesk.Windows.RibbonButton ribButton = new Autodesk.Windows.RibbonButton();
ribButton.Text = btName;//按钮名称
ribButton.CommandParameter = "HelloWorld";//修改的这里//cmdName;执行的命令名称
ribButton.ShowText = true;
ribButton.CommandHandler = new AdskCommandHandler();
return ribButton;
}
/// <summary>
/// 用于激活菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
if (Autodesk.Windows.ComponentManager.Ribbon != null)
Autodesk.Windows.ComponentManager.ItemInitialized -= new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
建议直接做成cui文件加载 飞狐版主有关于局部Cui的代码吗,我在网上找了几天了,只找到了关于 MenuGroup的代码,而快捷菜单等的代码都没有
我通过另外一种方式解决了这个问题,共享一下
void IExtensionApplication.Initialize()
{
Autodesk.Windows.ComponentManager.ItemInitialized += c1.Initialed;//在这里注册一个事件
}在这里事件响应这么写publicvoid Initialed(object sender,RibbonItemEventArgs args)
{
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
AddRibbon();
AddPalette();
Autodesk.Windows.ComponentManager.ItemInitialized -= Initialed;
}
}
页:
[1]