建筑外围标注

This commit is contained in:
GG Z
2021-12-14 18:26:37 +08:00
parent 70ab56d9d9
commit 0599f61301
10 changed files with 424 additions and 42 deletions

View File

@@ -85,6 +85,10 @@ namespace RookieStation.CommonTools.ViewModels
var vcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.View)).Cast<Autodesk.Revit.DB.View>();
var dimcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.Dimension)).Cast<Autodesk.Revit.DB.Dimension>();
var curvecol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.CurveElement)).Cast<Autodesk.Revit.DB.CurveElement>();
var referplanes = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.ReferencePlane)).Cast<Autodesk.Revit.DB.ReferencePlane>();
var modellines = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.ModelCurve)).Cast<Autodesk.Revit.DB.ModelCurve>();
var combinations = new FilteredElementCollector(famdoc).OfClass(typeof(GeomCombination)).Cast<GeomCombination>();
famdoc.Invoke(ts =>
{
@@ -112,7 +116,20 @@ namespace RookieStation.CommonTools.ViewModels
elemidtohide.Add(curve.Id);
}
}
foreach (var combination in combinations)
{
if (combination.CanBeHidden(view))
{
elemidtohide.Add(combination.Id);
}
}
foreach (var plane in referplanes)
{
if (plane.CanBeHidden(view))
{
elemidtohide.Add(plane.Id);
}
}
if (elemidtohide.Count > 0)
{
view.HideElements(elemidtohide);
@@ -136,6 +153,8 @@ namespace RookieStation.CommonTools.ViewModels
var vcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.View)).Cast<Autodesk.Revit.DB.View>();
var dimcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.Dimension)).Cast<Autodesk.Revit.DB.Dimension>();
var curvecol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.CurveElement)).Cast<Autodesk.Revit.DB.CurveElement>();
var referplanes = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.ReferencePlane)).Cast<Autodesk.Revit.DB.ReferencePlane>();
var combinations = new FilteredElementCollector(famdoc).OfClass(typeof(GeomCombination)).Cast<GeomCombination>();
famdoc.Invoke(ts =>
{
@@ -164,6 +183,20 @@ namespace RookieStation.CommonTools.ViewModels
}
}
foreach (var combination in combinations)
{
if (combination.IsHidden(view))
{
elemidtounHide.Add(combination.Id);
}
}
foreach (var plane in referplanes)
{
if (plane.IsHidden(view))
{
elemidtounHide.Add(plane.Id);
}
}
if (elemidtounHide.Count > 0)
{
view.UnhideElements(elemidtounHide);

View File

@@ -76,7 +76,6 @@ namespace RookieStation.Construction.ExecuteCmd
{
//边界组
CreateFloor(doc, edges);
CreateFloor(doc, edges);
}, "创建楼板");
doc.Invoke(ts =>
{

View File

@@ -0,0 +1,356 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using RookieStation.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace RookieStation.Drawing.ExecuteCmd
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class CreatePalanarViewAnnotation : Autodesk.Revit.UI.IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
DocumentSet docset = uiapp.Application.Documents;
string failedMessage = string.Empty;
ModelCurveArray modelCurveArray = null;
doc.InvokeGroup(tg =>
{
Room room = default;
var wallsToDim = new List<Wall>();
doc.Invoke(ts =>
{
room = CreateOuterRoom(doc.ActiveView, out modelCurveArray);
});
if (room != null)
{
//外侧边界逆时针,内侧边界顺时针
SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions()
{
StoreFreeBoundaryFaces = true,
SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary
};
IList<BoundarySegment> edges = new List<BoundarySegment>();
var boundingseg = room.GetBoundarySegments(options);
edges = boundingseg.LastOrDefault();//需要去重
foreach (BoundarySegment segment in edges)
{
var curve = segment.GetCurve() as Line;
if (curve != null)
{
var wall = doc.GetElement(segment.ElementId) as Wall;
if (wall != null)
{
wallsToDim.Add(wall);
}
}
}
}
doc.Invoke(ts =>
{
JoinWallsAndColumns(doc);
JointStructureCom(doc, BuiltInCategory.OST_Walls, BuiltInCategory.OST_StructuralFraming);
JointStructureCom(doc, BuiltInCategory.OST_StructuralFraming, BuiltInCategory.OST_StructuralColumns);
failedMessage = "";
}, "连接几何体");
doc.Invoke(ts =>
{
CreateWallDimension(doc, wallsToDim);
});
//doc.Invoke(ts =>
//{
// doc.Delete(room.Id);
// foreach (ModelCurve curve in modelCurveArray)
// {
// doc.Delete(curve.Id);
// }
//});
});
return Result.Succeeded;
}
/// <summary>
/// 墙柱连接
/// </summary>
/// <param name="doc"></param>
private void JoinWallsAndColumns(Document doc)
{
var wallcol = doc.QueryByView<Wall>(doc.ActiveView);
StringBuilder sb = new StringBuilder();
foreach (var wall in wallcol)
{
var columncol = doc.QueryByView<FamilyInstance>(doc.ActiveView, BuiltInCategory.OST_StructuralColumns);
BoundingBoxXYZ boundingBox = wall.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(boundingBox.Min, boundingBox.Max);
BoundingBoxIntersectsFilter intersectsFilter = new BoundingBoxIntersectsFilter(outline);
BoundingBoxIsInsideFilter isInsideFilter = new BoundingBoxIsInsideFilter(outline);
LogicalOrFilter orFilter = new LogicalOrFilter(isInsideFilter, intersectsFilter);
columncol.WherePasses(orFilter);
foreach (FamilyInstance column in columncol)
{
if (!JoinGeometryUtils.AreElementsJoined(doc, wall, column))
{
try
{
JoinGeometryUtils.JoinGeometry(doc, wall, column);
}
catch (Exception)
{
sb.Append($"{column.Name}:{column.Id.IntegerValue}/{wall.Name}:{wall.Id.IntegerValue}" + "\n\r");
}
}
}
}
if (sb.Length > 0)
{
TaskDialog.Show("连接墙柱存在错误", sb.ToString());
}
}
/// <summary>
/// 创建外围房间
/// </summary>
/// <param name="view"></param>
/// <param name="modelCurveArray"></param>
/// <returns></returns>
private Room CreateOuterRoom(View view, out ModelCurveArray modelCurveArray)
{
Document doc = view.Document;
List<Wall> wallList = doc.QueryByView<Wall>(view).Cast<Wall>().ToList();
Level level = view.GenLevel;
ElementId levelId = view.GenLevel.Id;
modelCurveArray = null;
wallList = wallList.FindAll(p => p.LevelId == levelId);
if (wallList.Count > 0)
{
List<Wall> tempWallList = new List<Wall>();
double distance = 5;
List<Curve> curveList = wallList.Select(p => RsRevitUtils.GetLocationCurveByElement(p)).ToList();
List<XYZ> xyzList = curveList.Select(p => p.GetEndPoint(0)).ToList();
double xMax = xyzList.Max(p => p.X) + distance;
double xMin = xyzList.Min(p => p.X) - distance;
double yMax = xyzList.Max(p => p.Y) + distance;
double yMin = xyzList.Min(p => p.Y) - distance;
try
{
tempWallList.ForEach(p => p.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0));
XYZ point1 = new XYZ(xMin, yMin, level.Elevation);
XYZ point2 = new XYZ(xMin, yMax, level.Elevation);
XYZ point3 = new XYZ(xMax, yMax, level.Elevation);
XYZ point4 = new XYZ(xMax, yMin, level.Elevation);
Line Line1 = Line.CreateBound(point1, point2);
Line line2 = Line.CreateBound(point2, point3);
Line line3 = Line.CreateBound(point3, point4);
Line line4 = Line.CreateBound(point4, point1);
CurveArray array = new CurveArray();
array.Append(Line1);
array.Append(line2);
array.Append(line3);
array.Append(line4);
//Plane plane = new Plane(XYZ.BasisZ, XYZ.Zero);
Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
SketchPlane sketchPlane = SketchPlane.Create(doc, plane);
modelCurveArray = doc.Create.NewRoomBoundaryLines(sketchPlane, array, view);
Level baseLevel = doc.GetElement(wallList[0].LevelId) as Level;
UV uv = new UV(xMin + 1, yMin + 1);
Room room = doc.Create.NewRoom(baseLevel, uv);
return room;
}
catch (Exception)
{
}
}
return null;
}
/// <summary>
/// 连接两个族类别的几何体
/// </summary>
/// <param name="doc"></param>
/// <param name="builtInCategory1"></param>
/// <param name="builtInCategory2"></param>
private void JointStructureCom(Document doc, BuiltInCategory builtInCategory1, BuiltInCategory builtInCategory2)
{
var collector1 = doc.QueryByBuiltInCategory(builtInCategory1).WhereElementIsNotElementType();
var collector2 = doc.QueryByBuiltInCategory(builtInCategory2).WhereElementIsNotElementType();
foreach (var fi1 in collector1)
{
ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(fi1, false);
collector2.WherePasses(intersectsElementFilter);
foreach (var fi2 in collector2)
{
try
{
JoinGeometryUtils.JoinGeometry(doc, fi2, fi1);
}
catch (Exception)
{
continue;
}
}
}
}
public List<Element> GetWallListToDim(Document doc)
{
var wallList = doc.QueryByView<Wall>(doc.ActiveView).Where(w =>
{
if (w.Name.Contains("墙饰面") || w.Name.Contains("踢脚线"))
{
return false;
}
return true;
});
return wallList.ToList();
}
private static void CreateWallDimension(Document doc, List<Wall> wallList)
{
foreach (Wall wall in wallList)
{
ReferenceArray wallLengthRefernceArray = new ReferenceArray();
List<Face> faces = new List<Face>();
//List<Face> faces = RsRevitUtils.GetSideFacesByElement(wall);
List<ElementId> ids = FindWallIdsConnected(doc, wall);
//var edgearrarray = RsRevitUtils.GetBottomEdgeArrayArray(wall);
foreach (var id in ids)
{
Element ele = doc.GetElement(id);
faces.AddRange(RsRevitUtils.GetSideFacesByElement(ele));
}
foreach (Face face in faces)
{
PlanarFace pf = face as PlanarFace;
if (pf == null || face.Reference == null || pf.OrientationMatchesSurfaceOrientation == false)
{
continue;
}
if (pf.FaceNormal.CrossProduct(wall.Orientation).IsAlmostEqualTo(XYZ.Zero))
{
}
else if (pf.FaceNormal.DotProduct(wall.Orientation) < 0.001)
{
wallLengthRefernceArray.Append(face.Reference);
}
else
{
}
}
try
{
var scale = doc.ActiveView.Scale;
var tranform = Transform.CreateTranslation(wall.Orientation * scale * 15 / 304.8);
var wallcurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line;
Line lengthDimLine = wallcurve.CreateTransformed(tranform) as Line;
//Dimension lengthdim = null;
Dimension lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, wallLengthRefernceArray);
doc.Regenerate();
ReferenceArray finallengthreferenceArray = RemoveZeroReferences(wall, wallLengthRefernceArray, lengthdim);
doc.Delete(lengthdim.Id);
lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, finallengthreferenceArray);
if (lengthdim.Segments.Size > 2)
{
ReferenceArray referenceArray = new ReferenceArray();
var refer1 = lengthdim.References.get_Item(0);
var refer2 = lengthdim.References.get_Item(lengthdim.References.Size - 1);
referenceArray.Append(refer1);
referenceArray.Append(refer2);
var tranform1 = Transform.CreateTranslation(wall.Orientation * scale * 25 / 304.8);
Line lengthTotalDimLine = wallcurve.CreateTransformed(tranform1) as Line;
doc.Create.NewDimension(doc.ActiveView, lengthTotalDimLine, referenceArray);
}
}
catch (Exception)
{
continue;
}
}
}
private static ReferenceArray RemoveZeroReferences(Wall wall, ReferenceArray wallLengthRefernceArray, Dimension lengthdim)
{
List<Reference> referencesdelete = new List<Reference>();
var finallengthreferenceArray = new ReferenceArray();
for (int i = 0; i < lengthdim.NumberOfSegments; i++)
{
if (lengthdim.Segments.get_Item(i).ValueString == "0")
{
if (lengthdim.References.get_Item(i).ElementId == wall.Id)
{
referencesdelete.Add(lengthdim.References.get_Item(i));
}
if (lengthdim.References.get_Item(i + 1).ElementId == wall.Id)
{
referencesdelete.Add(lengthdim.References.get_Item(i + 1));
}
}
}
for (int i = 0; i < wallLengthRefernceArray.Size; i++)
{
bool isContain = false;
var reference = wallLengthRefernceArray.get_Item(i);
foreach (var referdelete in referencesdelete)
{
if (reference.EqualTo(referdelete))
{
isContain = true;
}
}
if (!isContain)
{
finallengthreferenceArray.Append(reference);
}
}
return finallengthreferenceArray;
}
private static List<ElementId> FindWallIdsConnected(Document doc, Wall w)
{
List<ElementId> joinedElements = new List<ElementId>();
var loc = w.Location as LocationCurve;
Curve curve = loc.Curve;
FilteredElementCollector eles = doc.QueryByView<Wall>(doc.ActiveView).WhereElementIsNotElementType();
StringBuilder sb = new StringBuilder();
foreach (Wall wall in eles)
{
if (wall != null)
{
var lc = wall.Location as LocationCurve;
var c = lc.Curve;
var result = curve.Intersect(c, out var intersection);
if (result == SetComparisonResult.Overlap && !wall.Name.Contains("踢脚线") && !wall.Name.Contains("墙饰面"))
{
joinedElements.Add(wall.Id);
sb.Append($"{w.Name} {wall.Name} {result}\r\n");
}
}
}
//TaskDialog.Show("数据", sb.ToString());
return joinedElements;
}
}
}

