diff --git a/RookieStation/Construction/ExecuteCmd/AutoGenerateModels.cs b/RookieStation/Construction/ExecuteCmd/AutoGenerateModels.cs index f817177..574df8e 100644 --- a/RookieStation/Construction/ExecuteCmd/AutoGenerateModels.cs +++ b/RookieStation/Construction/ExecuteCmd/AutoGenerateModels.cs @@ -5,14 +5,10 @@ using System; using RookieStation.Utils; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Controls; -using System.Collections.ObjectModel; using Autodesk.Revit.DB.Architecture; -using System.Security.Cryptography; using RookieStation.Construction.Views; -using System.Windows.Media.Media3D; +using System.Windows.Forms.VisualStyles; +using System.Windows.Controls; namespace RookieStation.Construction.ExecuteCmd { @@ -31,8 +27,8 @@ namespace RookieStation.Construction.ExecuteCmd WpfAutoModeling settings = CommonUtils.ShowDialog(); if (settings.DialogResult == true) { - length = settings.Length / 304.8; - width = settings.Width / 304.8; + length = settings.mLength / 304.8; + width = settings.mWidth / 304.8; } else { @@ -42,8 +38,8 @@ namespace RookieStation.Construction.ExecuteCmd var pointsCorner = new List(); //边界 IList edges = new List(); - - var p1 = uidoc.Selection.PickPoint(ObjectSnapTypes.Endpoints, "请选择定位点"); + var p1 = new XYZ(-length / 2, -width / 2, 0); + //var p1 = uidoc.Selection.PickPoint(ObjectSnapTypes.Endpoints, "请选择定位点"); var p2 = p1.Add(width * XYZ.BasisY); var p3 = p1.Add(new XYZ(length, width, 0)); var p4 = p1.Add(length * XYZ.BasisX); @@ -72,22 +68,34 @@ namespace RookieStation.Construction.ExecuteCmd { doc.InvokeGroup(tg => { + doc.Invoke(ts => + { + CreateGrids(doc, edges); + }, "创建轴网"); doc.Invoke(ts => { //边界组 CreateFloor(doc, edges); - }); + }, "创建楼板"); doc.Invoke(ts => { CreateColumnAndFoundation(doc, edges, interval); }, "创建基础和柱"); doc.Invoke(ts => { - CreateFramings(doc, edges, interval); - }, "创建地梁"); + double horizontalOffest = 150 / 304.8; + CreateFramings(doc, edges, horizontalOffest, interval); + CreateOuterWallList(doc, loop, horizontalOffest); + }, "创建地梁,外墙"); doc.Invoke(ts => { - var roof = CreateRoof(doc, loop, 125 / 304.8, 160 / 304.8); + double distance = 1300 / 304.8; + double bottomOffest = 180 / 304.8; + double outerOffest = 125 / 304.8; + var roof = CreateRoof(doc, loop, outerOffest, bottomOffest); + var slope = roof.get_Parameter(BuiltInParameter.ROOF_SLOPE).AsDouble(); + //var h = roof.get_Parameter(BuiltInParameter.ACTUAL_MAX_RIDGE_HEIGHT_PARAM).AsDouble(); + CreateTopFramings(doc, edges, slope, distance, 4000 / 304.8); #region MyRegion @@ -122,33 +130,167 @@ namespace RookieStation.Construction.ExecuteCmd //} #endregion MyRegion - }, "创建屋面"); + }, "创建顶部构造"); + doc.Invoke(ts => { CreateGutter(doc, loop, 100.0 / 304.8, 180 / 304.8); }, "创建檐沟"); + var walllist = new List(); doc.Invoke(ts => { - CreateOuterWallList(doc, loop, 200 / 304.8); - }); - doc.Invoke(ts => - { - CreatePWallList(doc, loop, 400 / 304.8, 0.0); + walllist = CreateAluminumPlastic(doc, loop, 400 / 304.8, 0.0); }, "创建铝塑板"); + doc.Invoke(ts => + { + var wallSweepType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Reveals).WhereElementIsElementType().Where(w => w.Name.Contains("3mm")).FirstOrDefault(); + var wallsweepsId = new List(); + foreach (var wall in walllist) + { + if (wall != null) + { + var line = RsRevitUtils.GetLocationCurveByElement(wall); + var n = (int)Math.Floor(line.Length / (2440 / 304.8)); + for (int i = 0; i < n; i++) + { + WallSweepInfo info = new WallSweepInfo(WallSweepType.Reveal, true) + { + Distance = i * 2440 / 304.8, + WallSide = WallSide.Exterior, + DistanceMeasuredFrom = DistanceMeasuredFrom.Base, + }; + if (WallSweep.WallAllowsWallSweep(wall)) + { + var wallsweep = WallSweep.Create(wall, wallSweepType.Id, info); + } + } + } + }; + }, "创建分隔条"); }, "自动创建模型"); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return Result.Cancelled; } - catch (Exception e) + catch (Exception) { throw; //System.Windows.Forms.MessageBox.Show(e.InnerException.ToString()); } + return Result.Succeeded; } + public void CreateGrids(Document doc, IList edges) + { + var horizontalLines = from l in edges + where Math.Abs((l as Line).Direction.DotProduct(XYZ.BasisY)) < Math.Pow(10, -14) + select l; + var horizontalOrderedLines = horizontalLines.OrderBy(l => l.GetEndPoint(0).Y); + + var verticalLines = from l in edges + where Math.Abs((l as Line).Direction.DotProduct(XYZ.BasisX)) < Math.Pow(10, -14) + select l; + var verticalOrderedLines = verticalLines.OrderBy(l => l.GetEndPoint(0).X); + for (int i = 0; i < horizontalOrderedLines.Count(); i++)//水平轴网 + { + var horizontalLine = horizontalOrderedLines.ElementAt(i); + XYZ sp = horizontalLine.GetEndPoint(0) - (horizontalLine as Line).Direction * 10; + XYZ ep = horizontalLine.GetEndPoint(1) + (horizontalLine as Line).Direction * 10; + Line line = Line.CreateBound(sp, ep); + if (line.Direction.X < 0 || line.Direction.Y < 0) + { + line = line.CreateReversed() as Line; + } + var grid = Autodesk.Revit.DB.Grid.Create(doc, line); + grid.Name = ((char)(i + 65)).ToString(); + } + for (int i = 0; (i < verticalOrderedLines.Count()); i++) //垂直轴网 + { + var verticalLine = verticalOrderedLines.ElementAt(i); + XYZ sp = verticalLine.GetEndPoint(0) - (verticalLine as Line).Direction * 10; + XYZ ep = verticalLine.GetEndPoint(1) + (verticalLine as Line).Direction * 10; + Line line = Line.CreateBound(sp, ep); + if (line.Direction.X < 0 || line.Direction.Y < 0) + { + line = line.CreateReversed() as Line; + } + var grid = Autodesk.Revit.DB.Grid.Create(doc, line); + grid.Name = (i + 1).ToString(); + } + } + + /// + /// 顶部工字钢 + /// + /// + /// + /// 屋面坡度 + /// + /// + /// + private void CreateTopFramings(Document doc, IList edges, double slope, double wdithInterval, double lengthInterval) + { + Level topLevel = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).OrderBy(l => l.Elevation).FirstOrDefault(); + var frameSymbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralFraming).Cast().Where(s => s.Name.Contains("C16a")).FirstOrDefault(); + var frameSymbol1 = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralFraming).Cast().Where(s => s.Name.Contains("HN250x125x6x9")).FirstOrDefault(); + + Curve curve = edges.First(); + double width = edges.First().Length; + double length = edges.Last().Length; + var h = slope * width / 2; + var startpoint = curve.GetEndPoint(0) + topLevel.Elevation * XYZ.BasisZ; + var endpoint = curve.GetEndPoint(1) + topLevel.Elevation * XYZ.BasisZ; + XYZ centerpoint = curve.Evaluate(0.5, true) + (h + topLevel.Elevation) * XYZ.BasisZ; + Line l1 = Line.CreateBound(startpoint, centerpoint); + Line l2 = Line.CreateBound(endpoint, centerpoint); + + double n = 100; + var lines = new List(); + lines.Add(Line.CreateBound(startpoint, startpoint + length * XYZ.BasisX)); + lines.Add(Line.CreateBound(endpoint, endpoint + length * XYZ.BasisX)); + //工字钢 + for (int i = 1; i < n; i++) + { + var parameter = i * wdithInterval; + //if (parameter <= l1.Length) + if (l1.IsInside(parameter)) + { + var p1 = l1.Evaluate(parameter, false); + Line l = Line.CreateBound(p1, p1 + XYZ.BasisX * length); + var line = l.CreateTransformed(Transform.CreateTranslation(XYZ.BasisZ * 200 / 304.8)); + var beam = doc.Create.NewFamilyInstance(line, frameSymbol, topLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam); + beam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(topLevel.Id); + beam.get_Parameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE).Set(-slope); + } + if (l2.IsInside(parameter)) + { + var p1 = l2.Evaluate(parameter, false); + Line l = Line.CreateBound(p1, p1 + XYZ.BasisX * length); + var line = l.CreateTransformed(Transform.CreateTranslation(XYZ.BasisZ * 200 / 304.8)); + var beam = doc.Create.NewFamilyInstance(line, frameSymbol, topLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam); + beam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(topLevel.Id); + beam.get_Parameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE).Set(slope); + } + } + //长度方向C型钢 + int m = (int)Math.Floor(length / lengthInterval); + for (int i = 0; i <= m; i++) + { + Line offestl1 = l1.CreateOffset(length / m * i, XYZ.BasisZ) as Line; + Line offestl2 = l2.CreateOffset(length / m * i, -XYZ.BasisZ) as Line; + lines.Add(offestl1); + lines.Add(offestl2); + } + foreach (var l in lines) + { + var line = l.CreateTransformed(Transform.CreateTranslation(XYZ.BasisZ * 35 / 304.8)); + var beam = doc.Create.NewFamilyInstance(line, frameSymbol1, topLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam); + beam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(topLevel.Id); + } + } + private static void CreateFloor(Document doc, IList edges) { var floorCurveArray = new CurveArray(); @@ -166,42 +308,29 @@ namespace RookieStation.Construction.ExecuteCmd /// /// 水平向外偏移距离 /// - private void CreatePWallList(Document doc, CurveLoop loop, double horizontalOffest, double verticalOffest) + private List CreateAluminumPlastic(Document doc, CurveLoop loop, double horizontalOffest, double verticalOffest) { var wallType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).OfCategory(BuiltInCategory.OST_Walls).Cast().Where(w => w.Name.Contains("外墙 - 灰色铝塑板")).FirstOrDefault(); //var wallType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).OfCategory(BuiltInCategory.OST_Walls).Cast().Where(w => w.Name.Contains("铝合金玻璃幕墙")).FirstOrDefault(); - var wallSweepType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Reveals).WhereElementIsElementType().Where(w => w.Name.Contains("3mm")).FirstOrDefault(); var currentLevel = doc.ActiveView.GenLevel; - var topLevel = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).FirstOrDefault(); + var topLevel = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).OrderBy(l => l.Elevation).FirstOrDefault(); double heightOffest = topLevel.Elevation + verticalOffest; var offestCurveLoop = CurveLoop.CreateViaOffset(loop, horizontalOffest, -XYZ.BasisZ); - Transform transform = Transform.CreateTranslation(XYZ.BasisZ * heightOffest); - var translateCurveLoop = CurveLoop.CreateViaTransform(offestCurveLoop, transform); - + //Transform transform = Transform.CreateTranslation(XYZ.BasisZ * heightOffest); + //var translateCurveLoop = CurveLoop.CreateViaTransform(offestCurveLoop, transform); + var walllist = new List(); var pheight = 1220 / 304.8; - foreach (var curve in translateCurveLoop) + foreach (var curve in offestCurveLoop) { Wall wall = null; doc.InvokeSub(ts => { wall = Wall.Create(doc, curve, wallType.Id, topLevel.Id, pheight, 0, false, false); + walllist.Add(wall); }); - if (wall != null) - { - WallSweepInfo info = new WallSweepInfo(WallSweepType.Reveal, true) - { - WallOffset = 100 / 304.8, - Distance = 100 / 304.8, - WallSide = WallSide.Exterior, - DistanceMeasuredFrom = DistanceMeasuredFrom.Base, - }; - if (WallSweep.WallAllowsWallSweep(wall)) - { - var wallsweep = WallSweep.Create(wall, wallSweepType.Id, info); - } - } } + return walllist; } /// @@ -220,6 +349,12 @@ namespace RookieStation.Construction.ExecuteCmd foreach (var curve in offestCurve) { var wall = Wall.Create(doc, curve, wallType.Id, currentLevel.Id, height, 0, false, false); + var horizonGridNum = wall.get_Parameter(BuiltInParameter.SPACING_NUM_DIVISIONS_HORIZ); + if (!horizonGridNum.IsReadOnly) + { + horizonGridNum.Set(1); + } + //var curtainGridLine = doc.GetElement(wall.CurtainGrid.GetUGridLineIds().FirstOrDefault()) as CurtainGridLine; } } @@ -233,7 +368,8 @@ namespace RookieStation.Construction.ExecuteCmd private void CreateGutter(Document doc, CurveLoop loop, double horizontalOffest, double verticalOffest) { ReferenceArray references = new ReferenceArray(); - var level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).FirstOrDefault(); + var level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).OrderBy(l => l.Elevation).FirstOrDefault(); + double heightOffest = level.Elevation + verticalOffest; var offestCurveLoop = CurveLoop.CreateViaOffset(loop, horizontalOffest, -XYZ.BasisZ); Transform transform = Transform.CreateTranslation(XYZ.BasisZ * heightOffest); @@ -276,12 +412,12 @@ namespace RookieStation.Construction.ExecuteCmd /// /// /// 屋顶相对于轮廓向外水平偏移 - /// 相对当前标高以上默认标高的偏移 + /// 相对当前标高以上默认标高的偏移 /// - public FootPrintRoof CreateRoof(Document doc, CurveLoop loop, double horizontalOffest, double verticalOffest) + public FootPrintRoof CreateRoof(Document doc, CurveLoop loop, double horizontalOffest, double bottomOffest) { var roofType = new FilteredElementCollector(doc).OfClass(typeof(RoofType)).OfCategory(BuiltInCategory.OST_Roofs).Cast().Where(symbol => symbol.Name.Contains("彩钢板")).FirstOrDefault(); - var level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).FirstOrDefault(); + var level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OfCategory(BuiltInCategory.OST_Levels).Cast().Where(l => l.Elevation > doc.ActiveView.GenLevel.Elevation).OrderBy(l => l.Elevation).FirstOrDefault(); var roofCurveArray = new CurveArray(); var offestCurve = CurveLoop.CreateViaOffset(loop, horizontalOffest, -XYZ.BasisZ); @@ -298,20 +434,27 @@ namespace RookieStation.Construction.ExecuteCmd roof.set_SlopeAngle(line1, 0.2); roof.set_DefinesSlope(line2, true); roof.set_SlopeAngle(line2, 0.2); - roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM).Set(verticalOffest); + roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM).Set(bottomOffest); return roof; } /// - ///创建梁 + ///创建地梁 /// /// /// + /// 最外侧地梁水平向外偏移量 /// - private void CreateFramings(Document doc, IList edges, double interval) + private void CreateFramings(Document doc, IList edges, double horizontalOffest, double interval) { + CurveLoop loop = CurveLoop.Create(edges); + var offestCurve = CurveLoop.CreateViaOffset(loop, horizontalOffest, -XYZ.BasisZ); List> pointsOnLines = new List>(); - var lines = CreateGridLine(interval, edges); + var lines = CreateGridLine(interval, edges, false); + foreach (var item in offestCurve) + { + lines.Add(item); + } foreach (Line c in lines) { List pointsOnLine = new List(); @@ -326,6 +469,7 @@ namespace RookieStation.Construction.ExecuteCmd pointsOnLines.Add(pointsOnLine); } var frameSymbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_StructuralFraming).Cast().Where(s => s.Name.Contains("250*500")).FirstOrDefault(); + if (!frameSymbol.IsActive) { frameSymbol.Activate(); @@ -360,7 +504,7 @@ namespace RookieStation.Construction.ExecuteCmd foundationSymbol.Activate(); } - var lines = CreateGridLine(interval, edges).Cast().Where(l => l.Direction.Normalize().IsAlmostEqualTo(XYZ.BasisY) || l.Direction.Normalize().IsAlmostEqualTo(-XYZ.BasisY)); + var lines = CreateGridLine(interval, edges, true).Cast().Where(l => l.Direction.Normalize().IsAlmostEqualTo(XYZ.BasisY) || l.Direction.Normalize().IsAlmostEqualTo(-XYZ.BasisY)); //var lines = CreateGridLine(intervalColumn, curves).Where(l => l.Direction.Normalize().IsAlmostEqualTo(XYZ.BasisX) || l.Direction.Normalize().IsAlmostEqualTo(-XYZ.BasisX)); //var lines = CreateGridLine(intervalColumn, curves); //foreach (var l in lines) @@ -395,11 +539,14 @@ namespace RookieStation.Construction.ExecuteCmd /// /// /// - private List CreateGridLine(double maxCellSize, IList edges) + private List CreateGridLine(double maxCellSize, IList edges, bool containEdges) { var pointsOnLines = new List>(); var gridLines = new List(); - gridLines.AddRange(edges); + if (containEdges) + { + gridLines.AddRange(edges); + } //将边界线按跨数分割, foreach (Curve c in edges) { @@ -407,7 +554,7 @@ namespace RookieStation.Construction.ExecuteCmd } if (pointsOnLines.Count == 2) { - var li1 = pointsOnLines[0];//水平下 + var li1 = pointsOnLines[0];//竖直左 var li2 = pointsOnLines[1];//水平上 for (int i = 0; i < li1.Count; i++) { @@ -417,10 +564,10 @@ namespace RookieStation.Construction.ExecuteCmd } else if (pointsOnLines.Count == 4) { - var li1 = pointsOnLines[0];//水平下 + var li1 = pointsOnLines[0];//竖直左 var li3 = pointsOnLines[2];//水平上 - var li2 = pointsOnLines[1];//垂直右 - var li4 = pointsOnLines[3];//垂直左 + var li2 = pointsOnLines[1];//竖直右 + var li4 = pointsOnLines[3];//水平下 for (int i = 0; i < li1.Count; i++) { var line = Line.CreateBound(li1[i], li3[i]); diff --git a/RookieStation/Construction/Views/WpfAutoModeling.xaml b/RookieStation/Construction/Views/WpfAutoModeling.xaml index 4ee44b8..cf9c478 100644 --- a/RookieStation/Construction/Views/WpfAutoModeling.xaml +++ b/RookieStation/Construction/Views/WpfAutoModeling.xaml @@ -35,7 +35,7 @@ x:Name="tbLength" InputMethod.IsInputMethodEnabled="False" PreviewTextInput="tb_PreviewTextInput" - Text="15000" + Text="25000" TextAlignment="Center" />