多项功能优化
This commit is contained in:
@@ -13,58 +13,58 @@ namespace Sai.RvKits.UIRibbon;
|
||||
|
||||
public class FamilyApp
|
||||
{
|
||||
public FamilyApp(UIControlledApplication application, UIApplication uiapp)
|
||||
{
|
||||
Items = new ObservableCollection<FamilyModel>();
|
||||
uiapp.Application.DocumentChanged += Application_DocumentChanged;
|
||||
uiapp.Application.DocumentClosed += Application_DocumentClosed;
|
||||
//uiapp.Application.FamilyLoadedIntoDocument += Application_FamilyLoadedIntoDocument;
|
||||
CreateFamilyUI(application);
|
||||
public FamilyApp(UIControlledApplication application, UIApplication uiapp)
|
||||
{
|
||||
Items = new ObservableCollection<FamilyModel>();
|
||||
uiapp.Application.DocumentChanged += Application_DocumentChanged;
|
||||
uiapp.Application.DocumentClosed += Application_DocumentClosed;
|
||||
//uiapp.Application.FamilyLoadedIntoDocument += Application_FamilyLoadedIntoDocument;
|
||||
CreateFamilyUI(application);
|
||||
|
||||
CreateRecentPanel();
|
||||
BindingData();
|
||||
this.uiapp = uiapp;
|
||||
}
|
||||
CreateRecentPanel();
|
||||
BindingData();
|
||||
this.uiapp = uiapp;
|
||||
}
|
||||
|
||||
//private void Application_FamilyLoadedIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadedIntoDocumentEventArgs e)
|
||||
//{
|
||||
// Document doc = e.Document;
|
||||
// var existedFamilyIds = Items.Select(i => i.ReferenceFamily).Cast<Family>().Select(f => f.Id).ToList();
|
||||
// var i = existedFamilyIds.IndexOf(e.OriginalFamilyId);
|
||||
// if (i == -1)
|
||||
// {
|
||||
// var family = doc.GetElement(e.NewFamilyId) as Family;
|
||||
// var symbol = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
// var bitmapsymbol?.GetPreviewImage(new System.Drawing.Size(56, 56)).ToBitmapImage();
|
||||
// Items.Insert(0, new FamilyModel
|
||||
// {
|
||||
// Title = e.FamilyName,
|
||||
// ReferenceFamily = family,
|
||||
// $"布置 {e.FamilyName}",
|
||||
// uiApplication = uiapp,
|
||||
// BitmapbitmapImage
|
||||
// });
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Items.Move(i, 0);
|
||||
// }
|
||||
//}
|
||||
//private void Application_FamilyLoadedIntoDocument(object sender, Autodesk.Revit.DB.Events.FamilyLoadedIntoDocumentEventArgs e)
|
||||
//{
|
||||
// Document doc = e.Document;
|
||||
// var existedFamilyIds = Items.Select(i => i.ReferenceFamily).Cast<Family>().Select(f => f.Id).ToList();
|
||||
// var i = existedFamilyIds.IndexOf(e.OriginalFamilyId);
|
||||
// if (i == -1)
|
||||
// {
|
||||
// var family = doc.GetElement(e.NewFamilyId) as Family;
|
||||
// var symbol = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
// var bitmapsymbol?.GetPreviewImage(new System.Drawing.Size(56, 56)).ToBitmapImage();
|
||||
// Items.Insert(0, new FamilyModel
|
||||
// {
|
||||
// Title = e.FamilyName,
|
||||
// ReferenceFamily = family,
|
||||
// $"布置 {e.FamilyName}",
|
||||
// uiApplication = uiapp,
|
||||
// BitmapbitmapImage
|
||||
// });
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Items.Move(i, 0);
|
||||
// }
|
||||
//}
|
||||
|
||||
private const string VbPanelName = "族工具";
|
||||
private const string VbRecentPanelName = "最近使用";
|
||||
private const string VbPanelName = "族工具";
|
||||
private const string VbRecentPanelName = "最近使用";
|
||||
|
||||
//获取Ribbon类所在的通用类库目录
|
||||
private static readonly string TabName = Properties.Settings.Default.TabName;
|
||||
private readonly UIApplication uiapp;
|
||||
//获取Ribbon类所在的通用类库目录
|
||||
private static readonly string TabName = Properties.Settings.Default.TabName;
|
||||
private readonly UIApplication uiapp;
|
||||
|
||||
public ObservableCollection<FamilyModel> Items { get; set; }
|
||||
public ObservableCollection<FamilyModel> Items { get; set; }
|
||||
|
||||
private static bool IsFitting(FamilyInstance instance)
|
||||
{
|
||||
var category = instance.Category;
|
||||
if (category != null)
|
||||
{
|
||||
private static bool IsFitting(FamilyInstance instance)
|
||||
{
|
||||
var category = instance.Category;
|
||||
if (category != null)
|
||||
{
|
||||
#if REVIT2018 || REVIT2020
|
||||
var builtIncategory = (BuiltInCategory)category.Id.IntegerValue;
|
||||
#elif REVIT2025
|
||||
@@ -73,137 +73,137 @@ public class FamilyApp
|
||||
//var name = Enum.Parse(typeof(BuiltInCategory), .ToString());
|
||||
|
||||
var name = Enum.GetName(typeof(BuiltInCategory), builtIncategory);
|
||||
if (name.Contains("Fitting"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (name.Contains("Fitting"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
|
||||
{
|
||||
var doc = e.GetDocument();
|
||||
ElementClassFilter instanceClass = new(typeof(FamilyInstance));
|
||||
var elementIds = e.GetAddedElementIds(instanceClass);
|
||||
private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
|
||||
{
|
||||
var doc = e.GetDocument();
|
||||
ElementClassFilter instanceClass = new(typeof(FamilyInstance));
|
||||
var elementIds = e.GetAddedElementIds(instanceClass);
|
||||
//e.GetTransactionNames()
|
||||
//elementIds.AddRange(e.GetModifiedElementIds());
|
||||
if (elementIds.Any())
|
||||
{
|
||||
var elems = elementIds.ToList().ConvertAll(id => doc.GetElement(id)).OfType<FamilyInstance>();
|
||||
var instances = elems.Where(instance => !IsFitting(instance));
|
||||
var existedFamilyIds = Items.Select(i => i.ReferenceFamily).Select(f => f.Id).ToList();
|
||||
var instanceGroups = instances.GroupBy(ins => ins.Symbol.Family.Id);
|
||||
foreach (var grouping in instanceGroups)
|
||||
{
|
||||
var familyId = grouping.Key;
|
||||
var i = existedFamilyIds.IndexOf(familyId);
|
||||
if (i == -1)
|
||||
{
|
||||
NewGalleryItem(doc, familyId);
|
||||
}
|
||||
//不在第一位则新建到第一位
|
||||
else if (i > 0)
|
||||
{
|
||||
Items.RemoveAt(i);
|
||||
NewGalleryItem(doc, familyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (elementIds.Count > 0)
|
||||
{
|
||||
var elems = elementIds.Select(doc.GetElement).OfType<FamilyInstance>();
|
||||
var instances = elems.Where(instance => !IsFitting(instance));
|
||||
var existedFamilyIds = Items.Select(i => i.ReferenceFamily).Select(f => f.Id).ToList();
|
||||
var instanceGroups = instances.GroupBy(ins => ins.Symbol.Family.Id);
|
||||
foreach (var grouping in instanceGroups)
|
||||
{
|
||||
var familyId = grouping.Key;
|
||||
var i = existedFamilyIds.IndexOf(familyId);
|
||||
if (i == -1)
|
||||
{
|
||||
NewGalleryItem(doc, familyId);
|
||||
}
|
||||
//不在第一位则新建到第一位
|
||||
else if (i > 0)
|
||||
{
|
||||
Items.RemoveAt(i);
|
||||
NewGalleryItem(doc, familyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//foreach (var elementFunc in instances)
|
||||
//{
|
||||
// if (!(elementFunc is FamilyInstance instance)) continue;
|
||||
// var family = instance.Symbol.Family;
|
||||
// var symbolId = family?.GetFamilySymbolIds().FirstOrDefault();
|
||||
// var symbol = doc.GetElement(symbolId) as FamilySymbol;
|
||||
// var bitmapsymbol?.GetPreviewImage(new System.Drawing.Size(56, 56)).ConvertBitmapToBitmapImage();
|
||||
//foreach (var elementFunc in instances)
|
||||
//{
|
||||
// if (!(elementFunc is FamilyInstance instance)) continue;
|
||||
// var family = instance.Symbol.Family;
|
||||
// var symbolId = family?.GetFamilySymbolIds().FirstOrDefault();
|
||||
// var symbol = doc.GetElement(symbolId) as FamilySymbol;
|
||||
// var bitmapsymbol?.GetPreviewImage(new System.Drawing.Size(56, 56)).ConvertBitmapToBitmapImage();
|
||||
|
||||
|
||||
// Items.Insert(0, new FamilyModel
|
||||
// {
|
||||
// Title = family?.Name,
|
||||
// ReferenceFamily = family,
|
||||
// $"布置{family?.Name}",
|
||||
// uiApplication = uiApplication,
|
||||
// BitmapbitmapImage
|
||||
// });
|
||||
//}
|
||||
}
|
||||
// Items.Insert(0, new FamilyModel
|
||||
// {
|
||||
// Title = family?.Name,
|
||||
// ReferenceFamily = family,
|
||||
// $"布置{family?.Name}",
|
||||
// uiApplication = uiApplication,
|
||||
// BitmapbitmapImage
|
||||
// });
|
||||
//}
|
||||
}
|
||||
|
||||
private void Application_DocumentClosed(object sender, Autodesk.Revit.DB.Events.DocumentClosedEventArgs e)
|
||||
{
|
||||
Items.Clear();
|
||||
}
|
||||
private void Application_DocumentClosed(object sender, Autodesk.Revit.DB.Events.DocumentClosedEventArgs e)
|
||||
{
|
||||
Items.Clear();
|
||||
}
|
||||
|
||||
private void BindingData()
|
||||
{
|
||||
var adTab = ComponentManager.Ribbon.Tabs.First(o => o.Title == TabName);
|
||||
var adPanel = adTab.Panels.First(o => o.Source.Title == VbRecentPanelName);
|
||||
var gallery = adPanel.Source.Items.First() as RibbonGallery;
|
||||
gallery!.ItemWidth = 56;
|
||||
gallery.ItemHeight = 56;
|
||||
gallery.ResizeStyle = RibbonItemResizeStyles.ChangeSize;
|
||||
gallery.DisplayMode = GalleryDisplayMode.Window;
|
||||
gallery.ResizableBoxWidth = 0.0;
|
||||
gallery.IsVirtualizing = true;
|
||||
gallery.RowsInWindowMode = 1;
|
||||
gallery.ShowImage = true;
|
||||
gallery.MinWidth = 400;
|
||||
var resourceLocator = new Uri("Sai.RvKits;component/WPFUI.xaml", UriKind.Relative);
|
||||
var dictionary = (ResourceDictionary)Application.LoadComponent(resourceLocator);
|
||||
private void BindingData()
|
||||
{
|
||||
var adTab = ComponentManager.Ribbon.Tabs.First(o => o.Title == TabName);
|
||||
var adPanel = adTab.Panels.First(o => o.Source.Title == VbRecentPanelName);
|
||||
var gallery = adPanel.Source.Items.First() as RibbonGallery;
|
||||
gallery!.ItemWidth = 56;
|
||||
gallery.ItemHeight = 56;
|
||||
gallery.ResizeStyle = RibbonItemResizeStyles.ChangeSize;
|
||||
gallery.DisplayMode = GalleryDisplayMode.Window;
|
||||
gallery.ResizableBoxWidth = 0.0;
|
||||
gallery.IsVirtualizing = true;
|
||||
gallery.RowsInWindowMode = 1;
|
||||
gallery.ShowImage = true;
|
||||
gallery.MinWidth = 400;
|
||||
var resourceLocator = new Uri("Sai.RvKits;component/WPFUI.xaml", UriKind.Relative);
|
||||
var dictionary = (ResourceDictionary)Application.LoadComponent(resourceLocator);
|
||||
|
||||
gallery.ItemTemplate = (DataTemplate)dictionary["FamilyGalleryItemTemplate"];
|
||||
//绑定数据
|
||||
gallery.ItemsBinding = new System.Windows.Data.Binding
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath(nameof(Items)),
|
||||
//Source = Items,
|
||||
Mode = System.Windows.Data.BindingMode.OneWay
|
||||
};
|
||||
//绑定样式
|
||||
}
|
||||
gallery.ItemTemplate = (DataTemplate)dictionary["FamilyGalleryItemTemplate"];
|
||||
//绑定数据
|
||||
gallery.ItemsBinding = new System.Windows.Data.Binding
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath(nameof(Items)),
|
||||
//Source = Items,
|
||||
Mode = System.Windows.Data.BindingMode.OneWay
|
||||
};
|
||||
//绑定样式
|
||||
}
|
||||
|
||||
public void CreateFamilyUI(UIControlledApplication application)
|
||||
{
|
||||
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
public void CreateFamilyUI(UIControlledApplication application)
|
||||
{
|
||||
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
|
||||
//application.CreateRibbonTab(TabName);
|
||||
//application.CreateRibbonTab(TabName);
|
||||
|
||||
//UserPanel.AddAwItem(_loginPBData);
|
||||
//".\\*.*"中的“.”表示通用类库文件所在的目录(Debug),“..”表示的是上级的目录(bin),“..”\\..,引号表示再上一级目录
|
||||
//ContextualHelp contextualHelp = new ContextualHelp(ContextualHelpType.Url, "https://www.szmedi.com.cn");
|
||||
//_loginPBData.CreateContextualHelp(contextualHelp);
|
||||
//UserPanel.AddAwItem(_loginPBData);
|
||||
//".\\*.*"中的“.”表示通用类库文件所在的目录(Debug),“..”表示的是上级的目录(bin),“..”\\..,引号表示再上一级目录
|
||||
//ContextualHelp contextualHelp = new ContextualHelp(ContextualHelpType.Url, "https://www.szmedi.com.cn");
|
||||
//_loginPBData.CreateContextualHelp(contextualHelp);
|
||||
|
||||
var familyManagePanel = application.CreateRibbonPanel(TabName, VbPanelName);
|
||||
var familyManagePanel = application.CreateRibbonPanel(TabName, VbPanelName);
|
||||
|
||||
//在面板上添加添加浏览族库按钮
|
||||
var localFamilyPbd = UIAssist.NewPushButtonData<FamilyLibraryCmd>(
|
||||
"本地族库",
|
||||
Resources.library_32px,
|
||||
Resources.library_16px
|
||||
);
|
||||
//在面板上添加添加浏览族库按钮
|
||||
var localFamilyPbd = UIAssist.NewPushButtonData<FamilyLibraryCmd>(
|
||||
"本地族库",
|
||||
Resources.library_32px,
|
||||
Resources.library_16px
|
||||
);
|
||||
|
||||
|
||||
var familyMassSave = UIAssist.NewPushButtonData<FamilyProcessorCmd>(
|
||||
"族复用",
|
||||
Resources.family_processor_32px,
|
||||
Resources.family_processor_16px
|
||||
);
|
||||
var replaceInstance = UIAssist.NewPushButtonData<ReplaceInstanceCmd>(
|
||||
"替换族",
|
||||
Resources.replace_32px,
|
||||
Resources.replace_16px
|
||||
);
|
||||
var familyMassSave = UIAssist.NewPushButtonData<FamilyProcessorCmd>(
|
||||
"族复用",
|
||||
Resources.family_processor_32px,
|
||||
Resources.family_processor_16px
|
||||
);
|
||||
var replaceInstance = UIAssist.NewPushButtonData<ReplaceInstanceCmd>(
|
||||
"替换族",
|
||||
Resources.replace_32px,
|
||||
Resources.replace_16px
|
||||
);
|
||||
|
||||
var updateFamilyFile = UIAssist.NewPushButtonData<UpgradeFamilyCmd>(
|
||||
"更新族",
|
||||
Resources.available_updates_32px,
|
||||
Resources.available_updates_16px,
|
||||
"更新族文件缩略图及升级至当前版本"
|
||||
);
|
||||
var updateFamilyFile = UIAssist.NewPushButtonData<UpgradeFamilyCmd>(
|
||||
"更新族",
|
||||
Resources.available_updates_32px,
|
||||
Resources.available_updates_16px,
|
||||
"更新族文件缩略图及升级至当前版本"
|
||||
);
|
||||
|
||||
var renameFamily = UIAssist.NewPushButtonData<RenameFamilyNameCmd>(
|
||||
"重命名族",
|
||||
@@ -219,37 +219,37 @@ public class FamilyApp
|
||||
familyManagePanel.AddItem(localFamilyPbd);
|
||||
familyManagePanel.AddStackedItems(familyMassSave, replaceInstance, updateFamilyFile);
|
||||
familyManagePanel.AddStackedItems(renameFamily, renameType);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateRecentPanel()
|
||||
{
|
||||
var adTab = ComponentManager.Ribbon.Tabs.First(o => o.Title == TabName);
|
||||
var recentPanel = new Autodesk.Windows.RibbonPanel
|
||||
{
|
||||
Source = new RibbonPanelSource { Title = VbRecentPanelName }
|
||||
};
|
||||
private static void CreateRecentPanel()
|
||||
{
|
||||
var adTab = ComponentManager.Ribbon.Tabs.First(o => o.Title == TabName);
|
||||
var recentPanel = new Autodesk.Windows.RibbonPanel
|
||||
{
|
||||
Source = new RibbonPanelSource { Title = VbRecentPanelName }
|
||||
};
|
||||
|
||||
adTab.Panels.Insert(adTab.Panels.Count, recentPanel);
|
||||
adTab.Panels.Insert(adTab.Panels.Count, recentPanel);
|
||||
|
||||
recentPanel.Source.Items.Add(new RibbonGallery { Name = "_ribbonGallery_recent" });
|
||||
recentPanel.IsVisible = true;
|
||||
}
|
||||
recentPanel.Source.Items.Add(new RibbonGallery { Name = "_ribbonGallery_recent" });
|
||||
recentPanel.IsVisible = true;
|
||||
}
|
||||
|
||||
private void NewGalleryItem(Document doc, ElementId familyId)
|
||||
{
|
||||
var family = doc.GetElement(familyId) as Family;
|
||||
var symbol = doc.GetElement(family!.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
var bitmap = symbol?.GetPreviewImage(new System.Drawing.Size(50, 50)).ToBitmapImage();
|
||||
Items.Insert(
|
||||
0,
|
||||
new FamilyModel
|
||||
{
|
||||
ReferenceFamily = family,
|
||||
Title = family.Name,
|
||||
UiApplication = uiapp,
|
||||
BitmapImage = bitmap,
|
||||
ToolTip = $"布置:{family.Name}\n\r所属文档:{family.Document.Title}",
|
||||
}
|
||||
);
|
||||
}
|
||||
private void NewGalleryItem(Document doc, ElementId familyId)
|
||||
{
|
||||
var family = doc.GetElement(familyId) as Family;
|
||||
var symbol = doc.GetElement(family!.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
||||
var bitmap = symbol?.GetPreviewImage(new System.Drawing.Size(50, 50)).ToBitmapImage();
|
||||
Items.Insert(
|
||||
0,
|
||||
new FamilyModel
|
||||
{
|
||||
ReferenceFamily = family,
|
||||
Title = family.Name,
|
||||
UiApplication = uiapp,
|
||||
BitmapImage = bitmap,
|
||||
ToolTip = $"布置:{family.Name}\n\r所属文档:{family.Document.Title}",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Windows.Controls;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Controls;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
@@ -40,10 +41,11 @@ public class ModifyTabApp
|
||||
{
|
||||
case AlignType.Left:
|
||||
{
|
||||
var farthestAlign = alignElements.OrderBy(x => x.UpLeft.X).FirstOrDefault();
|
||||
//最左的元素
|
||||
var leftAlignElement = alignElements.OrderBy(x => x.UpLeft.X).FirstOrDefault();
|
||||
foreach (var alignElement in alignElements)
|
||||
{
|
||||
XYZ resultingPoint = new(farthestAlign.UpLeft.X, alignElement.UpLeft.Y, 0);
|
||||
XYZ resultingPoint = new(leftAlignElement.UpLeft.X, alignElement.UpLeft.Y, 0);
|
||||
alignElement.MoveTo(resultingPoint, AlignType.Left);
|
||||
}
|
||||
|
||||
@@ -52,10 +54,10 @@ public class ModifyTabApp
|
||||
|
||||
case AlignType.Right:
|
||||
{
|
||||
var farthestAlign = alignElements.OrderByDescending(x => x.UpRight.X).FirstOrDefault();
|
||||
var rightAlignElement = alignElements.OrderByDescending(x => x.UpRight.X).FirstOrDefault();
|
||||
foreach (var alignElement in alignElements)
|
||||
{
|
||||
XYZ resultingPoint = new(farthestAlign.UpRight.X, alignElement.UpRight.Y, 0);
|
||||
XYZ resultingPoint = new(rightAlignElement.UpRight.X, alignElement.UpRight.Y, 0);
|
||||
alignElement.MoveTo(resultingPoint, AlignType.Right);
|
||||
}
|
||||
|
||||
@@ -64,10 +66,10 @@ public class ModifyTabApp
|
||||
|
||||
case AlignType.Up:
|
||||
{
|
||||
var farthestAlign = alignElements.OrderByDescending(x => x.UpRight.Y).FirstOrDefault();
|
||||
var upAlignElement = alignElements.OrderByDescending(x => x.UpRight.Y).FirstOrDefault();
|
||||
foreach (var alignElement in alignElements)
|
||||
{
|
||||
XYZ resultingPoint = new(alignElement.UpRight.X, farthestAlign.UpRight.Y, 0);
|
||||
XYZ resultingPoint = new(alignElement.UpRight.X, upAlignElement.UpRight.Y, 0);
|
||||
alignElement.MoveTo(resultingPoint, AlignType.Up);
|
||||
}
|
||||
|
||||
@@ -87,9 +89,9 @@ public class ModifyTabApp
|
||||
case AlignType.HorizontallyCenter: //同一条垂直轴
|
||||
{
|
||||
var sortedElements = alignElements.OrderBy(x => x.UpRight.X).ToList();
|
||||
var rightAlignAnnotation = sortedElements.LastOrDefault();
|
||||
var leftAlignAnnotation = sortedElements.FirstOrDefault();
|
||||
var xCoord = (rightAlignAnnotation.Center.X + leftAlignAnnotation.Center.X) / 2;
|
||||
var rightElement = sortedElements.LastOrDefault();
|
||||
var leftElement = sortedElements.FirstOrDefault();
|
||||
var xCoord = (rightElement.Center.X + leftElement.Center.X) / 2;
|
||||
foreach (var alignElement in sortedElements)
|
||||
{
|
||||
XYZ resultingPoint = new(xCoord, alignElement.Center.Y, 0);
|
||||
@@ -151,8 +153,11 @@ public class ModifyTabApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Align(object obj)
|
||||
/// <summary>
|
||||
/// 对齐命令
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
private void AlignCommand(object obj)
|
||||
{
|
||||
if (obj is not Autodesk.Windows.RibbonButton rb)
|
||||
{
|
||||
@@ -162,11 +167,13 @@ public class ModifyTabApp
|
||||
var alignType = (AlignType)rb.CommandParameter;
|
||||
handler.Raise(_ =>
|
||||
{
|
||||
Document.Invoke(
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
var selectedIds = UIDocument.Selection.GetElementIds();
|
||||
var alignElements = (from id in selectedIds let e = new AlignModelElement(Document.GetElement(id)) select e).ToList();
|
||||
var alignElements = (from id in selectedIds
|
||||
let e = new AlignModelElement(Document.GetElement(id))
|
||||
select e).ToList();
|
||||
//List<AlignModelElement> alignElements = new();
|
||||
//foreach (var id in selectedIds)
|
||||
//{
|
||||
@@ -175,18 +182,23 @@ public class ModifyTabApp
|
||||
//}
|
||||
AlignByType(alignElements, alignType);
|
||||
},
|
||||
alignType.GetDescription()
|
||||
);
|
||||
alignType.GetAttribute<DescriptionAttribute>().Description);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否能进行对齐操作
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool CanAlign()
|
||||
{
|
||||
return UIDocument?.Selection
|
||||
.GetElementIds()
|
||||
.Count(id => Document.GetElement(id) is GenericForm || Document.GetElement(id).Category?.CategoryType == CategoryType.Model) > 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对齐面板
|
||||
/// </summary>
|
||||
/// <param name="tab"></param>
|
||||
private void AlignPanel(RibbonTab tab)
|
||||
{
|
||||
//新建面板
|
||||
@@ -207,7 +219,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,元素左侧对齐",
|
||||
Text = "左对齐",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Left
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -222,7 +234,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,元素右侧对齐",
|
||||
Text = "右对齐",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Right
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -238,7 +250,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,元素底部对齐",
|
||||
Text = "下对齐",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Down
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -253,7 +265,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,元素顶部对齐",
|
||||
Text = "上对齐",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Up
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -268,7 +280,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,水平居中",
|
||||
Text = "水平中",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.HorizontallyCenter
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -283,7 +295,7 @@ public class ModifyTabApp
|
||||
ToolTip = "根据几何元素范围,垂直居中",
|
||||
Text = "垂直中",
|
||||
IsCheckable = true,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.VerticallyCenter
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
@@ -300,7 +312,7 @@ public class ModifyTabApp
|
||||
IsCheckable = true,
|
||||
//默认水平,文字与图标
|
||||
//Orientation = Orientation.Vertical,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Top
|
||||
};
|
||||
var alignMiddleBtn = new Autodesk.Windows.RibbonButton
|
||||
@@ -315,7 +327,7 @@ public class ModifyTabApp
|
||||
Text = "中对齐",
|
||||
IsCheckable = true,
|
||||
//Orientation = Orientation.Vertical,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Middle
|
||||
};
|
||||
var alignBottomBtn = new Autodesk.Windows.RibbonButton
|
||||
@@ -331,7 +343,7 @@ public class ModifyTabApp
|
||||
Text = "底对齐",
|
||||
IsCheckable = true,
|
||||
//Orientation = Orientation.Vertical,
|
||||
CommandHandler = new RelayCommand<object>(Align, _ => CanAlign()),
|
||||
CommandHandler = new RelayCommand<object>(AlignCommand, _ => CanAlign()),
|
||||
CommandParameter = AlignType.Bottom
|
||||
};
|
||||
|
||||
@@ -359,7 +371,10 @@ public class ModifyTabApp
|
||||
alignSource.Items.Add(ribbonRowPanel1);
|
||||
tab.Panels.Add(alignElemsPanel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择元素面板
|
||||
/// </summary>
|
||||
/// <param name="tab"></param>
|
||||
private void SelectionPanel(RibbonTab tab)
|
||||
{
|
||||
//新建面板
|
||||
@@ -509,7 +524,6 @@ public class ModifyTabApp
|
||||
)
|
||||
//Orientation = System.Windows.Controls.Orientation.Vertical
|
||||
};
|
||||
|
||||
//面板按钮
|
||||
Autodesk.Windows.RibbonButton selFilterBtn =
|
||||
new()
|
||||
@@ -526,7 +540,7 @@ public class ModifyTabApp
|
||||
IsCheckable = true,
|
||||
Orientation = Orientation.Vertical,
|
||||
CommandHandler = new RelayCommand(
|
||||
() => WinDialogHelper.ShowModeless<DetailSelectFiltersView>(new DetailSelectFiltersViewModel(uiapp, handler)),
|
||||
() => WinDialogHelper.ShowModeless<DetailSelectFiltersView>(new DetailSelectFiltersViewModel(uiapp, handler)),
|
||||
() =>
|
||||
UIDocument?.Selection
|
||||
.GetElementIds()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
@@ -26,25 +25,29 @@ public class RvApp : ExternalApplication
|
||||
{
|
||||
saveHandler.RaiseAsync(app =>
|
||||
{
|
||||
|
||||
var doc = app.ActiveUIDocument.Document;
|
||||
#if REVIT2018
|
||||
foreach (Autodesk.Revit.DB.Document doc in app.Application.Documents)
|
||||
{
|
||||
if (doc.IsModified && !string.IsNullOrEmpty(doc.PathName))
|
||||
{
|
||||
doc.Save();
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.IsModified && !string.IsNullOrEmpty(doc.PathName))
|
||||
#else
|
||||
foreach (Autodesk.Revit.DB.Document doc in app.Application.Documents)
|
||||
if (!doc.IsBackgroundCalculationInProgress() && doc.IsModified && !string.IsNullOrEmpty(doc.PathName))
|
||||
#endif
|
||||
{
|
||||
if (!doc.IsBackgroundCalculationInProgress() && doc.IsModified&&!string.IsNullOrEmpty(doc.PathName))
|
||||
try
|
||||
{
|
||||
doc.Save();
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
MessageBox.Show("已手动取消本次保存", "提示");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var command = RevitCommandId.LookupPostableCommandId(PostableCommand.Save);
|
||||
app.PostCommand(command);
|
||||
//MessageBox.Show("本次自动保存失败,将重新计时", "提示");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
});
|
||||
}
|
||||
public override void OnStartup()
|
||||
@@ -87,7 +90,7 @@ public class RvApp : ExternalApplication
|
||||
|
||||
if (Properties.Settings.Default.IsActiveAutoSave)
|
||||
{
|
||||
var interval = Properties.Settings.Default.AutoSaveIntervalTime * 60 * 1000;
|
||||
var interval = Properties.Settings.Default.AutoSaveIntervalTime * 60_000;
|
||||
saveTimer.Interval = interval;
|
||||
saveTimer.Elapsed -= OnTimedEvent;
|
||||
saveTimer.Elapsed += OnTimedEvent;
|
||||
@@ -95,6 +98,8 @@ public class RvApp : ExternalApplication
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void CivilApp(UIControlledApplication application)
|
||||
{
|
||||
var ribbonPanel = application.CreateRibbonPanel(TabName, "土建装饰");
|
||||
|
||||
Reference in New Issue
Block a user