优化更新
This commit is contained in:
@@ -14,7 +14,6 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Win32;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
using Nice3point.Revit.Toolkit.Utils;
|
||||
|
||||
using Sai.RvKits.Windows;
|
||||
|
||||
@@ -24,36 +23,10 @@ namespace Sai.RvKits.RvFamily;
|
||||
|
||||
public partial class ModelCheckViewModel : ObservableObject
|
||||
{
|
||||
private readonly ActionEventHandler showElementsSectionBox = new();
|
||||
private readonly CorrectReferLevelExecutes correctReferLevelExecutes;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool useSectionBox;
|
||||
[ObservableProperty]
|
||||
private bool isCheckEqual;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckLength;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckLevel;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckName;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckProps;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckSlope;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isCheckSymbolGeometry;
|
||||
|
||||
[ObservableProperty]
|
||||
private int errorCount;
|
||||
|
||||
private readonly ActionEventHandler modifyModel = new();
|
||||
private readonly ActionEventHandler showElementsSectionBox = new();
|
||||
private readonly UIApplication uiapp;
|
||||
|
||||
public ModelCheckViewModel(UIApplication uiapp)
|
||||
@@ -66,6 +39,15 @@ public partial class ModelCheckViewModel : ObservableObject
|
||||
FindBasePoint();
|
||||
}
|
||||
|
||||
private bool CanExport()
|
||||
{
|
||||
return Items.Any();
|
||||
}
|
||||
private static bool CanShowElement(object obj)
|
||||
{
|
||||
return obj is MessageModel { IsInstance: true };
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private /*async Task*/ void CheckModel(/*CancellationToken token*/)
|
||||
{
|
||||
@@ -357,45 +339,6 @@ public partial class ModelCheckViewModel : ObservableObject
|
||||
ExportToExcelCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
private void FindBasePoint()
|
||||
{
|
||||
var basePoints = uiapp.ActiveUIDocument.Document.OfClass<BasePoint>().OfType<BasePoint>();
|
||||
foreach (var item in basePoints)
|
||||
{
|
||||
//南北
|
||||
var ns = Math.Round(
|
||||
item.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble() * 0.3048,
|
||||
4,
|
||||
MidpointRounding.AwayFromZero
|
||||
);
|
||||
//东西
|
||||
var ew = Math.Round(item.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble() * 0.3048, 4, MidpointRounding.AwayFromZero);
|
||||
//高程
|
||||
var elev = Math.Round(
|
||||
item.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble() * 0.3048,
|
||||
4,
|
||||
MidpointRounding.AwayFromZero
|
||||
);
|
||||
if (item.IsShared)//测量点
|
||||
{
|
||||
SharedBasePoint = $"南北:{ns}m;东西:{ew}m;高程:{elev}m";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.Category.GetHashCode() == -2001271)//项目基点
|
||||
{
|
||||
//正北角度
|
||||
var angle = item.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsValueString();
|
||||
ProjectBasePoint = $"南北:{ns}m;东西:{ew}m;高程:{elev}m;角度:{angle}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanExport()
|
||||
{
|
||||
return Items.Any();
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanExport))]
|
||||
private void ExportToExcel()
|
||||
{
|
||||
@@ -488,6 +431,40 @@ public partial class ModelCheckViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private void FindBasePoint()
|
||||
{
|
||||
var basePoints = uiapp.ActiveUIDocument.Document.OfClass<BasePoint>().OfType<BasePoint>();
|
||||
foreach (var item in basePoints)
|
||||
{
|
||||
//南北
|
||||
var ns = Math.Round(
|
||||
item.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble() * 0.3048,
|
||||
4,
|
||||
MidpointRounding.AwayFromZero
|
||||
);
|
||||
//东西
|
||||
var ew = Math.Round(item.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble() * 0.3048, 4, MidpointRounding.AwayFromZero);
|
||||
//高程
|
||||
var elev = Math.Round(
|
||||
item.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble() * 0.3048,
|
||||
4,
|
||||
MidpointRounding.AwayFromZero
|
||||
);
|
||||
if (item.IsShared)//测量点
|
||||
{
|
||||
SharedBasePoint = $"南北:{ns}m;东西:{ew}m;高程:{elev}m";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.Category.GetHashCode() == -2001271)//项目基点
|
||||
{
|
||||
//正北角度
|
||||
var angle = item.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsValueString();
|
||||
ProjectBasePoint = $"南北:{ns}m;东西:{ew}m;高程:{elev}m;角度:{angle}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ModifyModel()
|
||||
{
|
||||
@@ -576,10 +553,6 @@ public partial class ModelCheckViewModel : ObservableObject
|
||||
SingletonChildWindowManager.ShowOrActivate<MessageWin, MessageViewModel>(uiapp.ActiveUIDocument, errorItems, "未解决错误");
|
||||
});
|
||||
}
|
||||
private static bool CanShowElement(object obj)
|
||||
{
|
||||
return obj is MessageModel { IsInstance: true };
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanShowElement))]
|
||||
private void ShowElement(object obj)
|
||||
@@ -629,11 +602,39 @@ public partial class ModelCheckViewModel : ObservableObject
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<MessageModel> items;
|
||||
public partial int ErrorCount { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckEqual { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckLength { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckLevel { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckName { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckProps { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckSlope { get; set; }
|
||||
[ObservableProperty]
|
||||
public partial bool IsCheckSymbolGeometry { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial ObservableCollection<MessageModel> Items { get; set; }
|
||||
[ObservableProperty]
|
||||
public partial int MyProperty { get; set; }
|
||||
|
||||
public string ProjectBasePoint { get; set; }
|
||||
|
||||
public string SharedBasePoint { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool UseSectionBox { get; set; }
|
||||
}
|
||||
|
||||
public enum ModelCheckType
|
||||
|
||||
17
Sai.RvKits/ModelManager/SeparateModelCmd.cs
Normal file
17
Sai.RvKits/ModelManager/SeparateModelCmd.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace Sai.RvKits.ModelManager;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class SeparateModelCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
//var win = new SeparateModelWin();
|
||||
//win.Show();
|
||||
SingletonChildWindowManager.ShowOrActivate<SeparateModelWin, SeparateModelViewModel>();
|
||||
}
|
||||
}
|
||||
76
Sai.RvKits/ModelManager/SeparateModelViewModel.cs
Normal file
76
Sai.RvKits/ModelManager/SeparateModelViewModel.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
using UIFrameworkServices;
|
||||
|
||||
namespace Sai.RvKits.ModelManager
|
||||
{
|
||||
public partial class SeparateModelViewModel : ObservableObject
|
||||
{
|
||||
private readonly ActionEventHandler separate = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private string fileName = "示例";
|
||||
[ObservableProperty]
|
||||
private string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
|
||||
[RelayCommand]
|
||||
private void Separate()
|
||||
{
|
||||
separate.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var doc = uidoc.Document;
|
||||
var list = uidoc.Selection.GetElementIds();
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
MessageBox.Show("未选中元素", "提示");
|
||||
return;
|
||||
}
|
||||
SpearateByIds(doc, list);
|
||||
doc.Invoke(
|
||||
ts =>
|
||||
{
|
||||
doc.Delete(list);
|
||||
},
|
||||
"删除元素");
|
||||
});
|
||||
}
|
||||
private void SpearateByIds(Document doc, ICollection<ElementId> list)
|
||||
{
|
||||
var allOthers = doc.OfModelCollector()
|
||||
.Excluding(list)
|
||||
.ToElementIds();
|
||||
var ids = doc.OfClass<ImportInstance>().ToElementIds();
|
||||
var modelLineIds = doc.OfCollector().OfCategory(BuiltInCategory.OST_Lines).Select(e => e.Id).ToList();
|
||||
var texts = doc.OfCollector().OfCategory(BuiltInCategory.OST_TextNotes).Select(e => e.Id).ToList();
|
||||
doc.Invoke(
|
||||
ts =>
|
||||
{
|
||||
doc.Delete(allOthers);
|
||||
doc.Delete(ids);
|
||||
doc.Delete(modelLineIds);
|
||||
doc.Delete(texts);
|
||||
},
|
||||
"删除其他");
|
||||
if (!Directory.Exists(FolderPath))
|
||||
{
|
||||
Directory.CreateDirectory(FolderPath);
|
||||
}
|
||||
var filePath = Path.Combine(FolderPath, $"{FileName}.rvt");
|
||||
SaveAsOptions options = new SaveAsOptions() { OverwriteExistingFile = true, PreviewViewId = doc.ActiveView.Id, Compact = true };
|
||||
|
||||
doc.SaveAs(filePath, options);
|
||||
QuickAccessToolBarService.performMultipleUndoRedoOperations(true, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
Sai.RvKits/ModelManager/SeparateModelWin.xaml
Normal file
37
Sai.RvKits/ModelManager/SeparateModelWin.xaml
Normal file
@@ -0,0 +1,37 @@
|
||||
<ex:FluentWindowEx
|
||||
x:Class="Sai.RvKits.ModelManager.SeparateModelWin"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ex="https://github.com/sherlockforrest/Wpf.Ui.Extend"
|
||||
xmlns:local="clr-namespace:Sai.RvKits.ModelManager"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="拆分模型"
|
||||
Width="300"
|
||||
Height="300"
|
||||
d:DataContext="{d:DesignInstance Type=local:SeparateModelViewModel}"
|
||||
SizeToContent="Height"
|
||||
Topmost="True"
|
||||
mc:Ignorable="d">
|
||||
<ex:FluentWindowEx.Resources>
|
||||
<ResourceDictionary Source="pack://application:,,,/Sai.RvKits;component/WPFUI.xaml" />
|
||||
</ex:FluentWindowEx.Resources>
|
||||
<Grid>
|
||||
<StackPanel Margin="5">
|
||||
<ui:TextBox
|
||||
Margin="5"
|
||||
PlaceholderText="文件名"
|
||||
Text="{Binding FileName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<ui:TextBox
|
||||
Margin="5"
|
||||
PlaceholderText="保存路径"
|
||||
Text="{Binding FolderPath, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<ui:Button
|
||||
Margin="5"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding SeparateCommand}"
|
||||
Content="拆分" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ex:FluentWindowEx>
|
||||
14
Sai.RvKits/ModelManager/SeparateModelWin.xaml.cs
Normal file
14
Sai.RvKits/ModelManager/SeparateModelWin.xaml.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Wpf.Ui.Extend.Controls;
|
||||
|
||||
namespace Sai.RvKits.ModelManager;
|
||||
/// <summary>
|
||||
/// SeparateModelWin.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SeparateModelWin : FluentWindowEx
|
||||
{
|
||||
public SeparateModelWin()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
@@ -32,6 +31,56 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
fontFamilies = installedFonts.Families;
|
||||
}
|
||||
[RelayCommand]
|
||||
private void CleanFontType()
|
||||
{
|
||||
handler.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
var doc = uiapp.ActiveUIDocument.Document;
|
||||
var textTypes = doc.OfClass<TextNoteType>().ToList();
|
||||
|
||||
foreach (var type in textTypes)
|
||||
{
|
||||
{
|
||||
if (type is TextNoteType textNoteType)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var font = textNoteType.get_Parameter(BuiltInParameter.TEXT_FONT).AsString();
|
||||
var size = textNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsValueString().TrimEnd('m');
|
||||
var dSize = Math.Round(Convert.ToDouble(size), 1, MidpointRounding.AwayFromZero);
|
||||
if (dSize < 0.23)
|
||||
{
|
||||
return;
|
||||
}
|
||||
textNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).SetValueString(dSize.ToString());
|
||||
var scale = textNoteType.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).AsValueString();
|
||||
//var color = textNoteType.get_Parameter(BuiltInParameter.LINE_COLOR).AsInteger();
|
||||
var name = $"{font}-{dSize}mm-{scale}";
|
||||
var isExist = textTypes.FirstOrDefault(t => t.Name == name);
|
||||
if (isExist != null)
|
||||
{
|
||||
var texts = doc.OfClass<TextNote>().Where(e => e.GetTypeId() == textNoteType.Id).ToList();
|
||||
texts.ForEach(e => e.ChangeTypeId(isExist.Id));
|
||||
doc.Regenerate();
|
||||
doc.Delete(textNoteType.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
textNoteType.Name = name;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
[RelayCommand]
|
||||
private void ModifyFont()
|
||||
{
|
||||
handler.Raise(
|
||||
@@ -44,9 +93,9 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
var col = doc.OfClass<Family>()
|
||||
.Cast<Family>()
|
||||
.Where(f => f.FamilyCategory.CategoryType == CategoryType.Annotation);
|
||||
foreach(var family in col)
|
||||
foreach (var family in col)
|
||||
{
|
||||
if(!family.IsEditable)
|
||||
if (!family.IsEditable)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -56,7 +105,7 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
ts =>
|
||||
{
|
||||
var textElements = familyEditing.OfClass<TextElement>().Cast<TextElement>();
|
||||
foreach(var text in textElements)
|
||||
foreach (var text in textElements)
|
||||
{
|
||||
var type = text.Symbol;
|
||||
ElementType typeCopy;
|
||||
@@ -64,7 +113,8 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
{
|
||||
typeCopy = type.Duplicate(
|
||||
$"{SelectFontFamily.Name} {FontSize} - {WidthScale}");
|
||||
} catch(Autodesk.Revit.Exceptions.ArgumentException)
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.ArgumentException)
|
||||
{
|
||||
}
|
||||
type.get_Parameter(BuiltInParameter.TEXT_FONT)?.SetValueString(
|
||||
@@ -76,14 +126,15 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
}
|
||||
|
||||
var textNotes = familyEditing.OfClass<TextNote>().Cast<TextNote>();
|
||||
foreach(var text in textNotes)
|
||||
foreach (var text in textNotes)
|
||||
{
|
||||
var type = text.Symbol;
|
||||
try
|
||||
{
|
||||
var typeCopy = type.Duplicate(
|
||||
$"{SelectFontFamily.Name} {FontSize} - {WidthScale}");
|
||||
} catch(Autodesk.Revit.Exceptions.ArgumentException)
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.ArgumentException)
|
||||
{
|
||||
}
|
||||
type.get_Parameter(BuiltInParameter.TEXT_FONT)?.SetValueString(
|
||||
@@ -101,7 +152,7 @@ public partial class TemplateManagerViewModel : ObservableObject
|
||||
},
|
||||
"载入族");
|
||||
}
|
||||
},"调整文字");
|
||||
}, "调整文字");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user