93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using ShrlAlgoToolkit.Core.Assists;
|
|
using ShrlAlgoToolkit.Core.Extensions;
|
|
|
|
using System.IO;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.RvFamily.FamilyLibrary;
|
|
|
|
public partial class FamilyModel : ObservableObject
|
|
{
|
|
/// <summary>
|
|
/// 族库缩略图
|
|
/// </summary>
|
|
public BitmapSource ImageData => ImageAssist.LoadFileImage(Path, 128, 128);
|
|
|
|
/// <summary>
|
|
/// 最近使用面板
|
|
/// </summary>
|
|
public BitmapImage BitmapImage { get; set; }
|
|
|
|
public FileInfo FileInfo { get; set; }
|
|
|
|
/// <summary>
|
|
/// 族库文件标题
|
|
/// </summary>
|
|
public string Title { get; set; }
|
|
|
|
public Family ReferenceFamily { get; set; }
|
|
public string ToolTip { get; set; }
|
|
public UIApplication UiApplication { get; set; }
|
|
public string Path { get; set; }
|
|
public string RevitVersion { get; set; }
|
|
public ElementId FamilyId => ReferenceFamily.Id;
|
|
|
|
//private bool CanPlace()
|
|
//{
|
|
// uiApplication.ActiveUIDocument.Document.is
|
|
// return ReferenceFamily.IsValidObject;
|
|
// .IsValidObject = true;
|
|
//}
|
|
|
|
[RelayCommand]
|
|
private static void PlaceRecentFamily(object obj)
|
|
{
|
|
try
|
|
{
|
|
if (obj is FamilyModel { ReferenceFamily: { } family } info)
|
|
{
|
|
var uidoc = info.UiApplication.ActiveUIDocument;
|
|
var doc = uidoc.Document;
|
|
|
|
if (family.IsValidObject && doc.PathName == family.Document.PathName)
|
|
{
|
|
var fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
|
|
uidoc.PostRequestForElementTypePlacement(fs);
|
|
}
|
|
//else
|
|
//{
|
|
// var docs = info.uiApplication.Application.Documents;
|
|
// foreach (Document d in docs)
|
|
// {
|
|
// if (d.PathName == family.Document.PathName)
|
|
// {
|
|
// List<ElementId> list = new List<ElementId>()
|
|
// {
|
|
// family.ViewId
|
|
// };
|
|
// doc.Invoke(ts =>
|
|
// {
|
|
// ElementTransformUtils.CopyElements(d, list, doc, null, new CopyPasteOptions());
|
|
// },"复制族");
|
|
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
//}
|
|
}
|
|
}
|
|
catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }
|
|
catch (Exception e)
|
|
{
|
|
e.ToLog();
|
|
}
|
|
}
|
|
}
|