diff --git a/RookieStation/Drawing/ExecuteCmd/CreatePalanarViewAnnotation.cs b/RookieStation/Drawing/ExecuteCmd/CreatePalanarViewAnnotation.cs index 8ed7240..423fbeb 100644 --- a/RookieStation/Drawing/ExecuteCmd/CreatePalanarViewAnnotation.cs +++ b/RookieStation/Drawing/ExecuteCmd/CreatePalanarViewAnnotation.cs @@ -143,15 +143,17 @@ namespace RookieStation.Drawing.ExecuteCmd doc.Delete(item.Id); } doc.Delete(room.Id); + foreach (ModelCurve curve in modelCurveArray) { doc.Delete(curve.Id); } }, "删除临时房间,空标注"); } - catch (Exception) + catch (Exception ex) { - throw; + Log.WriteLog(ex.Message); + //throw; } return Result.Succeeded; }); @@ -165,11 +167,11 @@ namespace RookieStation.Drawing.ExecuteCmd /// private void JoinWallsAndColumns(Document doc) { - var wallcol = doc.QueryByView(doc.ActiveView); + var wallcol = doc.QueryInstancesByTypeInView(doc.ActiveView); StringBuilder sb = new StringBuilder(); foreach (var wall in wallcol) { - var columncol = doc.QueryByView(doc.ActiveView, BuiltInCategory.OST_StructuralColumns); + var columncol = doc.QueryInstancesByTypeAndCategoryInView(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); @@ -207,7 +209,7 @@ namespace RookieStation.Drawing.ExecuteCmd private Room CreateOuterRoom(View view, out ModelCurveArray modelCurveArray) { Document doc = view.Document; - List wallList = doc.QueryByView(view).Cast().ToList(); + List wallList = doc.QueryInstancesByTypeInView(view).Cast().ToList(); Level level = view.GenLevel; ElementId levelId = view.GenLevel.Id; modelCurveArray = null; @@ -265,8 +267,8 @@ namespace RookieStation.Drawing.ExecuteCmd /// private void JointStructureCom(Document doc, BuiltInCategory builtInCategory1, BuiltInCategory builtInCategory2) { - var collector1 = doc.QueryByBuiltInCategory(builtInCategory1).WhereElementIsNotElementType(); - var collector2 = doc.QueryByBuiltInCategory(builtInCategory2).WhereElementIsNotElementType(); + var collector1 = doc.QueryInstancesByCategory(builtInCategory1).WhereElementIsNotElementType(); + var collector2 = doc.QueryInstancesByCategory(builtInCategory2).WhereElementIsNotElementType(); foreach (var fi1 in collector1) { ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(fi1, false); @@ -292,7 +294,7 @@ namespace RookieStation.Drawing.ExecuteCmd /// private List GetWallListToDim(Document doc) { - var wallList = doc.QueryByView(doc.ActiveView).Where(w => + var wallList = doc.QueryInstancesByTypeInView(doc.ActiveView).Where(w => { if (w.Name.Contains("墙饰面") || w.Name.Contains("踢脚线")) { @@ -398,11 +400,11 @@ namespace RookieStation.Drawing.ExecuteCmd } //Line boundaryLine = Line.CreateBound(curve.GetEndPoint(0), curve.GetEndPoint(1));//直线方向 XYZ offestVector = XYZ.BasisZ.CrossProduct(boundaryLine.Direction).Normalize(); - Options options = new Options() - { - ComputeReferences = true, - DetailLevel = ViewDetailLevel.Fine - }; + //Options options = new Options() + //{ + // ComputeReferences = true, + // DetailLevel = ViewDetailLevel.Fine + //}; List faces = new List(); List mainWallFaces = RsRevitUtils.GetSideFacesByElement(wall); faces.AddRange(mainWallFaces); @@ -436,7 +438,7 @@ namespace RookieStation.Drawing.ExecuteCmd try { var scale = doc.ActiveView.Scale; - var tranform = Transform.CreateTranslation(offestVector * scale * 15 / 304.8); + var tranform = Transform.CreateTranslation(offestVector * scale * 20 / 304.8); var wallcurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line; Line lengthDimLine = wallcurve.CreateTransformed(tranform) as Line; Dimension templengthdim = doc.Create.NewDimension(doc.ActiveView, lengthDimLine, wallRefernceArray); @@ -456,7 +458,7 @@ namespace RookieStation.Drawing.ExecuteCmd var refer2 = finallengthdim.References.get_Item(finallengthdim.References.Size - 1); referenceArray.Append(refer1); referenceArray.Append(refer2); - var tranform1 = Transform.CreateTranslation(offestVector * scale * 20 / 304.8); + var tranform1 = Transform.CreateTranslation(offestVector * scale * 25 / 304.8); Line lengthTotalDimLine = wallcurve.CreateTransformed(tranform1) as Line; doc.Create.NewDimension(doc.ActiveView, lengthTotalDimLine, referenceArray); @@ -566,18 +568,18 @@ namespace RookieStation.Drawing.ExecuteCmd { if (IsTagAll) { - var instances = doc.QueryByView(doc.ActiveView, cate).Cast(); + var instances = doc.QueryInstancesByCategoryInView(doc.ActiveView, cate).Cast(); all.AddRange(instances); } else { - var groups = doc.QueryByView(doc.ActiveView, cate).Cast().GroupBy(instance => instance.Symbol.Name); - - foreach (var group in groups) - { - var instance = group.FirstOrDefault(); - all.Add(instance); - } + var group = doc.QueryInstancesByCategoryInView(doc.ActiveView, cate).Cast().GroupBy(instance => instance.Symbol.Name).Select(g => g.FirstOrDefault()); + all.AddRange(group); + //foreach (var group in groups) + //{ + // var instance = group.FirstOrDefault(); + // all.Add(instance); + //} } } @@ -634,7 +636,7 @@ namespace RookieStation.Drawing.ExecuteCmd /// private bool CreateLightTags(Document doc, out List lights) { - lights = doc.QueryByView(doc.ActiveView, BuiltInCategory.OST_LightingFixtures).Cast().ToList(); + lights = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_LightingFixtures).Cast().ToList(); var scale = doc.ActiveView.Scale; foreach (var light in lights) { @@ -730,7 +732,7 @@ namespace RookieStation.Drawing.ExecuteCmd private static void CreateShelvesDimensions(Document doc) { - var shelves = doc.QueryByView(doc.ActiveView, BuiltInCategory.OST_Furniture).Cast().Where(fi => fi.Symbol.FamilyName.Contains("货架")).ToList(); + var shelves = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_Furniture).Cast().Where(fi => fi.Symbol.FamilyName.Contains("货架")).ToList(); CreateShelvesXDimensions(doc, shelves); CreateShelvesYDimensions(doc, shelves); @@ -968,7 +970,7 @@ namespace RookieStation.Drawing.ExecuteCmd List joinedElements = new List(); var loc = w.Location as LocationCurve; Curve curve = loc.Curve; - FilteredElementCollector eles = doc.QueryByView(doc.ActiveView).WhereElementIsNotElementType(); + FilteredElementCollector eles = doc.QueryInstancesByTypeInView(doc.ActiveView).WhereElementIsNotElementType(); StringBuilder sb = new StringBuilder(); foreach (Wall wall in eles) { diff --git a/RookieStation/Drawing/ExecuteCmd/CreateViewPlanAnnotation.cs b/RookieStation/Drawing/ExecuteCmd/CreateViewPlanAnnotation.cs index de2be27..a8e26e1 100644 --- a/RookieStation/Drawing/ExecuteCmd/CreateViewPlanAnnotation.cs +++ b/RookieStation/Drawing/ExecuteCmd/CreateViewPlanAnnotation.cs @@ -40,7 +40,7 @@ namespace RookieStation.Drawing.ExecuteCmd CreateWallDimension(doc); CreateColumnsDimension(doc); CreateBeamsDimension(doc); - var visableCol = doc.QueryByView(v).ToElements(); + var visableCol = doc.QueryInstancesInView(v).ToElements(); doc.Invoke(ts => { @@ -497,8 +497,8 @@ namespace RookieStation.Drawing.ExecuteCmd private void JointStructureCom(Document doc, BuiltInCategory builtInCategory1, BuiltInCategory builtInCategory2) { - var collector1 = doc.QueryByBuiltInCategory(builtInCategory1).WhereElementIsNotElementType(); - var collector2 = doc.QueryByBuiltInCategory(builtInCategory2).WhereElementIsNotElementType(); + var collector1 = doc.QueryInstancesByCategory(builtInCategory1).WhereElementIsNotElementType(); + var collector2 = doc.QueryInstancesByCategory(builtInCategory2).WhereElementIsNotElementType(); foreach (var fi1 in collector1) { ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(fi1, false); @@ -519,11 +519,11 @@ namespace RookieStation.Drawing.ExecuteCmd private void JoinWallsAndColumns(Document doc) { - var wallcol = doc.QueryByView(doc.ActiveView); + var wallcol = doc.QueryInstancesByTypeInView(doc.ActiveView); StringBuilder sb = new StringBuilder(); foreach (var wall in wallcol) { - var columncol = doc.QueryByView(doc.ActiveView, BuiltInCategory.OST_StructuralColumns); + var columncol = doc.QueryInstancesByTypeAndCategoryInView(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); @@ -618,7 +618,7 @@ namespace RookieStation.Drawing.ExecuteCmd List joinedElements = new List(); var loc = w.Location as LocationCurve; Curve curve = loc.Curve; - FilteredElementCollector eles = doc.QueryByView(doc.ActiveView).WhereElementIsNotElementType(); + FilteredElementCollector eles = doc.QueryInstancesByTypeInView(doc.ActiveView).WhereElementIsNotElementType(); IntersectionResultArray intersection; StringBuilder sb = new StringBuilder(); foreach (Element e in eles) @@ -641,7 +641,7 @@ namespace RookieStation.Drawing.ExecuteCmd private static void CreateWallDimension(Document doc) { - var wallList = doc.QueryByView(doc.ActiveView).Where(w => + var wallList = doc.QueryInstancesByTypeInView(doc.ActiveView).Where(w => { if (w.Name.Contains("墙饰面") || w.Name.Contains("踢脚线")) { diff --git a/RookieStation/Drawing/ExecuteCmd/CreateViewSectionAnnotation.cs b/RookieStation/Drawing/ExecuteCmd/CreateViewSectionAnnotation.cs index d1940eb..e0f9a8a 100644 --- a/RookieStation/Drawing/ExecuteCmd/CreateViewSectionAnnotation.cs +++ b/RookieStation/Drawing/ExecuteCmd/CreateViewSectionAnnotation.cs @@ -1,12 +1,14 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; +using HandyControl.Controls; using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media.Media3D; @@ -25,49 +27,114 @@ namespace RookieStation.Drawing.ExecuteCmd DocumentSet docset = uiapp.Application.Documents; var v = doc.ActiveView; + //if (v.ViewType == ViewType.Elevation || v.ViewType == ViewType.Section) if (v is ViewSection) { - doc.InvokeGroup(tg => + try { - doc.Invoke(ts => + doc.InvokeGroup(tg => { - var walls = new FilteredElementCollector(doc, v.Id).OfClass(typeof(Wall)).OfCategory(BuiltInCategory.OST_StackedWalls).ToList(); - var stackedWallDistincts = walls.GroupBy(g => g.Name).Select(w => w.FirstOrDefault()); - foreach (Wall stackedwall in stackedWallDistincts) + doc.Invoke(ts => { - List tags = new List(); - if (stackedwall != null && v.ViewDirection.CrossProduct(stackedwall.Orientation).IsAlmostEqualTo(XYZ.Zero)) - { - var ids = stackedwall.GetStackedWallMemberIds(); - for (int i = 0; i < ids.Count; i++) - { - var wall = doc.GetElement(ids[i]); - var loc = RsRevitUtils.GetLocationCurveByElement(wall).Evaluate(0.5, true) + new XYZ(0, 0, 20 / 304.8); - var tagtext = loc + new XYZ(0, 0, 10 * (i + 1)); - var tag = IndependentTag.Create(doc, v.Id, new Reference(wall), true, TagMode.TM_ADDBY_MATERIAL, TagOrientation.Horizontal, loc); - doc.Regenerate(); + #region MyRegion - //tag.LeaderEnd = loc; - //tag.TagHeadPosition = tagtext; - tags.Add(tag); + //var walls = new FilteredElementCollector(doc, v.Id).OfClass(typeof(Wall)).OfCategory(BuiltInCategory.OST_StackedWalls).ToList(); + //var stackedWallDistincts = walls.GroupBy(g => g.Name).Select(w => w.FirstOrDefault()); + //foreach (Wall stackedwall in stackedWallDistincts) + //{ + // List tags = new List(); + // if (stackedwall != null && v.ViewDirection.CrossProduct(stackedwall.Orientation).IsAlmostEqualTo(XYZ.Zero)) + // { + // var ids = stackedwall.GetStackedWallMemberIds(); + // for (int i = 0; i < ids.Count; i++) + // { + // var wall = doc.GetElement(ids[i]); + // var loc = RsRevitUtils.GetLocationCurveByElement(wall).Evaluate(0.5, true) + new XYZ(0, 0, 20 / 304.8); + // var tagtext = loc + new XYZ(0, 0, 10 * (i + 1)); + // var tag = IndependentTag.Create(doc, v.Id, new Reference(wall), true, TagMode.TM_ADDBY_MATERIAL, TagOrientation.Horizontal, loc); + // doc.Regenerate(); + + // //tag.LeaderEnd = loc; + // //tag.TagHeadPosition = tagtext; + // tags.Add(tag); + // } + // //for (int i = 0; i < tags.Count; i++) + // //{ + // // IndependentTag tag = tags[i]; + // // Wall wall = tag.GetTaggedLocalElement() as Wall; + // // double wallLength = wall.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble(); + // // tag.LeaderElbow = new XYZ(tag.LeaderEnd.X + wallLength / 2, tag.LeaderEnd.Y + wallLength / 2, (i * 0.1 + 1) * 20); + // // tag.TagHeadPosition = new XYZ(tag.LeaderEnd.X + wallLength / 2 + 10, tag.LeaderEnd.Y + wallLength / 2 + 10, (i * 0.1 + 1) * 20); + // // tag.LeaderEnd += new XYZ(wallLength / 2, wallLength / 2, 0); + // //} + // } + //} + + //var box = doc.ActiveView.CropBox; + //var box = doc.ActiveView.Outline; + + #endregion MyRegion + + //裁剪视图选项设置 + doc.ActiveView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(1); + doc.ActiveView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION_VISIBLE).Set(1); + doc.Regenerate(); + + CreateMaterialTags(doc); + FurnSys(doc, BuiltInCategory.OST_FurnitureSystems); + doc.ActiveView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(1); + doc.ActiveView.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION_VISIBLE).Set(0); + //tags.AddRange(); + }); + doc.Invoke(ts => + { + var scale = doc.ActiveView.Scale; + var independentTags = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(IndependentTag)).Cast().Where(tag => tag.HasLeader).ToList(); + if (independentTags.Count > 0) + { + var groups = RsRevitUtils.GroupTags(independentTags); + + foreach (var tags in groups) + { + RsRevitUtils.ArrangeElevationTags(doc.ActiveView, scale * 10 / 304.8, tags); } - //for (int i = 0; i < tags.Count; i++) - //{ - // IndependentTag tag = tags[i]; - // Wall wall = tag.GetTaggedLocalElement() as Wall; - // double wallLength = wall.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble(); - // tag.LeaderElbow = new XYZ(tag.LeaderEnd.X + wallLength / 2, tag.LeaderEnd.Y + wallLength / 2, (i * 0.1 + 1) * 20); - // tag.TagHeadPosition = new XYZ(tag.LeaderEnd.X + wallLength / 2 + 10, tag.LeaderEnd.Y + wallLength / 2 + 10, (i * 0.1 + 1) * 20); - // tag.LeaderEnd += new XYZ(wallLength / 2, wallLength / 2, 0); - //} } - } + }, "调整标注"); + doc.Invoke(ts => + { + var scale = doc.ActiveView.Scale; + var independentTags = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(IndependentTag)).Cast().Where(tag => tag.HasLeader).ToList(); + if (independentTags.Count > 0) + { + var groups = RsRevitUtils.GroupTags(independentTags); + + foreach (var tags in groups) + { + RsRevitUtils.ArrangeElevationTags(doc.ActiveView, scale * 10 / 304.8, tags); + } + } + }, "再次调整标注"); }); - }); + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); + throw; + } + //doc.Invoke(ts => + //{ + // foreach (var tag in tags) + // { + // if (tag.TagText == "") + // { + // doc.Delete(tag.Id); + // } + // } + //}); } else { - message = "需在立面视图使用此命令"; + message = "需在立面或剖面视图使用此命令"; //TaskDialog.Show("温馨提示", "需在立面视图使用此命令"); return Result.Failed; } @@ -77,13 +144,184 @@ namespace RookieStation.Drawing.ExecuteCmd return Result.Succeeded; } - private void FurnSys(Document doc) + /// + /// 是否被遮挡 + /// + /// + /// + /// + public bool IsObscuredInView(FamilyInstance instance, View view) { - var furnsys = doc.QueryByBuiltInCategory(BuiltInCategory.OST_FurnitureSystems); - foreach (var item in furnsys) + Document doc = view.Document; + var loc = instance.GetTransform().Origin; + Line l = Line.CreateBound(loc, loc + view.ViewDirection * 10); + ModelCurve mc = doc.Create.NewModelCurve(l, SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, loc))); + doc.Regenerate(); + BoundingBoxXYZ mcBox = mc.get_BoundingBox(doc.ActiveView); + Outline ol = new Outline(mcBox.Min, mcBox.Max); + BoundingBoxIntersectsFilter boxFilter = new BoundingBoxIntersectsFilter(ol); + List idsToExclude = new List(); + idsToExclude.Add(instance.Id); + idsToExclude.Add(mc.Id); + FilteredElementCollector fec = new FilteredElementCollector(doc, doc.ActiveView.Id).Excluding(idsToExclude); + List eles = fec.WherePasses(boxFilter).ToElements().ToList(); + if (eles.Count == 0) { - IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(item), true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, new XYZ()); + return false; } + doc.Delete(mc.Id); + return true; + } + + //private bool IsAllInView(Wall wall) + //{ + // Document doc = wall.Document; + // var ele = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_Viewers); + // var box = ele.FirstOrDefault().get_BoundingBox(doc.ActiveView); + // XYZ max = box.Max; + // XYZ min = box.Min; + // var loc = RsRevitUtils.GetLocationCurveByElement(wall); + // var startp = loc.GetEndPoint(0); + // var endp = loc.GetEndPoint(1); + // Line l1 = Line.CreateBound(startp, max); + // Line l2 = Line.CreateBound(startp, min); + // var angle1 = l1.Direction.AngleTo(l2.Direction); + // Line l3 = Line.CreateBound(endp, max); + // Line l4 = Line.CreateBound(endp, min); + // var angle2 = l3.Direction.AngleTo(l4.Direction); + // if (angle1 > Math.PI / 2 && angle2 > Math.PI / 2) + // { + // return true; + // } + // return false; + //} + + private bool IsCenterPointInView(Wall wall) + { + Document doc = wall.Document; + var ele = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_Viewers); + var box = ele.FirstOrDefault().get_BoundingBox(doc.ActiveView); + XYZ max = box.Max; + XYZ min = box.Min; + var centerp = RsRevitUtils.GetLocationCurveByElement(wall).Evaluate(0.5, true); + + Line l1 = Line.CreateBound(centerp, max); + Line l2 = Line.CreateBound(centerp, min); + var angle1 = l1.Direction.AngleTo(l2.Direction); + if (angle1 > Math.PI / 2) + { + return true; + } + return false; + } + + private List CreateMaterialTags(Document doc) + { + var ele = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_Viewers); + var box = ele.FirstOrDefault().get_BoundingBox(doc.ActiveView); + XYZ max = box.Max; + XYZ min = box.Min; + Line topLine = Line.CreateBound(min + XYZ.BasisZ * (max.Z - min.Z), max); + Line topDimLine = Line.CreateBound(min + XYZ.BasisZ * (max.Z - min.Z), max).CreateOffset(200 / 304.8, doc.ActiveView.ViewDirection) as Line; + + Line leftDimLine = Line.CreateBound(min, min + XYZ.BasisZ * (max.Z - min.Z)).CreateOffset(200 / 304.8, doc.ActiveView.ViewDirection) as Line; + List tags = new List(); + var wallList = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(Wall)).OfCategory(BuiltInCategory.OST_Walls).Cast().Where(w => w.Orientation.IsAlmostEqualTo(doc.ActiveView.ViewDirection)).ToList(); + var Groups = wallList.GroupBy(w => w.Name); + var walls = Groups.Select(g => g.LastOrDefault()).ToList(); + //var wallIds = Groups.Select(g => g.FirstOrDefault()).Select(w => w.Id).ToList(); + + foreach (Wall wall in walls) + { + //单独做踢脚线、饰面的时候可以用 + if (wall.Name.Contains("墙饰面") || wall.Name.Contains("踢脚线")) + { + var reference = new Reference(wall); + XYZ loc = RsRevitUtils.GetLocationCurveByElement(wall).Evaluate(0.5, true); + var baseOffest = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();//底部偏移 + XYZ finalend = loc + (baseOffest + 20 / 304.8) * XYZ.BasisZ;//引线端点 + IndependentTag tag = IndependentTag.Create(doc, doc.ActiveView.Id, reference, true, TagMode.TM_ADDBY_MATERIAL, TagOrientation.Horizontal, XYZ.Zero); + var distance = topLine.GetEndPoint(1) - finalend.Z * XYZ.BasisZ;//与视图最顶部的边界线的距离 + tag.LeaderEnd = finalend; + tag.LeaderElbow = finalend + XYZ.BasisZ * distance.Z + 200 / 304.8 * XYZ.BasisZ; + tag.TagHeadPosition = tag.LeaderElbow + doc.ActiveView.RightDirection * 200 / 304.8; + tags.Add(tag); + } + var faces = RsRevitUtils.GetFaceByElement(wall); + var locCurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line; + ReferenceArray heightReferenceArray = new ReferenceArray(); + ReferenceArray lengthReferenceArray = new ReferenceArray(); + foreach (var face in faces) + { + var plane = face as PlanarFace; + if (plane != null && plane.FaceNormal.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero)) + { + heightReferenceArray.Append(face.Reference); + } + else if (plane != null && plane.FaceNormal.CrossProduct(locCurve.Direction).IsAlmostEqualTo(XYZ.Zero)) + { + lengthReferenceArray.Append(face.Reference); + } + } + try + { + doc.Create.NewDimension(doc.ActiveView, leftDimLine, heightReferenceArray); + doc.Create.NewDimension(doc.ActiveView, topLine, lengthReferenceArray); + } + catch (Exception) + { + continue; + } + + //Line line = RsRevitUtils.GetLocationCurveByElement(element) as Line; + //var angle = doc.ActiveView.ViewDirection.AngleTo(line.Direction); + //if (angle >= Math.PI / 2 + 0.001) + //{ + // angle = doc.ActiveView.ViewDirection.AngleTo(-line.Direction); + //} + //if (line != null && angle > Math.PI / 4 && angle < Math.PI / 2) + //{ + //} + } + return tags; + } + + private List FurnSys(Document doc, params BuiltInCategory[] builtInCategories) + { + var ele = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_Viewers); + var box = ele.FirstOrDefault().get_BoundingBox(doc.ActiveView); + XYZ max = box.Max; + XYZ min = box.Min; + Line topLine = Line.CreateBound(min + XYZ.BasisZ * (max.Z - min.Z), max); + List tags = new List(); + List all = new List(); + + foreach (var cate in builtInCategories) + { + var groups = doc.QueryInstancesByCategoryInView(doc.ActiveView, BuiltInCategory.OST_FurnitureSystems).Cast().GroupBy(w => w.Name); + foreach (var group in groups) + { + var instance = group.FirstOrDefault(); + all.Add(instance); + } + } + foreach (var instance in all) + { + var tag = IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(instance), true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, XYZ.Zero); + var p = topLine.GetEndPoint(0); + if (tag.LeaderEndCondition == LeaderEndCondition.Attached) + { + tag.LeaderEndCondition = LeaderEndCondition.Free; + } + doc.Regenerate(); + tag.LeaderElbow = tag.LeaderEnd + (p.Z - tag.LeaderEnd.Z + 200 / 304.8) * XYZ.BasisZ; + tag.TagHeadPosition = tag.LeaderElbow + doc.ActiveView.RightDirection * 200 / 304.8; + //if (!IsObscuredInView(item, doc.ActiveView)) + //{ + //} + tags.Add(tag); + } + return tags; } } } \ No newline at end of file diff --git a/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml.cs b/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml.cs index d3fda10..bc0dacb 100644 --- a/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml.cs +++ b/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml.cs @@ -256,7 +256,7 @@ namespace RookieStation.ParcelAreaModule.Views } CurrentNumber = LastNum + 1; doc.Regenerate(); - var fis = doc.QueryByType().Cast().Where(e => e.Symbol.FamilyName.Contains("货架端牌")).ToList(); + var fis = doc.QueryInstancesByType().Cast().Where(e => e.Symbol.FamilyName.Contains("货架端牌")).ToList(); RsRevitUtils.DeleteOverlapFamilyInstance(doc, fis); }, "创建端牌"); } @@ -423,7 +423,7 @@ namespace RookieStation.ParcelAreaModule.Views ////族的左右方向向量(重要,且常用) //var hand = fi.HandOrientation; doc.Regenerate(); - var fis = doc.QueryByType().Cast().Where(e => e.Symbol.FamilyName.Contains("货架端牌")).ToList(); + var fis = doc.QueryInstancesByType().Cast().Where(e => e.Symbol.FamilyName.Contains("货架端牌")).ToList(); RsRevitUtils.DeleteOverlapFamilyInstance(doc, fis); #endregion 备用 diff --git a/RookieStation/ProjectConfig/ExcuteCmd/ProjectSettings.cs b/RookieStation/ProjectConfig/ExcuteCmd/ProjectSettings.cs index df61f20..93b60d5 100644 --- a/RookieStation/ProjectConfig/ExcuteCmd/ProjectSettings.cs +++ b/RookieStation/ProjectConfig/ExcuteCmd/ProjectSettings.cs @@ -44,9 +44,9 @@ namespace RookieStation.ProjectConfig.ExecuteCmd Log.WriteLog(ex.Message); } - var viewSheets = doc.QueryByType(); - var viewPlans = doc.QueryByType(); - var levels = doc.QueryByType().Cast().OrderBy(l => l.Elevation); + var viewSheets = doc.QueryInstancesByType(); + var viewPlans = doc.QueryInstancesByType(); + var levels = doc.QueryInstancesByType().Cast().OrderBy(l => l.Elevation); foreach (Level level in levels) { if (Math.Round(level.Elevation) != 0.0) diff --git a/RookieStation/Utils/DocumentExtension.cs b/RookieStation/Utils/DocumentExtension.cs index 2f3c557..e6782eb 100644 --- a/RookieStation/Utils/DocumentExtension.cs +++ b/RookieStation/Utils/DocumentExtension.cs @@ -202,7 +202,7 @@ namespace RookieStation.Utils } } - public static FilteredElementCollector QueryByType(this Document doc) where T : Element + public static FilteredElementCollector QueryInstancesByType(this Document doc) where T : Element { return new FilteredElementCollector(doc).OfClass(typeof(T)).WhereElementIsNotElementType(); } @@ -214,31 +214,47 @@ namespace RookieStation.Utils /// /// /// - public static FilteredElementCollector QueryByView(this Document doc, View view) where T : Element + public static FilteredElementCollector QueryInstancesByTypeInView(this Document doc, View view) where T : Element { return new FilteredElementCollector(doc, view.Id).OfClass(typeof(T)).WhereElementIsNotElementType(); } + public static FilteredElementCollector QueryInstancesByTypeAndCategory(this Document doc, BuiltInCategory category) where T : Element + { + return new FilteredElementCollector(doc).OfClass(typeof(T)).OfCategory(category).WhereElementIsNotElementType(); + } + /// - /// 收集当前平面视图的某类图元 + /// 收集当前平面视图的某类别图元 /// /// /// /// /// - public static FilteredElementCollector QueryByView(this Document doc, View view, BuiltInCategory builtInCategory) where T : Element + public static FilteredElementCollector QueryInstancesByTypeAndCategoryInView(this Document doc, View view, BuiltInCategory builtInCategory) where T : Element { return new FilteredElementCollector(doc, view.Id).OfClass(typeof(T)).OfCategory(builtInCategory).WhereElementIsNotElementType(); } /// - /// 收集当前平面视图的某类图元 + /// 通过类别获取元素 + /// + /// + /// + /// + public static FilteredElementCollector QueryInstancesByCategory(this Document doc, BuiltInCategory category) + { + return new FilteredElementCollector(doc).OfCategory(category).WhereElementIsNotElementType(); + } + + /// + /// 收集当前平面视图的类别图元 /// /// /// /// /// - public static FilteredElementCollector QueryByView(this Document doc, View view, BuiltInCategory builtInCategory) + public static FilteredElementCollector QueryInstancesByCategoryInView(this Document doc, View view, BuiltInCategory builtInCategory) { return new FilteredElementCollector(doc, view.Id).OfCategory(builtInCategory).WhereElementIsNotElementType(); } @@ -249,25 +265,9 @@ namespace RookieStation.Utils /// /// /// - public static FilteredElementCollector QueryByView(this Document doc, View view) + public static FilteredElementCollector QueryInstancesInView(this Document doc, View view) { return new FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType(); } - - /// - /// 通过类别获取元素 - /// - /// - /// - /// - public static FilteredElementCollector QueryByBuiltInCategory(this Document doc, BuiltInCategory category) - { - return new FilteredElementCollector(doc).OfCategory(category).WhereElementIsNotElementType(); - } - - public static FilteredElementCollector QueryByClassAndBuiltInCategory(this Document doc, BuiltInCategory category) where T : Element - { - return new FilteredElementCollector(doc).OfClass(typeof(T)).OfCategory(category).WhereElementIsNotElementType(); - } } } \ No newline at end of file diff --git a/RookieStation/Utils/RsRevitUtils.cs b/RookieStation/Utils/RsRevitUtils.cs index cd5f949..daac109 100644 --- a/RookieStation/Utils/RsRevitUtils.cs +++ b/RookieStation/Utils/RsRevitUtils.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using static System.Net.WebRequestMethods; using Autodesk.Revit.UI; +using HandyControl.Controls; namespace RookieStation.Utils { @@ -51,7 +52,7 @@ namespace RookieStation.Utils /// public static View NewLegend(Document doc, string legendName, int viewScale) { - IEnumerable legends = doc.QueryByClassAndBuiltInCategory(BuiltInCategory.OST_Views).Cast().Where(v => v.ViewType == ViewType.Legend); + IEnumerable legends = doc.QueryInstancesByTypeAndCategory(BuiltInCategory.OST_Views).Cast().Where(v => v.ViewType == ViewType.Legend); Autodesk.Revit.DB.View newLegend = null; if (legends.Count() == 0) @@ -400,11 +401,13 @@ namespace RookieStation.Utils /// 元素 /// 打开方式 /// 所有的面 - public static List GetFaceByElement(Element item, Options options) + public static List GetFaceByElement(Element item) { + var ops = new Options(); + ops.ComputeReferences = true;//计算参照,为true时才能进行得到参照 List faces = new List(); //根据打开的方式得到几何信息 - GeometryElement geometry = item.get_Geometry(options); + GeometryElement geometry = item.get_Geometry(ops); foreach (GeometryObject geomObj in geometry) { //geomObj为几何实例 @@ -580,9 +583,7 @@ namespace RookieStation.Utils var instance = familyInstance.GetSubComponentIds() .Select(a => doc.GetElement(a)) .ToList(); - var ops = new Options(); - ops.ComputeReferences = true;//计算参照,为true时才能进行得到参照 - List faces = GetFaceByElement(instance.FirstOrDefault(), ops); + List faces = GetFaceByElement(instance.FirstOrDefault()); //List listFamilyInstances = new FilteredElementCollector(doc, doc.ActiveView.Id) // .OfClass(typeof(FamilyInstance)) // .Cast() @@ -839,7 +840,7 @@ namespace RookieStation.Utils tag.LeaderElbow = tag.LeaderEnd + (tag.TagHeadPosition.Y - tag.LeaderEnd.Y) * XYZ.BasisY; } } - //tag.LeaderEndCondition = LeaderEndCondition.Attached; + tag.LeaderEndCondition = LeaderEndCondition.Attached; } } @@ -895,7 +896,11 @@ namespace RookieStation.Utils orderedTags = tags.OrderBy(a => a.TagHeadPosition.Z).ThenByDescending(b => b.TagHeadPosition.X); } baseTag = orderedTags.FirstOrDefault(); - + if (baseTag.LeaderEndCondition == LeaderEndCondition.Attached) + { + baseTag.LeaderEndCondition = LeaderEndCondition.Free; + baseTag.TagOrientation = TagOrientation.Horizontal; + } baseTag.LeaderElbow = new XYZ(baseTag.LeaderEnd.X, baseTag.LeaderEnd.Y, baseTag.TagHeadPosition.Z); for (int i = 1; i < orderedTags.Count(); i++) @@ -934,6 +939,10 @@ namespace RookieStation.Utils tag.LeaderElbow = tag.LeaderEnd + (tag.TagHeadPosition.Z - tag.LeaderEnd.Z) * XYZ.BasisZ; } } + if (tag.CanLeaderEndConditionBeAssigned(LeaderEndCondition.Attached)) + { + tag.LeaderEndCondition = LeaderEndCondition.Attached; + } } } diff --git a/RookieStationSetup/RookieStationSetup.vdproj b/RookieStationSetup/RookieStationSetup.vdproj index c2cae2d..bf9ad43 100644 --- a/RookieStationSetup/RookieStationSetup.vdproj +++ b/RookieStationSetup/RookieStationSetup.vdproj @@ -2402,15 +2402,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:菜鸟驿站工具集" - "ProductCode" = "8:{33F732DA-22DF-4FB3-BA10-91AD7C2662FF}" - "PackageCode" = "8:{67553632-A83F-4028-A13A-3CBA3FB5243B}" + "ProductCode" = "8:{34472669-5555-4677-BDCA-76AE92FB33A0}" + "PackageCode" = "8:{68A99B7F-1AC0-4D64-932E-9E4C9549813D}" "UpgradeCode" = "8:{127EC3EC-7539-468B-84EA-E1ECDD6204E6}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:TRUE" - "ProductVersion" = "8:1.0.0" + "ProductVersion" = "8:1.0.1" "Manufacturer" = "8:YTX Engineering" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" @@ -2881,7 +2881,7 @@ { "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_106061D90DD7421EAB1EE10373608018" { - "SourcePath" = "8:..\\AddinDeployer\\obj\\Debug\\AddinDeployer.dll" + "SourcePath" = "8:..\\AddinDeployer\\obj\\Release\\AddinDeployer.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7C1EF99E309C4A3FB02B902F06BE7F60" @@ -2909,7 +2909,7 @@ } "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_FBE461B9D4BD4603919E2821D88FB7CB" { - "SourcePath" = "8:..\\RookieStation\\obj\\Debug\\RookieStation.dll" + "SourcePath" = "8:..\\RookieStation\\obj\\Release\\RookieStation.dll" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_7C1EF99E309C4A3FB02B902F06BE7F60"