添加项目文件。
This commit is contained in:
198
Sai.RvKits/UIRibbon/DrawingViewApp.cs
Normal file
198
Sai.RvKits/UIRibbon/DrawingViewApp.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Windows;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
using Sai.RvKits.Properties;
|
||||
using Sai.RvKits.RvView;
|
||||
|
||||
using adWin = Autodesk.Windows;
|
||||
|
||||
namespace Sai.RvKits.UIRibbon;
|
||||
|
||||
public class DrawingViewApp
|
||||
{
|
||||
private static readonly string TabName = Properties.Settings.Default.TabName;
|
||||
|
||||
public DrawingViewApp(UIControlledApplication application)
|
||||
{
|
||||
CreateAnnotationsTools(application);
|
||||
RegisterDockPaneAndEvent(application);
|
||||
}
|
||||
|
||||
private readonly ActionEventHandler zoomElementHandler = new();
|
||||
private void CreateAnnotationsTools(UIControlledApplication application)
|
||||
{
|
||||
var ribbonPanel = application.CreateRibbonPanel(TabName, "视图与出图");
|
||||
|
||||
var autoAlignTags = UIAssist.NewButtonData<AlignTagsCmd>(
|
||||
"对齐标记",
|
||||
Resources.align_tags_32px,
|
||||
Resources.align_tags_16px
|
||||
).SetAvailability<EnableInViewPlan>();
|
||||
var arrangeTags = UIAssist.NewButtonData<ArrangeTagsCmd>(
|
||||
"整理标记",
|
||||
Resources.arrange_tags_32px,
|
||||
Resources.arrange_tags_16px
|
||||
).SetAvailability<EnableInViewPlan>();
|
||||
|
||||
var dim2Line = UIAssist.NewButtonData<DimensionBy2LineCmd>(
|
||||
"双线标注",
|
||||
Resources.two_lines_32px,
|
||||
Resources.two_lines_16px,
|
||||
"选择要标注的两条平行的几何模型边缘线进行标注。"
|
||||
);
|
||||
|
||||
var visibilityControl = UIAssist.NewButtonData<VisibilityControlCmd>(
|
||||
"可见性",
|
||||
Resources.visibility_control_32px,
|
||||
Resources.visibility_control_16px,
|
||||
"可见性控制"
|
||||
).SetAvailability<OnProjectDocument>();
|
||||
var sectionBox = UIAssist.NewButtonData<SectionBoxControllerCmd>(
|
||||
"剖面框",
|
||||
Resources.sectionBox_32px,
|
||||
Resources.sectionBox_16px
|
||||
);
|
||||
var filter = UIAssist.NewButtonData<CivilViewFilterCmd>(
|
||||
"过滤器",
|
||||
Resources.filter_32px,
|
||||
Resources.filter_16px,
|
||||
"创建当前视图的结构模型区分的过滤"
|
||||
);
|
||||
|
||||
var panelSchedule = UIAssist.NewButtonData<PanelScheduleCmd>(
|
||||
"铺砖明细表",
|
||||
Resources.schedule_32px,
|
||||
Resources.schedule_16px
|
||||
);
|
||||
var exportSchedulesPbd = UIAssist.NewButtonData<ExportSchedulesCmd>(
|
||||
"导出明细表",
|
||||
Resources.export_excel_32px,
|
||||
Resources.export_excel_16px,
|
||||
"导出明细表为Excel文件"
|
||||
);
|
||||
var systemDisplay = UIAssist.NewButtonData<SystemDisplayCmd>(
|
||||
"系统显示",
|
||||
Resources.system_display_32px,
|
||||
Resources.system_display_16px
|
||||
);
|
||||
var viewManager = UIAssist.NewButtonData<ViewManagerCmd>(
|
||||
"视图管理",
|
||||
Resources.view_manager_32px,
|
||||
Resources.view_manager_16px
|
||||
);
|
||||
var quickViewSection = UIAssist.NewButtonData<QuickViewSectionCmd>(
|
||||
"快速剖面",
|
||||
Resources.view_section_32px,
|
||||
Resources.view_section_16px
|
||||
);
|
||||
var elementsControlCmd = UIAssist.NewButtonData<ElementsControlCmd>(
|
||||
"元素控制",
|
||||
Resources.open_pane_32px,
|
||||
Resources.open_pane_32px,
|
||||
"元素菜单控制"
|
||||
);
|
||||
|
||||
ribbonPanel.AddStackedItems(dim2Line, autoAlignTags, arrangeTags);
|
||||
ribbonPanel.AddStackedItems(visibilityControl, sectionBox, filter);
|
||||
//ribbonPanel.AddSplitButton(splitBtn1, dim2Line, autoAlignTags, arrangeTags);
|
||||
|
||||
ribbonPanel.AddItem(elementsControlCmd);
|
||||
var tab = ComponentManager.Ribbon.Tabs.First(t => t.Name == TabName);
|
||||
ribbonPanel.AddStackedItems(systemDisplay, viewManager, quickViewSection);
|
||||
CreateToggleButton(tab, "视图与出图");
|
||||
//面板下拉展开
|
||||
ribbonPanel.AddSlideOut();
|
||||
ribbonPanel.AddStackedItems(panelSchedule, exportSchedulesPbd);
|
||||
|
||||
//SplitButtonData splitBtn3 = new(nameof(splitBtn3), "显示设置");
|
||||
//ribbonPanel.AddPushButton<SystemDisplayCmd>("系统显示", Resources.system_display_32px, "系统显示");
|
||||
//ribbonPanel.AddPushButton<ViewManagerCmd>("视图管理", Resources.view_manager_32px, "视图管理");
|
||||
}
|
||||
|
||||
private void CreateToggleButton(Autodesk.Windows.RibbonTab rt, string panelName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var panel = rt.Panels.FirstOrDefault(p => p.Source.Name == panelName);
|
||||
var tog = new Autodesk.Windows.RibbonToggleButton()
|
||||
{
|
||||
LargeImage = Resources.zoom_32px.ToBitmapSource(),
|
||||
Size = RibbonItemSize.Large,
|
||||
Name = "ZoomElement",
|
||||
Text = "最大化",
|
||||
ShowText = true,
|
||||
ToolTip = "根据视图的图元是否可见,在切换视图时,对当前选中的图元进行快速缩放定位",
|
||||
IsCheckable = true,
|
||||
Orientation = System.Windows.Controls.Orientation.Vertical,
|
||||
};
|
||||
tog.CheckStateChanged += (s, e) =>
|
||||
{
|
||||
zoomElementHandler.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
if (tog.CheckState == true)
|
||||
{
|
||||
uiapp.ViewActivated -= UiApp_ViewActivated;
|
||||
uiapp.ViewActivated += UiApp_ViewActivated;
|
||||
}
|
||||
else
|
||||
{
|
||||
uiapp.ViewActivated -= UiApp_ViewActivated;
|
||||
}
|
||||
});
|
||||
};
|
||||
//Autodesk.Windows.RibbonItemControl
|
||||
panel.Source.Items.Add(tog);
|
||||
tog.IsChecked = true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MessageBox.Show(exception.Message, "错误");
|
||||
}
|
||||
}
|
||||
private static void RegisterDockPaneAndEvent(UIControlledApplication application)
|
||||
{
|
||||
ElementsControlDock pane = new();
|
||||
application.RegisterDockablePane(Variables.PaneId, "元素控制菜单", pane);
|
||||
}
|
||||
private static void UiApp_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sender is not UIApplication uiApp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var uidoc = uiApp.ActiveUIDocument;
|
||||
var elemIdsSelected = uidoc.Selection.GetElementIds();
|
||||
if (uidoc.Selection.GetElementIds().Count != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var elem = uidoc.Document.GetElement(elemIdsSelected.FirstOrDefault());
|
||||
e.CurrentActiveView.ZoomElement(uidoc, elem.Id);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
//if (elem.IsVisible(e.CurrentActiveView))
|
||||
//{
|
||||
// var box = elem.get_BoundingBox(UiDocument.ActiveGraphicalView);
|
||||
// const int extend = 5;
|
||||
// var uiView = UiDocument.GetOpenUIViews().FirstOrDefault(v => v.ViewId == UiDocument.ActiveGraphicalView.Id);
|
||||
// uiView?.ZoomAndCenterRectangle(
|
||||
// box.Min + (extend * box.Min.Normalize()),
|
||||
// box.Max - (extend * box.Min.Normalize())
|
||||
// );
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user