131 lines
4.7 KiB
C#
131 lines
4.7 KiB
C#
|
|
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External.Handlers;
|
|||
|
|
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Windows;
|
|||
|
|
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.FamilyTools
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// PreviewFam.xaml 的交互逻辑
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class PreviewFam
|
|||
|
|
{
|
|||
|
|
private readonly Document doc;
|
|||
|
|
private readonly UIDocument uidoc;
|
|||
|
|
private readonly Document famdoc;
|
|||
|
|
private readonly ActionEventHandler handler;
|
|||
|
|
public PreviewFam()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public PreviewFam(Autodesk.Revit.ApplicationServices.Application app, UIDocument uidoc, string filepath, ActionEventHandler handler)
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
this.handler = handler;
|
|||
|
|
Autodesk.Revit.ApplicationServices.Application application = app;
|
|||
|
|
famdoc = application.OpenDocumentFile(filepath);
|
|||
|
|
this.uidoc = uidoc;
|
|||
|
|
this.doc = uidoc.Document;
|
|||
|
|
//doc = uiapp.ActiveUIDocument.doc;
|
|||
|
|
FilteredElementCollector collector = new FilteredElementCollector(famdoc).OfClass(typeof(View3D));
|
|||
|
|
|
|||
|
|
//IEnumerable<View> secs = from Element f in collecotr where (f as View3D).CanBePrinted == true select (f as View);
|
|||
|
|
View3D v3d = collector.FirstOrDefault() as View3D;
|
|||
|
|
handler.Raise(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
using (Transaction trans = new(famdoc))
|
|||
|
|
{
|
|||
|
|
trans.Start("修改显示");
|
|||
|
|
v3d.DetailLevel = ViewDetailLevel.Fine;
|
|||
|
|
v3d.DisplayStyle = DisplayStyle.RealisticWithEdges;
|
|||
|
|
trans.Commit();
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
PreviewControl pre = new(famdoc, v3d.Id);
|
|||
|
|
|
|||
|
|
grid.Children.Add(pre);
|
|||
|
|
|
|||
|
|
ParaViewModel vm = new(famdoc);
|
|||
|
|
CbbFamType.DataContext = vm;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void CbbFamType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (CbbFamType.SelectedItem != null)
|
|||
|
|
{
|
|||
|
|
FamilyType ft = ((KeyValuePair<string, FamilyType>)CbbFamType.SelectedItem).Value;
|
|||
|
|
System.Collections.ObjectModel.ObservableCollection<ParaModel> paras = new ParaViewModel(famdoc, ft).Parameters;
|
|||
|
|
ParasDG.ItemsSource = paras;
|
|||
|
|
ICollectionView vw = CollectionViewSource.GetDefaultView(paras);
|
|||
|
|
//分组
|
|||
|
|
vw.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
|
|||
|
|
//注意这行代码,设置视图的区域性信息为当前区域性对象
|
|||
|
|
vw.Culture = System.Globalization.CultureInfo.CurrentCulture;
|
|||
|
|
//排序
|
|||
|
|
vw.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending));
|
|||
|
|
handler.Raise(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
using Transaction trans = new(famdoc);
|
|||
|
|
trans.Start("修改类型");
|
|||
|
|
famdoc.FamilyManager.CurrentType = ft;
|
|||
|
|
trans.Commit();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void LoadFam_Click(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
handler.Raise(
|
|||
|
|
_ =>
|
|||
|
|
{
|
|||
|
|
using Transaction trans = new(doc);
|
|||
|
|
trans.Start("加载族" + "-" + Path.GetFileNameWithoutExtension(famdoc.PathName));
|
|||
|
|
doc.LoadFamily(famdoc.PathName, out var family);
|
|||
|
|
trans.Commit();
|
|||
|
|
Close();
|
|||
|
|
var fs = family.GetFamilySymbolIds().Select(id => doc.GetElement(id) as FamilySymbol).FirstOrDefault();
|
|||
|
|
if (fs != null)
|
|||
|
|
{
|
|||
|
|
uidoc.PromptForFamilyInstancePlacement(fs);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
catch (System.Exception)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
throw;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Window_Closed(object sender, System.EventArgs e)
|
|||
|
|
{
|
|||
|
|
famdoc.Close(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//private ObservableCollection<ParaModel> GetParameters(FamilyType ft)
|
|||
|
|
//{
|
|||
|
|
// ObservableCollection<ParaModel> parameters = new ObservableCollection<ParaModel>();
|
|||
|
|
// //FamilyTypeSet types = famdoc.FamilyManager.Types;
|
|||
|
|
// //var familytype = from FamilyType t in types
|
|||
|
|
// // where t.Name == ft
|
|||
|
|
// // select t;
|
|||
|
|
// var paras = new ParaViewModel(, ft).Parameters;
|
|||
|
|
// return parameters;
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
}
|