优化更新
This commit is contained in:
@@ -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