图例功能
This commit is contained in:
@@ -9,6 +9,7 @@ using RookieStation.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace RookieStation.Drawing.ExecuteCmds
|
||||
{
|
||||
@@ -31,11 +32,30 @@ namespace RookieStation.Drawing.ExecuteCmds
|
||||
TaskDialog.Show("温馨提示", "请选择平面视图的视口");
|
||||
return Result.Failed;
|
||||
}
|
||||
doc.InvokeGroup(tg =>
|
||||
try
|
||||
{
|
||||
var viewScale = viewport.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger();
|
||||
CreateLegend(doc, GetShelfData(uidoc), viewScale);
|
||||
});
|
||||
doc.InvokeGroup(tg =>
|
||||
{
|
||||
var viewScale = viewport.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger();
|
||||
View legend = null;
|
||||
doc.Invoke(ts =>
|
||||
{
|
||||
legend = RsRevitUtils.CreateNewLegend(doc, "货架说明", viewScale);
|
||||
});
|
||||
doc.Invoke(ts =>
|
||||
{
|
||||
var shelvesData = GetShelfData(doc);
|
||||
CreateShelfLegend(doc, shelvesData, legend, viewScale);
|
||||
});
|
||||
doc.Invoke(ts =>
|
||||
{
|
||||
RsRevitUtils.SetLegendLocation(doc, legend);
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,9 +65,8 @@ namespace RookieStation.Drawing.ExecuteCmds
|
||||
return Result.Succeeded;
|
||||
}
|
||||
|
||||
private static List<ShelfStatistic> GetShelfData(UIDocument uidoc)
|
||||
private List<ShelfStatistic> GetShelfData(Document doc)
|
||||
{
|
||||
Document doc = uidoc.Document;
|
||||
var shelves = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Furniture).Cast<FamilyInstance>().Where(s => s.Symbol.FamilyName.Contains("货架"));
|
||||
var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).Cast<Room>();
|
||||
double area = 0.0;
|
||||
@@ -76,112 +95,71 @@ namespace RookieStation.Drawing.ExecuteCmds
|
||||
return statistics;
|
||||
}
|
||||
|
||||
private static Autodesk.Revit.DB.View CreateLegend(Document doc, List<ShelfStatistic> statistics, int scale)
|
||||
/// <summary>
|
||||
/// 创建表格、文字
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
/// <param name="statistics"></param>
|
||||
/// <param name="newLegend"></param>
|
||||
/// <param name="viewScale"></param>
|
||||
private void CreateShelfLegend(Document doc, List<ShelfStatistic> statistics, View newLegend, int viewScale)
|
||||
{
|
||||
var legends = doc.QueryByClassAndBuiltInCategory<Autodesk.Revit.DB.View>(BuiltInCategory.OST_Views).Cast<Autodesk.Revit.DB.View>().Where(v => v.ViewType == ViewType.Legend);
|
||||
Autodesk.Revit.DB.View newLegend = null;
|
||||
|
||||
if (legends.Count() == 0)
|
||||
{
|
||||
TaskDialog.Show("温馨提示", "请先新建图例");
|
||||
return newLegend;
|
||||
}
|
||||
doc.Invoke(ts =>
|
||||
{
|
||||
var legendToCopy = legends.FirstOrDefault();
|
||||
|
||||
var newLegendId = legendToCopy.Duplicate(ViewDuplicateOption.Duplicate);
|
||||
newLegend = doc.GetElement(newLegendId) as Autodesk.Revit.DB.View;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
newLegend.Name = $"货架说明 {i}";
|
||||
break;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
newLegend.Scale = scale;
|
||||
});
|
||||
|
||||
TextNoteType textNoteType = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).Where(x => x.Name.Contains("宋")).FirstOrDefault() as TextNoteType;
|
||||
TextNoteType textNoteType = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).Where(x => x.Name.Contains(UserConstant.FontName)).FirstOrDefault() as TextNoteType;
|
||||
double fontSize = textNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble();
|
||||
double actualTextHeight = fontSize * 1.6;
|
||||
double legendGridHeight = actualTextHeight * scale * 1.2;//图例网格高度
|
||||
double legendGridLength = legendGridHeight * 5;//图例网格长度
|
||||
doc.Invoke(ts =>
|
||||
double tableGridHeight = actualTextHeight * viewScale * 1.2;//图例网格高度
|
||||
double tableGridWidth = tableGridHeight * 5;//图例网格长度
|
||||
double[] widths = new double[6] { tableGridHeight * 2, tableGridHeight * 2, tableGridHeight * 6, tableGridHeight * 2, tableGridHeight * 2, tableGridHeight * 2 };
|
||||
CurveArray curveArray = new CurveArray();
|
||||
|
||||
for (int i = statistics.Count + 1; i >= 0; i--)//水平线
|
||||
{
|
||||
CurveArray curveArray = new CurveArray();
|
||||
for (int i = 0; i < statistics.Count() + 2; i++)//水平线
|
||||
Curve line;
|
||||
if (i > 0 && i < statistics.Count)
|
||||
{
|
||||
if (i == 0 || i == statistics.Count() || i == statistics.Count() + 1)
|
||||
{
|
||||
Curve line = Line.CreateBound(XYZ.Zero, XYZ.BasisX * legendGridLength * 6).CreateOffset(legendGridHeight * i, -XYZ.BasisZ);
|
||||
curveArray.Append(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
Curve line = Line.CreateBound(XYZ.Zero, XYZ.BasisX * legendGridLength * 3).CreateOffset(legendGridHeight * i, -XYZ.BasisZ);
|
||||
curveArray.Append(line);
|
||||
}
|
||||
line = Line.CreateBound(XYZ.Zero, XYZ.BasisX * tableGridWidth * 3).CreateOffset(tableGridHeight * i, -XYZ.BasisZ);
|
||||
}
|
||||
for (int i = 0; i < 7; i++)//垂直线
|
||||
else
|
||||
{
|
||||
Curve line = Line.CreateBound(XYZ.Zero, XYZ.BasisY * (statistics.Count() + 1) * legendGridHeight).CreateOffset(legendGridLength * i, XYZ.BasisZ);
|
||||
curveArray.Append(line);
|
||||
line = Line.CreateBound(XYZ.Zero, XYZ.BasisX * tableGridWidth * 6).CreateOffset(tableGridHeight * i, -XYZ.BasisZ);
|
||||
}
|
||||
var opts = new TextNoteOptions(textNoteType.Id);
|
||||
for (int i = 0; i <= statistics.Count(); i++)
|
||||
{
|
||||
var yElevation = XYZ.BasisY * legendGridHeight * (i + 1);
|
||||
if (i < statistics.Count())
|
||||
{
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * 0.5 + yElevation, statistics[i].ShelfType, opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength + 0.5) + yElevation, statistics[i].Count.ToString(), opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 2 + 0.5) + yElevation,
|
||||
statistics[i].LinearMetre.ToString(), opts);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * 0.5 + yElevation, "货架类型", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength + 0.5) + yElevation, "数量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 2 + 0.5) + yElevation, "总延米", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 3 + 0.5) + yElevation, "总承载单量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 4 + 0.5) + yElevation, "设计单量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 5 + 0.5) + yElevation, "场地面积", opts);
|
||||
}
|
||||
}
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 3 + 0.5) + XYZ.BasisY * legendGridHeight * (statistics.Count() + 1) / 2, statistics[0].CapacityOrders.ToString(), opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 4 + 0.5) + XYZ.BasisY * legendGridHeight * (statistics.Count() + 1) / 2, statistics[0].DesignOrders.ToString(), opts);
|
||||
TextNote tn = TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (legendGridLength * 5 + 0.5) + XYZ.BasisY * legendGridHeight * (statistics.Count() + 1) / 2, statistics[0].GroundArea + "m2".ToString(), opts);
|
||||
FormattedText formattedText = new FormattedText(tn.Text);
|
||||
TextRange range = new TextRange(tn.Text.Length - 2, 1);
|
||||
formattedText.SetSuperscriptStatus(range, true);
|
||||
tn.SetFormattedText(formattedText);
|
||||
doc.Create.NewDetailCurveArray(newLegend, curveArray);
|
||||
});
|
||||
|
||||
doc.Invoke(ts =>
|
||||
curveArray.Append(line);
|
||||
}
|
||||
for (int i = 0; i < 7; i++)//垂直线
|
||||
{
|
||||
//doc.Create.NewDetailCurve(doc.ActiveView, Line.CreateBound(XYZ.Zero, XYZ.BasisX));
|
||||
//XYZ p = new XYZ(6.0335, 1, 0) * 0.03606;
|
||||
//ViewSheet.Create(doc, newLegend.Id);
|
||||
var viewport = Viewport.Create(doc, doc.ActiveView.Id, newLegend.Id, XYZ.Zero);
|
||||
double l = viewport.GetBoxOutline().MaximumPoint.X - viewport.GetBoxOutline().MinimumPoint.X;
|
||||
double w = viewport.GetBoxOutline().MaximumPoint.Y - viewport.GetBoxOutline().MinimumPoint.Y;
|
||||
XYZ c = new XYZ(l / 2 + 7 / 304.8, w / 2 + 7 / 304.8, 0);
|
||||
Curve line = Line.CreateBound(XYZ.Zero, XYZ.BasisY * (statistics.Count() + 1) * tableGridHeight).CreateOffset(tableGridWidth * i, XYZ.BasisZ);
|
||||
curveArray.Append(line);
|
||||
}
|
||||
var y = XYZ.BasisY * tableGridHeight * (statistics.Count + 0.5);
|
||||
|
||||
viewport.SetBoxCenter(c);
|
||||
var opts = new TextNoteOptions(textNoteType.Id)
|
||||
{
|
||||
VerticalAlignment = VerticalTextAlignment.Middle,
|
||||
HorizontalAlignment = HorizontalTextAlignment.Center
|
||||
};
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * tableGridWidth * 0.5 + y, "货架类型", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 1.5) + y, "数量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 2.5) + y, "总延米", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 3.5) + y, "总承载单量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 4.5) + y, "设计单量", opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 5.5) + y, "场地面积", opts);
|
||||
for (int i = 0; i < statistics.Count(); i++)
|
||||
{
|
||||
var yElevation = XYZ.BasisY * tableGridHeight * (i + 0.5);
|
||||
|
||||
var ele = new FilteredElementCollector(doc).OfClass(typeof(ElementType)).WhereElementIsElementType().FirstOrDefault(x => x.Name.Contains("无"));
|
||||
viewport.ChangeTypeId(ele.Id);//选择视口-无标题
|
||||
});
|
||||
|
||||
return newLegend;
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * tableGridWidth * 0.5 + yElevation, statistics[i].ShelfType, opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 1.5) + yElevation, statistics[i].Count.ToString(), opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 2.5) + yElevation,
|
||||
statistics[i].LinearMetre.ToString(), opts);
|
||||
}
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 3.5) + XYZ.BasisY * tableGridHeight * statistics.Count() / 2, statistics[0].CapacityOrders.ToString(), opts);
|
||||
TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 4.5) + XYZ.BasisY * tableGridHeight * statistics.Count() / 2, statistics[0].DesignOrders.ToString(), opts);
|
||||
TextNote tn = TextNote.Create(doc, newLegend.Id, XYZ.BasisX * (tableGridWidth * 5.5) + XYZ.BasisY * tableGridHeight * statistics.Count() / 2, statistics[0].GroundArea + "m2".ToString(), opts);
|
||||
FormattedText formattedText = new FormattedText(tn.Text);
|
||||
TextRange range = new TextRange(tn.Text.Length - 2, 1);
|
||||
formattedText.SetSuperscriptStatus(range, true);
|
||||
tn.SetFormattedText(formattedText);
|
||||
var curves = doc.Create.NewDetailCurveArray(newLegend, curveArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user