View File

@@ -8,6 +8,7 @@ using System.Windows.Controls;
using System;
using System.Text;
using System.Windows.Media.Media3D;
using Autodesk.Revit.DB.Architecture;
namespace RookieStation.Drawing.ExecuteCmd
{
@@ -27,7 +28,6 @@ namespace RookieStation.Drawing.ExecuteCmd
//var wall = doc.GetElement(wallrefer) as Wall;
//var joinids = JoinGeometryUtils.GetJoinedElements(doc, wall);//接触关系过滤不出来,连接命令连接的才能过滤
//uidoc.Selection.SetElementIds(joinids);
doc.InvokeGroup(tg =>
{
doc.Invoke(ts =>
@@ -48,7 +48,6 @@ namespace RookieStation.Drawing.ExecuteCmd
CreateShelvesAnnotations(doc, visableCol);
}, "创建标注");
});
//var cutids = SolidSolidCutUtils.GetCuttingSolids(wall);
//uidoc.Selection.SetElementIds(insertids);
//uidoc.Selection.SetElementIds(cutids);
@@ -552,24 +551,6 @@ namespace RookieStation.Drawing.ExecuteCmd
}
}
private static void CreateTag(Document doc, List<Reference> references, TagMode tagMode, bool addleader)
{
doc.Invoke(ts =>
{
foreach (var refer in references)
{
try
{
IndependentTag independentTag = IndependentTag.Create(doc, doc.ActiveView.Id, refer, addleader, tagMode, TagOrientation.Horizontal, new XYZ(0, 0, 0));
}
catch (Exception)
{
continue;
}
}
});
}
private static List<ElementId> GetWallConnectEles(Document doc, Wall wall)
{
GeometryElement geometryElement = wall.get_Geometry(new Options());
@@ -626,7 +607,7 @@ namespace RookieStation.Drawing.ExecuteCmd
}
/// <summary>
/// 获取与当前墙体连接和相交的墙体
/// 获取当前视图中与当前墙体连接和相交的墙体
/// </summary>
/// <param name="doc"></param>
/// <param name="w"></param>
@@ -636,7 +617,7 @@ namespace RookieStation.Drawing.ExecuteCmd
List<ElementId> joinedElements = new List<ElementId>();
var loc = w.Location as LocationCurve;
Curve curve = loc.Curve;
FilteredElementCollector eles = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();
FilteredElementCollector eles = doc.QueryByView<Wall>(doc.ActiveView).WhereElementIsNotElementType();
IntersectionResultArray intersection;
StringBuilder sb = new StringBuilder();
foreach (Element e in eles)
@@ -647,7 +628,7 @@ namespace RookieStation.Drawing.ExecuteCmd
var lc = wall.Location as LocationCurve;
var c = lc.Curve;
var result = curve.Intersect(c, out intersection);
if (result == SetComparisonResult.Overlap)
if (result == SetComparisonResult.Overlap && !e.Name.Contains("踢脚线") && !e.Name.Contains("墙饰面"))
{
joinedElements.Add(wall.Id);
}
@@ -659,19 +640,24 @@ namespace RookieStation.Drawing.ExecuteCmd
private static void CreateWallDimension(Document doc)
{
FilteredElementCollector wallCol = doc.QueryByView<Wall>(doc.ActiveView as ViewPlan);
var visableIdCol = doc.QueryByView(doc.ActiveView).ToElementIds();
var wallList = doc.QueryByView<Wall>(doc.ActiveView).Where(w =>
{
if (w.Name.Contains("墙饰面") || w.Name.Contains("踢脚线"))
{
return false;
}
return true;
});
doc.Invoke(ts =>
{
foreach (Wall wall in wallCol)
foreach (Wall wall in wallList)
{
if (wall.WallType.Kind != WallKind.Basic)
{
continue;
}
var loc = wall.Location as LocationCurve;
ReferenceArray wallThickReferenceArray = new ReferenceArray();
//if (wall.WallType.Kind != WallKind.Basic)
//{
// continue;
//}
//ReferenceArray wallThickReferenceArray = new ReferenceArray();
ReferenceArray wallLengthRefernceArray = new ReferenceArray();
ReferenceArray ColumnLengthRefernceArray = new ReferenceArray();
List<Face> faces = RsRevitUtils.GetSideFacesByElement(wall);
@@ -693,10 +679,10 @@ namespace RookieStation.Drawing.ExecuteCmd
if (pf.FaceNormal.CrossProduct(wall.Orientation).IsAlmostEqualTo(XYZ.Zero))
{
if (doc.GetElement(face.Reference).Id == wall.Id)
{
wallThickReferenceArray.Append(face.Reference);
}
//if (doc.GetElement(face.Reference).Id == wall.Id)
//{
// wallThickReferenceArray.Append(face.Reference);//墙厚标注
//}
}
else if (pf.FaceNormal.DotProduct(wall.Orientation) < 0.001)
{
@@ -720,7 +706,7 @@ namespace RookieStation.Drawing.ExecuteCmd
doc.Create.NewDimension(doc.ActiveView, lengthLine, finallengthreferenceArray);
Line thickLine = Line.CreateUnbound(wallcurve.Evaluate(0.2, true), wall.Orientation);
var thickdim = doc.Create.NewDimension(doc.ActiveView, thickLine, wallThickReferenceArray);
//var thickdim = doc.Create.NewDimension(doc.ActiveView, thickLine, wallThickReferenceArray);
if (lengthdim.Segments.Size > 2)
{

View File

@@ -97,6 +97,7 @@
<Compile Include="CommonTools\ExecuteCmd\ChangeBackgroundColor.cs" />
<Compile Include="CommonTools\ExecuteCmd\DecryptFamily.cs" />
<Compile Include="CommonTools\ExecuteCmd\EncryptFamily.cs" />
<Compile Include="Drawing\ExecuteCmd\CreatePalanarViewAnnotation.cs" />
<Compile Include="ScheduleTools\ExecuteCmd\UpdateSheetContents.cs" />
<Compile Include="CommonTools\ViewModels\EncryptOrDecryptFamily.cs" />
<Compile Include="CommonTools\ViewModels\ProgressMonitorControl.cs" />

View File

@@ -99,14 +99,14 @@ namespace RookieStation.RibbonMenu
RibbonPanel projectPanel = application.CreateRibbonPanel(TabName, ProjectSettingsPanelName);
NewPushButtonData<ProjectSettings>(projectPanel, "项目设置", Properties.Resources.cainiao, null);
NewPushButtonData<AutoGenerateModels>(projectPanel, "建模型", Properties.Resources.Architect, ViewPlanCmdEnabled);
NewPushButtonData<AutoGenerateModels>(projectPanel, "建模型", Properties.Resources.Architect, ViewPlanCmdEnabled);
//前台布置
RibbonPanel receptionAreaPanel = application.CreateRibbonPanel(TabName, ReceptionPanelName);
NewPushButtonData<PlaceReceptionArea>(receptionAreaPanel, "前台布置", Properties.Resources.Reception, ViewPlanCmdEnabled);
NewPushButtonData<ExtrusionLogo>(receptionAreaPanel, "标识挤出", Properties.Resources.LogoExtrusion, ViewPlanCmdEnabled);
NewPushButtonData<WallDivide>(receptionAreaPanel, "铝塑板分缝", Properties.Resources.WallSweep, null);
NewPushButtonData<WallDivide>(receptionAreaPanel, "墙面分缝", Properties.Resources.WallSweep, null);
//出入口布置
RibbonPanel packAreaPanel = application.CreateRibbonPanel(TabName, EntranceAndExitGatePanelName);

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace RookieStation.Utils
{
/// <summary>
/// 命令在平面视图可用
/// 命令在楼层平面视图可用
/// </summary>
internal class EnableCmdInViewPlan : IExternalCommandAvailability
{

View File

@@ -446,6 +446,13 @@ namespace RookieStation.Utils
return faces;
}
public static EdgeArrayArray GetBottomEdgeArrayArray(Element element)
{
List<Edge> edges = new List<Edge>();
var face = GetBottomFaceByElement(element);
return face.EdgeLoops;
}
/// <summary>
/// 获取族实例所有面(实际为族类型的所有面)
/// </summary>

Binary file not shown.