Revit擴展組件介紹之_AdWindow


AdWindow.dll是Autodesk開發一套支持Ribbon風格的組件,其在很多Autodesk的產品中得到了大量的應用,我們通過以下案例,介紹AdWindow組件在Revit中應用的基本情況。

在RevitAPI中,對界面通過UIControlledApplication進行了部分的封裝,但封裝后,部分控件的特性並沒有暴漏出來,我們需要更底層的界面操作,比較困難。所以我們可以通過直接訪問界面的AdWindow組件,實現對界面的訪問。通過以下代碼,我們可以直接獲取Revit所有界面的管理類。

Autodesk.Windows.ComponentManager 當前類的屬性截圖如下所示:

ComponentManager 是對Revit界面的綜合管理,其有幾個重要的屬性,每個屬性對應這Revit界面上一個元素,其對用關系如下:

同時,我們可以通過以下事件對Ribbon的改變進行

以下實現在Revit修改面板添加一個按鈕,如下所示:

using Autodesk.Revit.UI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace RevitExapmle { public class HelloWord : IExternalApplication { public Result OnStartup(UIControlledApplication application) { ///在修改面板添加按鈕
Autodesk.Windows.ComponentManager.UIElementActivated += ComponentManager_UIElementActivated; foreach (Autodesk.Windows.RibbonTab tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs) { if (tab.Id == "Modify") { Autodesk.Windows.RibbonPanel newPanel = new Autodesk.Windows.RibbonPanel(); Autodesk.Windows.RibbonPanelSource panelSource = new Autodesk.Windows.RibbonPanelSource(); panelSource.Id = "xiugb"; panelSource.Name = "xiugb"; newPanel.Source = panelSource; Autodesk.Windows.RibbonButton button = new Autodesk.Windows.RibbonButton(); button.ShowImage = true; button.Size = Autodesk.Windows.RibbonItemSize.Large; button.ShowText = true; button.Id = "xiugbc"; button.Name = "xiugbc"; button.Text = "按鈕"; button.IsEnabled = true; button.IsVisible = true; button.IsCheckable = true; button.Orientation = System.Windows.Controls.Orientation.Vertical; newPanel.Source.Items.Add(button); tab.Panels.Add(newPanel); break; } } return Result.Succeeded; } /// <summary>
/// 按鈕的切換事件 /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComponentManager_UIElementActivated(object sender, Autodesk.Windows.UIElementActivatedEventArgs e) { if (e != null && e.Item != null && e.Item.Id != null && e.Item.Id == "ads") { try { //邏輯代碼
} catch { } } } public Result OnShutdown(UIControlledApplication application) { return Result.Succeeded; } } } 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM