diff --git a/RookieStation/CommonTools/ExecuteCmd/CmdEncryptFamily.cs b/RookieStation/CommonTools/ExecuteCmd/CmdEncryptFamily.cs new file mode 100644 index 0000000..0de61cc --- /dev/null +++ b/RookieStation/CommonTools/ExecuteCmd/CmdEncryptFamily.cs @@ -0,0 +1,91 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; +using RookieStation.Extension; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RookieStation.CommonTools.ExecuteCmd +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdEncryptFamily : 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; + var instances = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).Cast(); + var distinctInstances = instances.GroupBy(f => f.Symbol.FamilyName).Select(f => f.FirstOrDefault()); + + try + { + doc.InvokeGroup(tg => + { + foreach (var ins in distinctInstances) + { + var famdoc = doc.EditFamily(ins.Symbol.Family); + var formcol = new FilteredElementCollector(famdoc).OfClass(typeof(GenericForm)).Cast(); + var vcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.View)).Cast(); + var dimcol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.Dimension)).Cast(); + var curvecol = new FilteredElementCollector(famdoc).OfClass(typeof(Autodesk.Revit.DB.CurveElement)).Cast(); + + famdoc.Invoke(ts => + { + foreach (var view in vcol) + { + var elemidtohide = new List(); + foreach (GenericForm form in formcol) + { + if (form.CanBeHidden(view)) + { + elemidtohide.Add(form.Id); + } + } + foreach (Dimension dim in dimcol) + { + if (dim.CanBeHidden(view)) + { + elemidtohide.Add(dim.Id); + } + } + foreach (CurveElement curve in curvecol) + { + if (curve.CanBeHidden(view)) + { + elemidtohide.Add(curve.Id); + } + } + + if (elemidtohide.Count > 0) + { + view.HideElements(elemidtohide); + } + } + }); + + famdoc.LoadFamily(doc, new RsFamilyLoadOption()); + + famdoc.Close(false); + } + }, "加密族"); + } + catch (Exception ex) + { + if (!(ex is Autodesk.Revit.Exceptions.OperationCanceledException)) + { + message = ex.Message; + return Result.Failed; + } + } + return Result.Succeeded; + } + } +} \ No newline at end of file diff --git a/RookieStation/CommonTools/ExtHandler/FamilyDockablePaneHandler.cs b/RookieStation/CommonTools/ExtHandler/FamilyDockablePaneHandler.cs index db2b14f..d74a548 100644 --- a/RookieStation/CommonTools/ExtHandler/FamilyDockablePaneHandler.cs +++ b/RookieStation/CommonTools/ExtHandler/FamilyDockablePaneHandler.cs @@ -1,6 +1,6 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; -using RookieStation.CommonTools.Model; +using RookieStation.CommonTools.Models; using RookieStation.Extension; using RookieStation.Utils; using System; diff --git a/RookieStation/CommonTools/Model/FamilyInfo.cs b/RookieStation/CommonTools/Models/FamilyInfo.cs similarity index 96% rename from RookieStation/CommonTools/Model/FamilyInfo.cs rename to RookieStation/CommonTools/Models/FamilyInfo.cs index ef68b0f..7239b9c 100644 --- a/RookieStation/CommonTools/Model/FamilyInfo.cs +++ b/RookieStation/CommonTools/Models/FamilyInfo.cs @@ -10,7 +10,7 @@ using System.Windows.Media.Imaging; using System.Windows; using RookieStation.Utils; -namespace RookieStation.CommonTools.Model +namespace RookieStation.CommonTools.Models { internal class FamilyInfo { diff --git a/RookieStation/CommonTools/View/WpfFamilyDockablePane.xaml b/RookieStation/CommonTools/Views/WpfFamilyDockablePane.xaml similarity index 98% rename from RookieStation/CommonTools/View/WpfFamilyDockablePane.xaml rename to RookieStation/CommonTools/Views/WpfFamilyDockablePane.xaml index 9cbc169..835afe3 100644 --- a/RookieStation/CommonTools/View/WpfFamilyDockablePane.xaml +++ b/RookieStation/CommonTools/Views/WpfFamilyDockablePane.xaml @@ -1,5 +1,5 @@  /// WpfFamilyDockablePane.xaml 的交互逻辑 diff --git a/RookieStation/Drawing/ExecuteCmd/CmdAutoCreateLegend.cs b/RookieStation/Drawing/ExecuteCmds/CmdAutoCreateLegend.cs similarity index 98% rename from RookieStation/Drawing/ExecuteCmd/CmdAutoCreateLegend.cs rename to RookieStation/Drawing/ExecuteCmds/CmdAutoCreateLegend.cs index 5cb1aaa..3e65e93 100644 --- a/RookieStation/Drawing/ExecuteCmd/CmdAutoCreateLegend.cs +++ b/RookieStation/Drawing/ExecuteCmds/CmdAutoCreateLegend.cs @@ -2,7 +2,7 @@ using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; -using RookieStation.Drawing.Model; +using RookieStation.Drawing.Models; using RookieStation.Extension; using RookieStation.ProjectConfig; using RookieStation.Utils; @@ -10,7 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace RookieStation.Drawing.ExecuteCmd +namespace RookieStation.Drawing.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -73,7 +73,7 @@ namespace RookieStation.Drawing.ExecuteCmd DesignOrders = UserConstant.Orders }; shelfStatistic.LinearMetre = shelfStatistic.Count * l; - shelfStatistic.CapacityOrders = shelfStatistic.Count * 80; + shelfStatistic.CapacityOrders = (int)shelfStatistic.LinearMetre * 80; statistics.Add(shelfStatistic); } return statistics; diff --git a/RookieStation/Drawing/ExecuteCmd/CmdBatchExportDwg.cs b/RookieStation/Drawing/ExecuteCmds/CmdBatchExportDwg.cs similarity index 96% rename from RookieStation/Drawing/ExecuteCmd/CmdBatchExportDwg.cs rename to RookieStation/Drawing/ExecuteCmds/CmdBatchExportDwg.cs index 39e5153..6bc59b4 100644 --- a/RookieStation/Drawing/ExecuteCmd/CmdBatchExportDwg.cs +++ b/RookieStation/Drawing/ExecuteCmds/CmdBatchExportDwg.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation.Drawing.ExecuteCmd +namespace RookieStation.Drawing.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] diff --git a/RookieStation/Drawing/ExecuteCmd/CmdCreateViewPlanAnnotation.cs b/RookieStation/Drawing/ExecuteCmds/CmdCreateViewPlanAnnotation.cs similarity index 55% rename from RookieStation/Drawing/ExecuteCmd/CmdCreateViewPlanAnnotation.cs rename to RookieStation/Drawing/ExecuteCmds/CmdCreateViewPlanAnnotation.cs index be673a3..d7ec5ed 100644 --- a/RookieStation/Drawing/ExecuteCmd/CmdCreateViewPlanAnnotation.cs +++ b/RookieStation/Drawing/ExecuteCmds/CmdCreateViewPlanAnnotation.cs @@ -10,7 +10,7 @@ using System; using System.Text; using System.Windows.Media.Media3D; -namespace RookieStation.Drawing.ExecuteCmd +namespace RookieStation.Drawing.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -29,28 +29,22 @@ namespace RookieStation.Drawing.ExecuteCmd //var joinids = JoinGeometryUtils.GetJoinedElements(doc, wall);//接触关系过滤不出来,连接命令连接的才能过滤 //uidoc.Selection.SetElementIds(joinids); - //var insertids = wall.FindInserts(true, true, true, true);//嵌入的元素 - //SelectJoinedElements(wall); doc.InvokeGroup(tg => { - #region 墙尺寸标注 - doc.Invoke(ts => { - JointStructureCom(doc, BuiltInCategory.OST_StructuralColumns); - JointStructureCom(doc, BuiltInCategory.OST_StructuralFraming); + JoinWallsAndColumns(doc); + JointStructureCom(doc, BuiltInCategory.OST_Walls, BuiltInCategory.OST_StructuralFraming); JointStructureCom(doc, BuiltInCategory.OST_StructuralFraming, BuiltInCategory.OST_StructuralColumns); }, "连接墙柱梁"); CreateWallDimension(doc); - - #endregion 墙尺寸标注 - + CreateColumnsDimension(doc); + CreateBeamsDimension(doc); var visableCol = doc.QueryByView(v).ToElements(); - var doorRefers = new List(); - var furnRefers = new List(); + doc.Invoke(ts => { - CreateDoorTags(doc, visableCol); + CreateDoorWinTags(doc, visableCol); CreateLightAnnotations(doc, visableCol); CreateShelvesAnnotations(doc, visableCol); }, "创建标注"); @@ -75,6 +69,124 @@ namespace RookieStation.Drawing.ExecuteCmd return Result.Succeeded; } + public void CreateColumnsDimension(Document doc) + { + var col = new FilteredElementCollector(doc, doc.ActiveView.Id); + ElementCategoryFilter categoryFilter1 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns); + ElementCategoryFilter categoryFilter2 = new ElementCategoryFilter(BuiltInCategory.OST_Columns); + LogicalOrFilter andFilter = new LogicalOrFilter(categoryFilter1, categoryFilter2); + col.WherePasses(andFilter); + var columns = col.GroupBy(g => g.Name).Select(s => s.FirstOrDefault()); + doc.Invoke(ts => + { + foreach (FamilyInstance familyInstance in columns) + { + var loc = RsRevitUtils.GetLocationPointByElement(familyInstance); + var faces = RsRevitUtils.GetSideFacesByElement(familyInstance); + if (faces.Count == 0)//找不到实例的几何元素时,需从类型集合查找 + { + Options options = new Options(); + options.ComputeReferences = true; + faces = RsRevitUtils.GetFacesByFamilyInstance(familyInstance, options); + for (int i = faces.Count - 1; i >= 0; i--) + { + PlanarFace pf = faces[i] as PlanarFace; + if (pf.FaceNormal.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero)) + { + faces.Remove(faces[i]);//移除顶面底面 + } + } + } + var referenceArray = new ReferenceArray(); + var referenceArrayArray = new ReferenceArrayArray(); + GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray); + foreach (ReferenceArray array in referenceArrayArray) + { + var face = familyInstance.GetGeometryObjectFromReference(array.get_Item(0)) as PlanarFace; + var line = Line.CreateUnbound(loc, face.FaceNormal).CreateOffset(600 / 304.8, XYZ.BasisZ) as Line; + doc.Create.NewDimension(doc.ActiveView, line, array); + } + } + }, "创建柱子标注"); + } + + public void CreateBeamsDimension(Document doc) + { + var col = new FilteredElementCollector(doc, doc.ActiveView.Id); + ElementCategoryFilter categoryFilter1 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); + col.WherePasses(categoryFilter1); + var beams = col.GroupBy(g => g.Name).Select(s => s.FirstOrDefault()); + doc.Invoke(ts => + { + foreach (FamilyInstance familyInstance in beams) + { + var loc = RsRevitUtils.GetLocationPointByElement(familyInstance); + var faces = RsRevitUtils.GetSideFacesByElement(familyInstance); + if (faces.Count == 0)//找不到实例的几何元素时,需从类型集合查找 + { + Options options = new Options(); + options.ComputeReferences = true; + faces = RsRevitUtils.GetFacesByFamilyInstance(familyInstance, options); + for (int i = faces.Count - 1; i >= 0; i--) + { + PlanarFace pf = faces[i] as PlanarFace; + if (pf.FaceNormal.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero)) + { + faces.Remove(faces[i]);//移除顶面底面 + } + } + } + var referenceArray = new ReferenceArray(); + var referenceArrayArray = new ReferenceArrayArray(); + GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray); + foreach (ReferenceArray array in referenceArrayArray) + { + var face = familyInstance.GetGeometryObjectFromReference(array.get_Item(0)) as PlanarFace; + var line = Line.CreateUnbound(loc, face.FaceNormal).CreateOffset(600 / 304.8, XYZ.BasisZ) as Line; + doc.Create.NewDimension(doc.ActiveView, line, array); + } + } + }, "创建柱子标注"); + } + + /// + /// 递归找到所有面法向相等的面集合 + /// + /// + /// + /// + /// + public void GetParallFacesReferenceArray(List faces, Face firstFace, ReferenceArray referenceArray, ReferenceArrayArray referenceArrayArray) + { + if (referenceArrayArray.Size == 0) + { + referenceArrayArray.Append(referenceArray); + } + for (int i = 0; i < faces.Count; i++) + { + PlanarFace tempFace = faces[i] as PlanarFace; + var pf = firstFace as PlanarFace; + var facenormal = pf.FaceNormal; + //把初始的第一个添加进集合 + + if (tempFace.FaceNormal.CrossProduct(facenormal).IsAlmostEqualTo(XYZ.Zero)) + { + referenceArray.Append(tempFace.Reference); + faces.Remove(tempFace); + GetParallFacesReferenceArray(faces, tempFace, referenceArray, referenceArrayArray); + } + if (i == faces.Count() - 1) + { + referenceArray = new ReferenceArray(); + GetParallFacesReferenceArray(faces, faces.FirstOrDefault(), referenceArray, referenceArrayArray); + if (faces.Count() == 0) + { + referenceArrayArray.Append(referenceArray); + } + } + } + } + private static void CreateShelvesAnnotations(Document doc, IList visableCol) { var shelves = new List(); @@ -240,7 +352,7 @@ namespace RookieStation.Drawing.ExecuteCmd return true; } - private static bool CreateLightTags(Document doc, IList visableCol, out List lights) + private bool CreateLightTags(Document doc, IList visableCol, out List lights) { lights = new List(); foreach (var light in visableCol) @@ -261,7 +373,7 @@ namespace RookieStation.Drawing.ExecuteCmd return true; } - private static void CreateLightAnnotations(Document doc, IList visableCol) + private void CreateLightAnnotations(Document doc, IList visableCol) { List lights; CreateLightTags(doc, visableCol, out lights); @@ -269,7 +381,7 @@ namespace RookieStation.Drawing.ExecuteCmd CreateLightYDimensions(doc, lights); } - private static void CreateLightXDimensions(Document doc, List lights) + private void CreateLightXDimensions(Document doc, List lights) { var lightDistincts = lights .OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).X) @@ -310,7 +422,7 @@ namespace RookieStation.Drawing.ExecuteCmd } } - private static void CreateLightYDimensions(Document doc, List lights) + private void CreateLightYDimensions(Document doc, List lights) { var lightDistincts = lights .OrderBy(o => RsRevitUtils.GetLocationPointByElement(o).Y) @@ -353,53 +465,79 @@ namespace RookieStation.Drawing.ExecuteCmd } } - private static void CreateDoorTags(Document doc, IList visableCol) + private void CreateDoorWinTags(Document doc, IList visableCol) { - foreach (var door in visableCol) + foreach (Element ele in visableCol) { - var doorcategory = door.Category; - var loc = RsRevitUtils.GetLocationPointByElement(door); - var d = door as FamilyInstance; + var cate = ele.Category; + var loc = RsRevitUtils.GetLocationPointByElement(ele); + var d = ele as FamilyInstance; var rotateaxis = Line.CreateUnbound(new XYZ(), XYZ.BasisZ); - if (loc != null && doorcategory != null && doorcategory.Id.IntegerValue == -2000023) + if (loc != null && cate != null) { - IndependentTag independentTag = IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(door), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, loc); - //ElementTransformUtils.RotateElement(doc, independentTag.Id, rotateaxis, d.HandOrientation.AngleTo(XYZ.BasisY)); - double substract = d.HandOrientation.AngleTo(XYZ.BasisX) - Math.PI / 2; - if (substract > -0.001 && substract < 0.001) + if (cate.Id.IntegerValue == -2000023 || cate.Id.IntegerValue == -2000014) { - independentTag.TagOrientation = TagOrientation.Vertical; + IndependentTag independentTag = IndependentTag.Create(doc, doc.ActiveView.Id, new Reference(ele), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, loc); + //ElementTransformUtils.RotateElement(doc, independentTag.Id, rotateaxis, d.HandOrientation.AngleTo(XYZ.BasisY)); + double substract = d.HandOrientation.AngleTo(XYZ.BasisX) - Math.PI / 2; + if (substract > -0.001 && substract < 0.001) + { + independentTag.TagOrientation = TagOrientation.Vertical; + } } } } } - private void JointStructureCom(Document doc, BuiltInCategory builtInCategory) - { - var wallcollector = doc.QueryByBuiltInCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType(); - var Columncollector = doc.QueryByBuiltInCategory(builtInCategory).WhereElementIsNotElementType(); - foreach (Wall wall in wallcollector) - { - ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(wall, false); - Columncollector.WherePasses(intersectsElementFilter); - foreach (var column in Columncollector) - { - JoinGeometryUtils.JoinGeometry(doc, column, wall); - } - } - } - private void JointStructureCom(Document doc, BuiltInCategory builtInCategory1, BuiltInCategory builtInCategory2) { - var wallcollector = doc.QueryByBuiltInCategory(builtInCategory1).WhereElementIsNotElementType(); - var Columncollector = doc.QueryByBuiltInCategory(builtInCategory2).WhereElementIsNotElementType(); - foreach (FamilyInstance wall in wallcollector) + var collector1 = doc.QueryByBuiltInCategory(builtInCategory1).WhereElementIsNotElementType(); + var collector2 = doc.QueryByBuiltInCategory(builtInCategory2).WhereElementIsNotElementType(); + foreach (var fi1 in collector1) { - ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(wall, false); - Columncollector.WherePasses(intersectsElementFilter); - foreach (var column in Columncollector) + ElementIntersectsElementFilter intersectsElementFilter = new ElementIntersectsElementFilter(fi1, false); + collector2.WherePasses(intersectsElementFilter); + foreach (var fi2 in collector2) { - JoinGeometryUtils.JoinGeometry(doc, column, wall); + try + { + JoinGeometryUtils.JoinGeometry(doc, fi2, fi1); + } + catch (Exception) + { + continue; + } + } + } + } + + private void JoinWallsAndColumns(Document doc) + { + var wallcol = doc.QueryByView(doc.ActiveView); + foreach (var wall in wallcol) + { + var columncol = doc.QueryByView(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) + { + TaskDialog.Show("error", column.Id.ToString()); + } + } } } } @@ -422,12 +560,10 @@ namespace RookieStation.Drawing.ExecuteCmd }); } - private static IList SelectJoinedElements(Element selected_wall) + private static List GetWallConnectEles(Document doc, Wall wall) { - IList joinedElementIds = new List(); - - Wall w = selected_wall as Wall; - GeometryElement geometryElement = w.get_Geometry(new Options()); + GeometryElement geometryElement = wall.get_Geometry(new Options()); + List joinedElements = new List(); foreach (GeometryObject geometryObject in geometryElement) { if (geometryObject is Solid) @@ -435,109 +571,146 @@ namespace RookieStation.Drawing.ExecuteCmd Solid solid = geometryObject as Solid; foreach (Face face in solid.Faces) { - // for each face, find the other elements that generated the geometry of that face - ICollection generatingElementIds = w.GetGeneratingElementIds(face); + // 查找生成该几何面的元素ID + ICollection generatingElementIds = wall.GetGeneratingElementIds(face); - generatingElementIds.Remove(w.Id); // remove the originally selected wall, leaving only other elements joined to it + generatingElementIds.Remove(wall.Id); // 移除墙体本身 foreach (ElementId id in generatingElementIds) { - if (!(joinedElementIds.Contains(id))) - joinedElementIds.Add(id); // add each wall joined to this face to the overall collection + if (!joinedElements.Contains(id)) + joinedElements.Add(id); } } } } - return joinedElementIds; + var loc = wall.Location as LocationCurve; + Curve curve = loc.Curve; + FilteredElementCollector col = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType(); + IntersectionResultArray intersection = new IntersectionResultArray(); + //StringBuilder sb = new StringBuilder(); + foreach (Wall w in col) + { + if (w != null) + { + var lc = w.Location as LocationCurve; + var c = lc.Curve; + var result = curve.Intersect(c, out intersection); + if (result == SetComparisonResult.Overlap && !joinedElements.Contains(w.Id)) + { + joinedElements.Add(w.Id); + } + //sb.Append(w.Id.ToString() + result + "\r\n"); + } + } + + var ids = JoinGeometryUtils.GetJoinedElements(doc, wall); + foreach (var id in ids) + { + if (!joinedElements.Contains(id)) + { + joinedElements.Add(id); + } + } + + return joinedElements; + } + + /// + /// 获取与当前墙体连接和相交的墙体 + /// + /// + /// + /// + private static List FindWallIdsConnected(Document doc, Wall w) + { + List joinedElements = new List(); + var loc = w.Location as LocationCurve; + Curve curve = loc.Curve; + FilteredElementCollector eles = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType(); + IntersectionResultArray intersection = new IntersectionResultArray(); + StringBuilder sb = new StringBuilder(); + foreach (Wall ele in eles) + { + if (ele != null) + { + var lc = ele.Location as LocationCurve; + var c = lc.Curve; + var result = curve.Intersect(c, out intersection); + if (result == SetComparisonResult.Overlap) + { + joinedElements.Add(ele.Id); + } + sb.Append(ele.Id.ToString() + result + "\r\n"); + } + } + return joinedElements; } private static void CreateWallDimension(Document doc) { FilteredElementCollector wallCol = doc.QueryByView(doc.ActiveView as ViewPlan); - FilteredElementCollector instanceCol = doc.QueryByView(doc.ActiveView); var visableIdCol = doc.QueryByView(doc.ActiveView).ToElementIds(); doc.Invoke(ts => { foreach (Wall wall in wallCol) { - ReferenceArray wallThickReferenceArray = new ReferenceArray(); - ReferenceArray wallLengthRefernceArray = new ReferenceArray(); - //ReferenceArray ColumnLengthRefernceArray = new ReferenceArray(); - List faces = RsRevitUtils.GetSideFacesByElement(wall); if (wall.WallType.Kind != WallKind.Basic) { continue; } - //var insertids = wall.FindInserts(true, true, true, true); - //foreach (var item in insertids) - //{ - // var elem = doc.GetElement(item); - // var insertfaces = RsRevitUtils.GetSideFacesByElement(elem); - // if (insertfaces.Count != 0) - // { - // faces.AddRange(insertfaces); - // } - //} - var joinids = JoinGeometryUtils.GetJoinedElements(doc, wall); - foreach (var id in joinids) + var loc = wall.Location as LocationCurve; + ReferenceArray wallThickReferenceArray = new ReferenceArray(); + ReferenceArray wallLengthRefernceArray = new ReferenceArray(); + ReferenceArray ColumnLengthRefernceArray = new ReferenceArray(); + List faces = RsRevitUtils.GetSideFacesByElement(wall); + List ids = FindWallIdsConnected(doc, wall); + + foreach (var id in ids) { - bool b = visableIdCol.Contains(id); - if (!b) - { - continue; - } - - //if (elem.IsHidden(doc.ActiveView)) - //{ - // continue; - //} - var elem = doc.GetElement(id); - var joinFaces = RsRevitUtils.GetSideFacesByElement(elem); - - if (joinFaces.Count != 0) - { - faces.AddRange(joinFaces); - } + Element ele = doc.GetElement(id); + faces.AddRange(RsRevitUtils.GetSideFacesByElement(ele)); } + foreach (Face face in faces) { PlanarFace pf = face as PlanarFace; - if (pf == null) + if (pf == null || face.Reference == null || pf.OrientationMatchesSurfaceOrientation == false) { continue; } + if (pf.FaceNormal.CrossProduct(wall.Orientation).IsAlmostEqualTo(XYZ.Zero)) { - if (face.Reference == null) - { - continue; - } - if (doc.GetElement(face.Reference).GetType() == typeof(Wall)) + if (doc.GetElement(face.Reference).Id == wall.Id) { wallThickReferenceArray.Append(face.Reference); } - //if (doc.GetElement(face.Reference).Category.Id.IntegerValue == -2001330) - //{ - // ColumnLengthRefernceArray.Append(face.Reference); - //} + } + else if (pf.FaceNormal.DotProduct(wall.Orientation) < 0.001) + { + wallLengthRefernceArray.Append(face.Reference); } else { - wallLengthRefernceArray.Append(face.Reference); } } try { var scale = doc.ActiveView.Scale; - var tranform = Transform.CreateTranslation(wall.Orientation * scale * 5 / 304.8); + var tranform = Transform.CreateTranslation(wall.Orientation * scale * 15 / 304.8); var wallcurve = RsRevitUtils.GetLocationCurveByElement(wall) as Line; Line lengthLine = wallcurve.CreateTransformed(tranform) as Line; var lengthdim = doc.Create.NewDimension(doc.ActiveView, lengthLine, wallLengthRefernceArray); - - Line thickLine = Line.CreateUnbound(wallcurve.Evaluate(0.5, true), wall.Orientation); - //Line lengthLine = wallcurve.CreateOffset(500 / 304.8, -XYZ.BasisZ) as Line; - var thickdim = doc.Create.NewDimension(doc.ActiveView, thickLine, wallThickReferenceArray); doc.Regenerate(); + + ReferenceArray finallengthreferenceArray = RemoveZeroSegements(wall, wallLengthRefernceArray, lengthdim); + doc.Delete(lengthdim.Id); + 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); + if (lengthdim.Segments.Size > 2) { ReferenceArray referenceArray = new ReferenceArray(); @@ -545,7 +718,7 @@ namespace RookieStation.Drawing.ExecuteCmd var refer2 = lengthdim.References.get_Item(lengthdim.References.Size - 1); referenceArray.Append(refer1); referenceArray.Append(refer2); - var tranform1 = Transform.CreateTranslation(wall.Orientation * scale * 10 / 304.8); + var tranform1 = Transform.CreateTranslation(wall.Orientation * scale * 25 / 304.8); Line lengthLine1 = wallcurve.CreateTransformed(tranform1) as Line; doc.Create.NewDimension(doc.ActiveView, lengthLine1, referenceArray); @@ -559,54 +732,42 @@ namespace RookieStation.Drawing.ExecuteCmd }); } - public PlanarFace GetWallSideFace(Wall wall, ShellLayerType slt) + private static ReferenceArray RemoveZeroSegements(Wall wall, ReferenceArray wallLengthRefernceArray, Dimension lengthdim) { - Reference reference = HostObjectUtils.GetSideFaces(wall, slt)[0]; - PlanarFace face = wall.GetGeometryObjectFromReference(reference) as PlanarFace; - return face; - } - - public void CreateShelfDim(UIDocument uidoc) - { - Document doc = uidoc.Document; - IEnumerable instances = uidoc.Selection.PickObjects(ObjectType.Element, "请选择货架") - .Select(x => doc.GetElement(x)) - .Cast(); - ReferenceArray refArry = new ReferenceArray(); - List reffaces = new List(); - var ins = instances.FirstOrDefault(); - - var p = RsRevitUtils.GetLocationPointByElement(ins); - var v = ins.FacingOrientation; - Line line = Line.CreateUnbound(p, v); - //createoffest需要根据线的方向和参考方向进行叉乘 - var line1 = line.CreateOffset(1000 / 304.8, XYZ.BasisZ) as Line; - if (instances.Count() == 0) + List referencesdelete = new List(); + var finallengthreferenceArray = new ReferenceArray(); + for (int i = 0; i < lengthdim.NumberOfSegments; i++) { - return; - } - foreach (FamilyInstance instance in instances) - { - List allfaces = new List(); - - Options opt = new Options(); - opt.ComputeReferences = true; - - ICollection eleids = instance.GetSubComponentIds(); - - var referback = instance.GetReferences(FamilyInstanceReferenceType.Back); - var referfront = instance.GetReferences(FamilyInstanceReferenceType.Front); - //var geom = instance.GetGeometryObjectFromReference(referface.FirstOrDefault()); - refArry.Append(referback.First()); - refArry.Append(referfront.First()); - - using (Transaction trans = new Transaction(doc, "创建尺寸标注")) + if (lengthdim.Segments.get_Item(i).ValueString == "0") { - trans.Start(); - Dimension dim = doc.Create.NewDimension(doc.ActiveView, line1, refArry); - trans.Commit(); + 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; } } } \ No newline at end of file diff --git a/RookieStation/Drawing/ExecuteCmd/CmdCreateViewSectionAnnotation.cs b/RookieStation/Drawing/ExecuteCmds/CmdCreateViewSectionAnnotation.cs similarity index 98% rename from RookieStation/Drawing/ExecuteCmd/CmdCreateViewSectionAnnotation.cs rename to RookieStation/Drawing/ExecuteCmds/CmdCreateViewSectionAnnotation.cs index f17fb9e..05525d7 100644 --- a/RookieStation/Drawing/ExecuteCmd/CmdCreateViewSectionAnnotation.cs +++ b/RookieStation/Drawing/ExecuteCmds/CmdCreateViewSectionAnnotation.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Media.Media3D; -namespace RookieStation.Drawing.ExecuteCmd +namespace RookieStation.Drawing.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] diff --git a/RookieStation/Drawing/Model/ShelfStatistic.cs b/RookieStation/Drawing/Models/ShelfStatistic.cs similarity index 91% rename from RookieStation/Drawing/Model/ShelfStatistic.cs rename to RookieStation/Drawing/Models/ShelfStatistic.cs index aa2ccf7..ff89bf4 100644 --- a/RookieStation/Drawing/Model/ShelfStatistic.cs +++ b/RookieStation/Drawing/Models/ShelfStatistic.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation.Drawing.Model +namespace RookieStation.Drawing.Models { internal class ShelfStatistic { diff --git a/RookieStation/Drawing/View/WpfLegendCreator.xaml b/RookieStation/Drawing/Views/WpfLegendCreator.xaml similarity index 81% rename from RookieStation/Drawing/View/WpfLegendCreator.xaml rename to RookieStation/Drawing/Views/WpfLegendCreator.xaml index 7c11f78..f6f212c 100644 --- a/RookieStation/Drawing/View/WpfLegendCreator.xaml +++ b/RookieStation/Drawing/Views/WpfLegendCreator.xaml @@ -1,9 +1,9 @@  /// WpfLegendCreator.xaml 的交互逻辑 diff --git a/RookieStation/Finishes/ExecuteCmd/CmdFloorFinishes.cs b/RookieStation/Finishes/ExecuteCmds/CmdFloorFinishes.cs similarity index 95% rename from RookieStation/Finishes/ExecuteCmd/CmdFloorFinishes.cs rename to RookieStation/Finishes/ExecuteCmds/CmdFloorFinishes.cs index 6e80ddf..ca2682a 100644 --- a/RookieStation/Finishes/ExecuteCmd/CmdFloorFinishes.cs +++ b/RookieStation/Finishes/ExecuteCmds/CmdFloorFinishes.cs @@ -9,9 +9,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Windows; -using RookieStation.Finishes.View; +using RookieStation.Finishes.Views; -namespace RookieStation.Finishes.ExecuteCmd +namespace RookieStation.Finishes.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -23,7 +23,6 @@ namespace RookieStation.Finishes.ExecuteCmd UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; - Family family = null; FamilySymbol symbol; var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms); if (rooms.Count() == 0) @@ -208,21 +207,26 @@ namespace RookieStation.Finishes.ExecuteCmd { //删除模型线 doc.Delete(modelCurveIds); - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "FloorFinish\\地砖.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); - foreach (var p in pts) + string file = UserConstant.FamilyLibraryDirectory + "FloorFinish\\地砖.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try { - var fi = doc.Create - .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(fi); + foreach (var p in pts) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + foreach (var p in lastpoints) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } } - foreach (var p in lastpoints) + catch (Exception ex) { - var fi = doc.Create - .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(fi); + Log.WriteLog(ex.Message); } }, "地面铺装"); diff --git a/RookieStation/Finishes/ExecuteCmd/CmdPlaceFloorFinishes.cs b/RookieStation/Finishes/ExecuteCmds/CmdPlaceFloorFinishes.cs similarity index 99% rename from RookieStation/Finishes/ExecuteCmd/CmdPlaceFloorFinishes.cs rename to RookieStation/Finishes/ExecuteCmds/CmdPlaceFloorFinishes.cs index 65c7ef3..1376d71 100644 --- a/RookieStation/Finishes/ExecuteCmd/CmdPlaceFloorFinishes.cs +++ b/RookieStation/Finishes/ExecuteCmds/CmdPlaceFloorFinishes.cs @@ -3,13 +3,13 @@ using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using RookieStation.Extension; -using RookieStation.Finishes.View; +using RookieStation.Finishes.Views; using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; -namespace RookieStation.Finishes.ExecuteCmd +namespace RookieStation.Finishes.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] diff --git a/RookieStation/Finishes/ExecuteCmd/CmdPlaceWallFinishes.cs b/RookieStation/Finishes/ExecuteCmds/CmdPlaceWallFinishes.cs similarity index 99% rename from RookieStation/Finishes/ExecuteCmd/CmdPlaceWallFinishes.cs rename to RookieStation/Finishes/ExecuteCmds/CmdPlaceWallFinishes.cs index b55d811..f33032a 100644 --- a/RookieStation/Finishes/ExecuteCmd/CmdPlaceWallFinishes.cs +++ b/RookieStation/Finishes/ExecuteCmds/CmdPlaceWallFinishes.cs @@ -3,14 +3,14 @@ using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using RookieStation.Extension; -using RookieStation.Finishes.View; +using RookieStation.Finishes.Views; using RookieStation.RibbonMenu; using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; -namespace RookieStation.Finishes.ExecuteCmd +namespace RookieStation.Finishes.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] diff --git a/RookieStation/Finishes/View/WpfFloorFinishes.xaml b/RookieStation/Finishes/Views/WpfFloorFinishes.xaml similarity index 98% rename from RookieStation/Finishes/View/WpfFloorFinishes.xaml rename to RookieStation/Finishes/Views/WpfFloorFinishes.xaml index 7f105dc..cf2f760 100644 --- a/RookieStation/Finishes/View/WpfFloorFinishes.xaml +++ b/RookieStation/Finishes/Views/WpfFloorFinishes.xaml @@ -1,5 +1,5 @@  /// WpfFloorFinishes.xaml 的交互逻辑 diff --git a/RookieStation/Finishes/View/WpfWallFinishes.xaml b/RookieStation/Finishes/Views/WpfWallFinishes.xaml similarity index 98% rename from RookieStation/Finishes/View/WpfWallFinishes.xaml rename to RookieStation/Finishes/Views/WpfWallFinishes.xaml index 86ec01b..79acda5 100644 --- a/RookieStation/Finishes/View/WpfWallFinishes.xaml +++ b/RookieStation/Finishes/Views/WpfWallFinishes.xaml @@ -1,5 +1,5 @@  /// WpfWallFinishes.xaml 的交互逻辑 diff --git a/RookieStation/MailingAreaModule/ExecuteCmd/CmdLogoExtrusion.cs b/RookieStation/MailingAreaModule/ExecuteCmds/CmdLogoExtrusion.cs similarity index 91% rename from RookieStation/MailingAreaModule/ExecuteCmd/CmdLogoExtrusion.cs rename to RookieStation/MailingAreaModule/ExecuteCmds/CmdLogoExtrusion.cs index b4e8dbb..7335b6e 100644 --- a/RookieStation/MailingAreaModule/ExecuteCmd/CmdLogoExtrusion.cs +++ b/RookieStation/MailingAreaModule/ExecuteCmds/CmdLogoExtrusion.cs @@ -7,7 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace RookieStation.MailingAreaModule.ExecuteCmd +namespace RookieStation.MailingAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -160,29 +160,30 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd /// 所有线串的集合 private void SearchCurveConnected(List curves, Curve initcurve, CurveArray initCurveArray, CurveArrArray curveArrArray) { + if (curveArrArray.Size == 0) + { + curveArrArray.Append(initCurveArray); + } for (int i = 0; i < curves.Count; i++) { Curve tempCurve = curves[i]; var baseEndXyz = initcurve.GetEndPoint(0); //把初始的第一个添加进集合 - if (curveArrArray.Size == 0) - { - curveArrArray.Append(initCurveArray); - } - if (tempCurve.GetEndPoint(0).IsAlmostEqualTo(baseEndXyz) || tempCurve.GetEndPoint(1).IsAlmostEqualTo(baseEndXyz)) + + if (tempCurve.GetEndPoint(0).IsAlmostEqualTo(baseEndXyz) || tempCurve.GetEndPoint(1).IsAlmostEqualTo(baseEndXyz))//可以为重合的线,做剔除 { initCurveArray.Append(tempCurve); curves.Remove(tempCurve); - SearchCurveConnected(curves, tempCurve, initCurveArray, curveArrArray); + //将tempcurve作为起点继续查找 + SearchCurveConnected(curves, tempCurve, initCurveArray, curveArrArray);//最后一次执行方法也在此处 } - //遍历完一个线串时 + + //遍历完一个线串时,寻找下一个线串,即查找到最后,都找不到相连的曲线时 if (i == curves.Count() - 1) { - //curveArrArray.Append(initCurveArray); - //array.Clear(); - initCurveArray = new CurveArray(); - SearchCurveConnected(curves, curves.FirstOrDefault(), initCurveArray, curveArrArray); - ////由于最后一轮运行完递归后,所有线段均成串,只执行上面的if内容,所以没办法将剩余线加到集合中。 + initCurveArray = new CurveArray();//下一个线串需重新建立合集 + SearchCurveConnected(curves, curves.FirstOrDefault(), initCurveArray, curveArrArray);//每有一次新的线串时执行一次,查找与其相连的线 + ////由于最后一轮运行完递归后,所有线段均成组,只执行上面的if内容,所以没办法将剩余线加到集合中。 if (curves.Count() == 0) { curveArrArray.Append(initCurveArray); diff --git a/RookieStation/MailingAreaModule/ExecuteCmd/CmdPlaceReceptionArea.cs b/RookieStation/MailingAreaModule/ExecuteCmds/CmdPlaceReceptionArea.cs similarity index 76% rename from RookieStation/MailingAreaModule/ExecuteCmd/CmdPlaceReceptionArea.cs rename to RookieStation/MailingAreaModule/ExecuteCmds/CmdPlaceReceptionArea.cs index e7bde3f..b4532ff 100644 --- a/RookieStation/MailingAreaModule/ExecuteCmd/CmdPlaceReceptionArea.cs +++ b/RookieStation/MailingAreaModule/ExecuteCmds/CmdPlaceReceptionArea.cs @@ -8,9 +8,12 @@ using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; -using RookieStation.MailingAreaModule.View; +using RookieStation.MailingAreaModule.Views; +using System.Windows.Media.Media3D; +using System.Windows.Documents; +using System.IO; -namespace RookieStation.MailingAreaModule.ExecuteCmd +namespace RookieStation.MailingAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -89,7 +92,6 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd { return Result.Failed; } - Family family = null; FamilySymbol symbol; return doc.InvokeGroup(tg => { @@ -110,13 +112,13 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { + uiapp.Application.DocumentChanged -= Application_DocumentChanged; var interval = gap + aluminumPlasticPanelLength; if (eleIdsAdded.Count == 0) { return Result.Cancelled; } Line referline = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); - uiapp.Application.DocumentChanged -= Application_DocumentChanged; double backgroundWallLength = referline.Length; if (backgroundWallLength < 1500 / 304.8) @@ -199,16 +201,20 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd FamilyInstance signage = null; doc.Invoke(ts => { - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Sign\\菜鸟使命.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); + string file = UserConstant.FamilyLibraryDirectory + "Sign\\菜鸟使命.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); var endPoint = referline.GetEndPoint(0); endPoint += (skirtingLineHeight + aluminumPlasticPanelHeight) * XYZ.BasisZ; - signage = doc.Create.NewFamilyInstance(endPoint, symbol, StructuralType.NonStructural); - //标准面要朝上,族要面向背侧 + try + { + signage = doc.Create.NewFamilyInstance(endPoint, symbol, StructuralType.NonStructural); + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); + } }, "菜鸟的使命"); doc.Invoke(ts => { @@ -223,52 +229,54 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd FamilyInstance reception = null; doc.Invoke(ts => { - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Furniture\\寄件接待台.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); - var wallCenterPoint = referline.Evaluate(0.5, true); + string file = UserConstant.FamilyLibraryDirectory + "Furniture\\寄件接待台.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try + { + var wallCenterPoint = referline.Evaluate(0.5, true); - reception = doc.Create.NewFamilyInstance(wallCenterPoint, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + reception = doc.Create.NewFamilyInstance(wallCenterPoint, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - symbol.GetParameters("台面长度").FirstOrDefault().Set(receptionLength); - //symbol.GetParameters("台面长度").FirstOrDefault().AsDouble(); + symbol.GetParameters("台面长度").FirstOrDefault().Set(receptionLength); + doc.Regenerate(); + RsRevitUtils.AdjustInstance(doc, reception, referline, receptionWallDistance); + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); + } }, "接待台布置"); - doc.Invoke(ts => - { - RsRevitUtils.AdjustInstance(doc, reception, referline, receptionWallDistance); - }, "调整接待台"); FamilyInstance logo = null; doc.Invoke(ts => { - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Sign\\菜鸟LOGO.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(id => doc.GetElement(id).Name == glowTextSymbol); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); - var wallCenterPoint = referline.Evaluate(0.5, true); + var file = UserConstant.FamilyLibraryDirectory + "Sign\\菜鸟LOGO.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try + { + var wallCenterPoint = referline.Evaluate(0.5, true); - logo = doc.Create.NewFamilyInstance(wallCenterPoint, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - - //symbol.GetParameters("背景墙长度").FirstOrDefault().Set(reception_length); - //width = symbol.GetParameters("台面宽度").FirstOrDefault().AsDouble(); + logo = doc.Create.NewFamilyInstance(wallCenterPoint, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + doc.Regenerate(); + RsRevitUtils.AdjustInstance(doc, logo, referline, aluminumPlasticPanelThickness + baseLayerThickness); + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); + } }, "菜鸟LOG布置"); - doc.Invoke(ts => - { - RsRevitUtils.AdjustInstance(doc, logo, referline, aluminumPlasticPanelThickness + baseLayerThickness); - }, "调整lOGO"); doc.Invoke(ts => { - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Lamp\\吊灯.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); + string file = UserConstant.FamilyLibraryDirectory + "Lamp\\吊灯.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); var referlineDirection = referline.Direction; List lampLocationPoints = new List(); var lampsLocationLine = referline.CreateOffset(lampsWallDistance, -XYZ.BasisZ); - var centerPoint = lampsLocationLine.Evaluate(0.5, true); - n = (int)Math.Floor(backgroundWallLength / lampsInterval); + var centerPoint = lampsLocationLine.Evaluate(0.5, true) + XYZ.BasisZ * lampsHeight; + + //n = (int)Math.Floor(backgroundWallLength / lampsInterval); + n = (int)Math.Floor(receptionLength / lampsInterval); //单侧的数量 int m = (int)Math.Floor((n + 1.0) / 2); if ((n + 1) % 2 == 0) @@ -276,15 +284,22 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd //开始间隔为0.5 for (int i = 0; i < m; i++) { - XYZ p = centerPoint.Add(referlineDirection * (i + 0.5) * lampsInterval) + XYZ.BasisZ * lampsHeight; - XYZ reversePoint = centerPoint.Add(-referlineDirection * (i + 0.5) * lampsInterval) + XYZ.BasisZ * lampsHeight; + XYZ p = centerPoint.Add(referlineDirection * (i + 0.5) * lampsInterval); + XYZ reversePoint = centerPoint.Add(-referlineDirection * (i + 0.5) * lampsInterval); lampLocationPoints.Add(p); lampLocationPoints.Add(reversePoint); } - foreach (XYZ p in lampLocationPoints) + try { - doc.Create.NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + foreach (XYZ p in lampLocationPoints) + { + var light = doc.Create.NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + } + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); } } else @@ -298,9 +313,16 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd lampLocationPoints.Add(p); lampLocationPoints.Add(reversePoint); } - foreach (XYZ p in lampLocationPoints) + try { - doc.Create.NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + foreach (XYZ p in lampLocationPoints) + { + var light = doc.Create.NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + } + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); } } }, "吊灯布置"); @@ -349,21 +371,5 @@ namespace RookieStation.MailingAreaModule.ExecuteCmd } return face; } - - private Reference GetWallSideFaceReference(Wall wall, XYZ normal) - { - var interFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).FirstOrDefault(); - var exterFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior).FirstOrDefault(); - - PlanarFace pf = wall.GetGeometryObjectFromReference(interFaceReference) as PlanarFace; - if (pf.FaceNormal.IsAlmostEqualTo(normal)) - { - return interFaceReference; - } - else - { - return exterFaceReference; - } - } } } \ No newline at end of file diff --git a/RookieStation/MailingAreaModule/View/WpfReceptionArea.xaml b/RookieStation/MailingAreaModule/Views/WpfReceptionArea.xaml similarity index 98% rename from RookieStation/MailingAreaModule/View/WpfReceptionArea.xaml rename to RookieStation/MailingAreaModule/Views/WpfReceptionArea.xaml index 4cbd94d..b7d634c 100644 --- a/RookieStation/MailingAreaModule/View/WpfReceptionArea.xaml +++ b/RookieStation/MailingAreaModule/Views/WpfReceptionArea.xaml @@ -1,5 +1,5 @@  /// WpfReceptionArea.xaml 的交互逻辑 diff --git a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceExitGate.cs b/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceExitGate.cs deleted file mode 100644 index f7a079d..0000000 --- a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceExitGate.cs +++ /dev/null @@ -1,239 +0,0 @@ -using Autodesk.Revit.DB; -using Autodesk.Revit.DB.Events; -using Autodesk.Revit.UI; -using RookieStation.ProjectConfig; -using RookieStation.Extension; -using RookieStation.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using RookieStation.ParcelAreaModule.View; - -namespace RookieStation.ParcelAreaModule.ExecuteCmd -{ - [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] - [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] - internal class CmdPlaceExitGate : IExternalCommand - { - /// - /// 是否起始为通道 - /// - internal bool isPassageStart; - - /// - /// 选择一次后停止 - /// - private static bool PlaceSingleInstanceAbort = true; - - /// - /// revit窗口句柄 - /// - private IntPtr revitWindow; - - /// - /// 添加的元素 - /// - private List eleIdsAdded = new List(); - - public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) - { - UIApplication uiapp = commandData.Application; - UIDocument uidoc = uiapp.ActiveUIDocument; - Document doc = uidoc.Document; - revitWindow = uiapp.MainWindowHandle; - - WpfExitGate gateLayout = CommonUtils.GenerateWindow(); - - if (gateLayout.DialogResult == true) - { - isPassageStart = gateLayout.IsStartPassage; - } - else - { - return Result.Cancelled; - } - double interval = (2 * (1030 + gateLayout.PassageWidth) + 100) / 304.8; - double gateFrontOffest = 1630 / 304.8; - List instances = new List(); - - using (TransactionGroup tg = new TransactionGroup(doc, "布置出口收检台")) - { - tg.Start(); - try - { - FamilySymbol guideSymbol = RsRevitUtils.GetGuideSymbol(doc); ; - if (guideSymbol == null) - { - TaskDialog.Show("错误", "定位族丢失"); - return Result.Failed; - } - eleIdsAdded.Clear(); - uiapp.Application.DocumentChanged += Application_DocumentChanged; - uidoc.PromptForFamilyInstancePlacement(guideSymbol); - uiapp.Application.DocumentChanged -= Application_DocumentChanged; - } - catch (Autodesk.Revit.Exceptions.OperationCanceledException) - { - if (eleIdsAdded.Count == 0) - { - return Result.Cancelled; - } - //直线向量 - Line referline = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); - uiapp.Application.DocumentChanged -= Application_DocumentChanged; - - int orders = UserConstant.Orders; - int n = GetGateCountByOrders(orders); - if (orders.Equals(0) || n == 0) - { - //message = "单量有误"; - TaskDialog.Show("温馨提示", "单量有误"); - return Result.Failed; - } - - int m = isPassageStart - ? (int)Math.Floor((referline.Length * 304.8 / 1630) + 0.5) - : (int)Math.Floor(((referline.Length * 304.8) - 200) / 1630 + 0.5); - if (m < n) - { - n = m; - } - List locationPoint = new List(); - doc.Invoke(ts => - { - Family gateFamily = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Gate\\L型收检台.rfa"); - IEnumerable leftSymbolId = from id in gateFamily.GetFamilySymbolIds() - where doc.GetElement(id).Name == "左" - select id; - IEnumerable rightSymbolId = from id in gateFamily.GetFamilySymbolIds() - where doc.GetElement(id).Name == "右" - select id; - FamilySymbol rightSymbol = doc.GetElement(rightSymbolId.FirstOrDefault()) as FamilySymbol; - //ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - FamilySymbol leftSymbol = doc.GetElement(leftSymbolId.FirstOrDefault()) as FamilySymbol; - Level level = uidoc.ActiveView.GenLevel; - if (level == null) - { - return; - } - if (isPassageStart)//起始是通道 - { - for (int i = 0; i < n; i++) - { - XYZ p = referline.Evaluate(i * interval, false); - locationPoint.Add(p); - } - - foreach (XYZ point in locationPoint) - { - leftSymbol.Activate(); - FamilyInstance leftInstance = doc.Create.NewFamilyInstance(point, leftSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(leftInstance); - if (instances.Count() == n + 1) - { - break; - } - rightSymbol.Activate(); - FamilyInstance rightInstance = doc.Create.NewFamilyInstance(point, rightSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(rightInstance); - if (instances.Count() == n + 1) - { - break; - } - - //offest = symbol.GetParameters("深度").FirstOrDefault().AsDouble() / 2; - } - - doc.Delete(instances.First().Id); - instances.RemoveAt(0); - } - else//起始是收检台 - { - for (int i = 0; i < n; i++) - { - XYZ p = referline.Evaluate((i * interval) + 1830 / 304.8, false); - - locationPoint.Add(p); - } - foreach (var pt in locationPoint) - { - leftSymbol.Activate(); - var leftInstance = doc.Create.NewFamilyInstance(pt, leftSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - - //offest = symbol.GetParameters("深度").FirstOrDefault().AsDouble() / 2; - instances.Add(leftInstance); - if (instances.Count() == n) - { - break; - } - - rightSymbol.Activate(); - var rightInstance = doc.Create.NewFamilyInstance(pt, rightSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(rightInstance); - if (instances.Count() == n) - { - break; - } - } - } - }, "加载并创建收检台"); - doc.Invoke(ts => - { - RsRevitUtils.AdjustInstances(doc, instances, referline, gateFrontOffest); - }, "调整收检台位置"); - //if (tg.GetStatus() == TransactionStatus.Started) - //{ - // tg.RollBack(); - //} - //return Result.Cancelled; - } - tg.Assimilate(); - } - return Result.Succeeded; - } - - private int GetGateCountByOrders(int orders) - { - int n; - if (0 < orders && orders <= 2000) - { - n = 2; - } - else if (2000 < orders && orders <= 4000) - { - n = 3; - } - else if (4000 < orders && orders <= 6000) - { - n = 4; - } - else if (6000 < orders && orders <= 8000) - { - n = 5; - } - else if (8000 < orders) - { - n = 6; - } - else - { - n = 0; - } - - return n; - } - - private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e) - { - ICollection idsAdded = e.GetAddedElementIds(); - int n = idsAdded.Count; - eleIdsAdded.AddRange(idsAdded); - if (PlaceSingleInstanceAbort && n == 1) - { - KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); - KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); - //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); - } - } - } -} \ No newline at end of file diff --git a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdArrangeShelfCards.cs b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdArrangeShelfCards.cs similarity index 96% rename from RookieStation/ParcelAreaModule/ExecuteCmd/CmdArrangeShelfCards.cs rename to RookieStation/ParcelAreaModule/ExecuteCmds/CmdArrangeShelfCards.cs index 8477a7c..b0ab12e 100644 --- a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdArrangeShelfCards.cs +++ b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdArrangeShelfCards.cs @@ -1,7 +1,7 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; -using RookieStation.ParcelAreaModule.View; +using RookieStation.ParcelAreaModule.Views; using RookieStation.RibbonMenu; using RookieStation.Utils; using System; @@ -11,7 +11,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; -namespace RookieStation.ParcelAreaModule.ExecuteCmd +namespace RookieStation.ParcelAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] diff --git a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceEntranceGate.cs b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceEntranceGate.cs similarity index 98% rename from RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceEntranceGate.cs rename to RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceEntranceGate.cs index 3f236b0..53d4d06 100644 --- a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceEntranceGate.cs +++ b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceEntranceGate.cs @@ -6,9 +6,9 @@ using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; -using RookieStation.ParcelAreaModule.View; +using RookieStation.ParcelAreaModule.Views; -namespace RookieStation.ParcelAreaModule.ExecuteCmd +namespace RookieStation.ParcelAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -58,12 +58,12 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { + uiapp.Application.DocumentChanged -= Application_DocumentChanged; if (eleIdsAdded.Count == 0) { return Result.Cancelled; } Line line = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); - uiapp.Application.DocumentChanged -= Application_DocumentChanged; double interval = (330 + entranceGateLayout.PassageWidth) / 304.8; double offest = 0.0; diff --git a/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceExitGate.cs b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceExitGate.cs new file mode 100644 index 0000000..eb1c0e8 --- /dev/null +++ b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceExitGate.cs @@ -0,0 +1,234 @@ +using Autodesk.Revit.DB; +using Autodesk.Revit.DB.Events; +using Autodesk.Revit.UI; +using RookieStation.ProjectConfig; +using RookieStation.Extension; +using RookieStation.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using RookieStation.ParcelAreaModule.Views; + +namespace RookieStation.ParcelAreaModule.ExecuteCmds +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + internal class CmdPlaceExitGate : IExternalCommand + { + /// + /// 是否起始为通道 + /// + internal bool isPassageStart; + + internal double PassageWidth; + + /// + /// 选择一次后停止 + /// + private static bool PlaceSingleInstanceAbort = true; + + /// + /// revit窗口句柄 + /// + private IntPtr revitWindow; + + /// + /// 添加的元素 + /// + private List eleIdsAdded = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + revitWindow = uiapp.MainWindowHandle; + + WpfExitGate gateLayout = CommonUtils.GenerateWindow(); + + if (gateLayout.DialogResult == true) + { + isPassageStart = gateLayout.IsStartPassage; + PassageWidth = gateLayout.PassageWidth; + } + else + { + return Result.Cancelled; + } + double interval = (1030 + PassageWidth + 50); + List instances = new List(); + + return doc.InvokeGroup(tg => + { + try + { + FamilySymbol guideSymbol = RsRevitUtils.GetGuideSymbol(doc); ; + if (guideSymbol == null) + { + TaskDialog.Show("错误", "定位族丢失"); + return Result.Failed; + } + eleIdsAdded.Clear(); + uiapp.Application.DocumentChanged += Application_DocumentChanged; + uidoc.PromptForFamilyInstancePlacement(guideSymbol); + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + uiapp.Application.DocumentChanged -= Application_DocumentChanged; + if (eleIdsAdded.Count == 0) + { + return Result.Cancelled; + } + //直线向量 + Line referline = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); + + int orders = UserConstant.Orders; + int n = GetGateCountByOrders(orders);//根据单量得到收检台数量 + if (orders.Equals(0) || n == 0) + { + //message = "单量有误"; + TaskDialog.Show("温馨提示", "单量有误"); + return Result.Failed; + } + + int m = (int)Math.Floor((referline.Length * 304.8 / (PassageWidth + 1030 + 50)) + 0.5); + + if (m < n)//如果实际场地设置的数量无法满足单量要求,按实际场地设置 + { + n = m; + } + List locationPoint = new List(); + doc.Invoke(ts => + { + Family gateFamily = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Gate\\收检台-左.rfa"); + IEnumerable leftSymbolId = from id in gateFamily.GetFamilySymbolIds() + where doc.GetElement(id).Name.Contains("左") + select id; + gateFamily = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Gate\\收检台-右.rfa"); + IEnumerable rightSymbolId = from id in gateFamily.GetFamilySymbolIds() + where doc.GetElement(id).Name.Contains("右") + select id; + FamilySymbol rightSymbol = doc.GetElement(rightSymbolId.FirstOrDefault()) as FamilySymbol; + FamilySymbol leftSymbol = doc.GetElement(leftSymbolId.FirstOrDefault()) as FamilySymbol; + Level level = uidoc.ActiveView.GenLevel; + if (level == null) + { + return; + } + if (isPassageStart)//起始是通道 + { + for (int i = 0; i < n; i++) + { + double parameter = (interval * (i + 0.5 * (1 - Math.Pow(-1, i))) + Math.Pow(-1, i) * PassageWidth) / 304.8; + XYZ p = referline.Evaluate(parameter, false); + locationPoint.Add(p); + } + for (int i = 0; i < locationPoint.Count; i++) + { + var point = locationPoint[i]; + if (i % 2 == 0) + { + rightSymbol.Activate(); + FamilyInstance rightInstance = doc.Create.NewFamilyInstance(point, rightSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(rightInstance); + } + else + { + leftSymbol.Activate(); + FamilyInstance leftInstance = doc.Create.NewFamilyInstance(point, leftSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(leftInstance); + } + } + + //doc.Delete(instances.First().Id); + //instances.RemoveAt(0); + } + else//起始是收检台 + { + for (int i = 0; i < n; i++) + { + double parameter = (interval * (i + 0.5 * (1 + Math.Pow(-1, i))) - 50 - Math.Pow(-1, i) * PassageWidth) / 304.8; + XYZ p = referline.Evaluate(parameter, false); + locationPoint.Add(p); + } + for (int i = 0; i < locationPoint.Count; i++) + { + var point = locationPoint[i]; + if (i % 2 == 0) + { + leftSymbol.Activate(); + FamilyInstance leftInstance = doc.Create.NewFamilyInstance(point, leftSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(leftInstance); + } + else + { + rightSymbol.Activate(); + FamilyInstance rightInstance = doc.Create.NewFamilyInstance(point, rightSymbol, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(rightInstance); + } + } + } + }, "加载并创建收检台"); + + doc.Invoke(ts => + { + RsRevitUtils.AdjustInstances(doc, instances, referline, 0); + }, "调整收检台位置"); + + //if (tg.GetStatus() == TransactionStatus.Started) + //{ + // tg.RollBack(); + //} + //return Result.Cancelled; + } + + return Result.Succeeded; + }, "布置收检台"); + } + + private int GetGateCountByOrders(int orders) + { + int n; + if (0 < orders && orders <= 2000) + { + n = 2; + } + else if (2000 < orders && orders <= 4000) + { + n = 3; + } + else if (4000 < orders && orders <= 6000) + { + n = 4; + } + else if (6000 < orders && orders <= 8000) + { + n = 5; + } + else if (8000 < orders) + { + n = 6; + } + else + { + n = 0; + } + + return n; + } + + private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e) + { + ICollection idsAdded = e.GetAddedElementIds(); + int n = idsAdded.Count; + eleIdsAdded.AddRange(idsAdded); + if (PlaceSingleInstanceAbort && n == 1) + { + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + KeyPress.PostMessage(revitWindow, (uint)KeyPress.KEYBOARD_MSG.WM_KEYDOWN, (uint)System.Windows.Forms.Keys.Escape, 0); + //KeyPress.OneKey(revitWindow, (char)System.Windows.Forms.Keys.Escape); + } + } + } +} \ No newline at end of file diff --git a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceLamps.cs b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceLamps.cs similarity index 90% rename from RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceLamps.cs rename to RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceLamps.cs index 3c5c6d0..9ac05dd 100644 --- a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceLamps.cs +++ b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceLamps.cs @@ -8,9 +8,9 @@ using RookieStation.Utils; using System; using System.Collections.Generic; using System.Linq; -using RookieStation.ParcelAreaModule.View; +using RookieStation.ParcelAreaModule.Views; -namespace RookieStation.ParcelAreaModule.ExecuteCmd +namespace RookieStation.ParcelAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -23,7 +23,6 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; DocumentSet docset = uiapp.Application.Documents; - Family family = null; FamilySymbol symbol; double leftRightDistance = 0.0; double frontDistance = 0.0; @@ -191,21 +190,26 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd { //删除模型线 doc.Delete(modelCurveIds); - family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Lamp\\筒灯.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - symbol = doc.GetElement(symbolId) as FamilySymbol; - symbol.Activate(); - foreach (var p in pts) + string file = UserConstant.FamilyLibraryDirectory + "Lamp\\筒灯.rfa"; + symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try { - var fi = doc.Create - .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(fi); + foreach (var p in pts) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } + foreach (var p in lastps) + { + var fi = doc.Create + .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instances.Add(fi); + } } - foreach (var p in lastps) + catch (Exception ex) { - var fi = doc.Create - .NewFamilyInstance(p, symbol, baseLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instances.Add(fi); + Log.WriteLog(ex.Message); } }, "载入布置灯具"); doc.Invoke(ts => diff --git a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceShelves.cs b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceShelves.cs similarity index 93% rename from RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceShelves.cs rename to RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceShelves.cs index 2395d21..d4eb677 100644 --- a/RookieStation/ParcelAreaModule/ExecuteCmd/CmdPlaceShelves.cs +++ b/RookieStation/ParcelAreaModule/ExecuteCmds/CmdPlaceShelves.cs @@ -7,12 +7,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using RookieStation.ParcelAreaModule.Model; -using RookieStation.ParcelAreaModule.View; +using RookieStation.ParcelAreaModule.Models; +using RookieStation.ParcelAreaModule.Views; using Autodesk.Revit.DB.Electrical; using Autodesk.Revit.Creation; +using System.IO; +using RookieStation.ParcelAreaModule.ViewModels; -namespace RookieStation.ParcelAreaModule.ExecuteCmd +namespace RookieStation.ParcelAreaModule.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -75,12 +77,12 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { + uiapp.Application.DocumentChanged -= Application_DocumentChanged; if (eleIdsAdded.Count == 0) { return Result.Failed; } Line referline = RsRevitUtils.GetGuideGeometryAndDeleteGuide(doc, eleIdsAdded); - uiapp.Application.DocumentChanged -= Application_DocumentChanged; Family shelfFamily = null; FamilySymbol shelfSymbol = null; @@ -250,7 +252,9 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd } if (vm.IsPlaceLight == true) { - CreateLights(doc, vm, referline, shelfSpacing, passageWidth, parallelReferlineOffest); + var locs = new List(); + CreateLights(doc, vm, referline, shelfSpacing, passageWidth, parallelReferlineOffest, out locs); + CreateMessengerWire(doc, vm, locs); } } return Result.Succeeded; @@ -315,6 +319,35 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd return shelfSymbol; } + /// + /// 创建吊线 + /// + /// + private void CreateMessengerWire(Autodesk.Revit.DB.Document doc, ShelvesPlacementViewModel vm, List locs) + { + doc.Invoke(ts => + { + string file = UserConstant.FamilyLibraryDirectory + "Others\\吊线.rfa"; + FamilySymbol symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try + { + for (int i = 0; i < locs.Count; i++) + { + var instance = doc.Create.NewFamilyInstance(locs[i] + XYZ.BasisZ * (vm.LightHeight + 100) / 304.8, symbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + double length = (UserConstant.Height - vm.LightHeight - 100) / 304.8; + if (length > 0) + { + instance.GetParameters("吊线长度").FirstOrDefault().Set(length); + } + } + } + catch (Exception ex) + { + Log.WriteLog(ex.Message); + } + }, "布置吊线"); + } + private void CreateCableTrays(Autodesk.Revit.DB.Document doc, ShelvesPlacementViewModel vm, Line referline, double shelfSpacing, double passageWidth, double parallelReferlineOffest) { Level level = doc.ActiveView.GenLevel; @@ -346,9 +379,9 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd } foreach (var ct in cts) { - ct.get_Parameter(BuiltInParameter.RBS_CTC_BOTTOM_ELEVATION).Set((vm.LightHeight + 100) / 304.8); ct.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM).Set(100 / 304.8); ct.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM).Set(50 / 304.8); + ct.get_Parameter(BuiltInParameter.RBS_CTC_BOTTOM_ELEVATION).Set((vm.LightHeight + 100) / 304.8); } doc.Regenerate(); List connectors = new List(); @@ -402,7 +435,7 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd }, "桥架创建"); } - private void CreateLights(Autodesk.Revit.DB.Document doc, ShelvesPlacementViewModel vm, Line referline, double shelfSpacing, double passageWidth, double parallelReferlineOffest) + private void CreateLights(Autodesk.Revit.DB.Document doc, ShelvesPlacementViewModel vm, Line referline, double shelfSpacing, double passageWidth, double parallelReferlineOffest, out List Locations) { ObservableCollection shelves = vm.Data; var referlinePoints = GetReferlineCableTrayStartPoint(referline, shelfSpacing, parallelReferlineOffest, shelves.First().Width / 304.8); @@ -412,11 +445,12 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd var totalLength = GetTotalFrontShelvesLength(shelves, shelves.Count) + passageWidth * (shelves.Count - 1); //最后一排 var lastRowPoints = referlinePoints.ConvertAll(p => p + offestVector * (400 / 304.8 + totalLength)); - Family family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Lamp\\筒灯.rfa"); - ElementId symbolId = family.GetFamilySymbolIds().FirstOrDefault(); - FamilySymbol symbol = doc.GetElement(symbolId) as FamilySymbol; - List instanceCreationDatas = new List(); List locs = new List(); + Locations = locs; + + string file = UserConstant.FamilyLibraryDirectory + "Lamp\\筒灯.rfa"; + List instanceCreationDatas = new List(); + for (int i = 0; i < firstRowPoints.Count; i++) { Line line = Line.CreateBound(firstRowPoints[i], lastRowPoints[i]); @@ -436,17 +470,20 @@ namespace RookieStation.ParcelAreaModule.ExecuteCmd } doc.Invoke(ts => { - if (!symbol.IsActive) + FamilySymbol symbol = RsRevitUtils.GetAndActiveDefaultFamilySymbol(doc, file); + try { - symbol.Activate(); + foreach (XYZ p in locs) + { + FamilyInstanceCreationData instanceCreationData = new FamilyInstanceCreationData(p + XYZ.BasisZ * vm.LightHeight / 304.8, symbol, doc.ActiveView.GenLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); + instanceCreationDatas.Add(instanceCreationData); + } + doc.Create.NewFamilyInstances2(instanceCreationDatas); } - - foreach (XYZ p in locs) + catch (Exception ex) { - FamilyInstanceCreationData instanceCreationData = new FamilyInstanceCreationData(p + XYZ.BasisZ * vm.LightHeight / 304.8, symbol, doc.ActiveView.GenLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); - instanceCreationDatas.Add(instanceCreationData); + Log.WriteLog(ex.Message); } - doc.Create.NewFamilyInstances2(instanceCreationDatas); }, "创建灯具"); } diff --git a/RookieStation/ParcelAreaModule/Model/Enum.cs b/RookieStation/ParcelAreaModule/Models/Enum.cs similarity index 94% rename from RookieStation/ParcelAreaModule/Model/Enum.cs rename to RookieStation/ParcelAreaModule/Models/Enum.cs index f7763b6..b3a7b6e 100644 --- a/RookieStation/ParcelAreaModule/Model/Enum.cs +++ b/RookieStation/ParcelAreaModule/Models/Enum.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation.ParcelAreaModule.Model +namespace RookieStation.ParcelAreaModule.Models { public enum NumOfGroup { diff --git a/RookieStation/ParcelAreaModule/Model/Shelf.cs b/RookieStation/ParcelAreaModule/Models/Shelf.cs similarity index 95% rename from RookieStation/ParcelAreaModule/Model/Shelf.cs rename to RookieStation/ParcelAreaModule/Models/Shelf.cs index c167ad0..b4c6453 100644 --- a/RookieStation/ParcelAreaModule/Model/Shelf.cs +++ b/RookieStation/ParcelAreaModule/Models/Shelf.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation.ParcelAreaModule.Model +namespace RookieStation.ParcelAreaModule.Models { public class Shelf { diff --git a/RookieStation/ParcelAreaModule/ViewModel/ShelvesPlacementViewModel.cs b/RookieStation/ParcelAreaModule/ViewModels/ShelvesPlacementViewModel.cs similarity index 97% rename from RookieStation/ParcelAreaModule/ViewModel/ShelvesPlacementViewModel.cs rename to RookieStation/ParcelAreaModule/ViewModels/ShelvesPlacementViewModel.cs index c5cc2d8..618e791 100644 --- a/RookieStation/ParcelAreaModule/ViewModel/ShelvesPlacementViewModel.cs +++ b/RookieStation/ParcelAreaModule/ViewModels/ShelvesPlacementViewModel.cs @@ -1,4 +1,4 @@ -using RookieStation.ParcelAreaModule.Model; +using RookieStation.ParcelAreaModule.Models; using RookieStation.Utils; using System; using System.Collections.Generic; @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RookieStation.ParcelAreaModule +namespace RookieStation.ParcelAreaModule.ViewModels { public class ShelvesPlacementViewModel { diff --git a/RookieStation/ParcelAreaModule/View/WpfEntranceGate.xaml b/RookieStation/ParcelAreaModule/Views/WpfEntranceGate.xaml similarity index 96% rename from RookieStation/ParcelAreaModule/View/WpfEntranceGate.xaml rename to RookieStation/ParcelAreaModule/Views/WpfEntranceGate.xaml index e14c771..15ee97e 100644 --- a/RookieStation/ParcelAreaModule/View/WpfEntranceGate.xaml +++ b/RookieStation/ParcelAreaModule/Views/WpfEntranceGate.xaml @@ -1,5 +1,5 @@  /// WpfEntranceGate.xaml 的交互逻辑 diff --git a/RookieStation/ParcelAreaModule/View/WpfExitGate.xaml b/RookieStation/ParcelAreaModule/Views/WpfExitGate.xaml similarity index 97% rename from RookieStation/ParcelAreaModule/View/WpfExitGate.xaml rename to RookieStation/ParcelAreaModule/Views/WpfExitGate.xaml index a510e5a..ea54409 100644 --- a/RookieStation/ParcelAreaModule/View/WpfExitGate.xaml +++ b/RookieStation/ParcelAreaModule/Views/WpfExitGate.xaml @@ -1,5 +1,5 @@  /// WpfExitGate.xaml 的交互逻辑 @@ -34,10 +34,9 @@ namespace RookieStation.ParcelAreaModule.View { double passageWidth; bool a = double.TryParse(tbPassagewidth.Text, out passageWidth); - + PassageWidth = passageWidth; if (rbStartPassage.IsChecked == true) { - PassageWidth = passageWidth; IsStartPassage = true; } else if (rbStartInspection.IsChecked == true) diff --git a/RookieStation/ParcelAreaModule/View/WpfLampsLayout.xaml b/RookieStation/ParcelAreaModule/Views/WpfLampsLayout.xaml similarity index 97% rename from RookieStation/ParcelAreaModule/View/WpfLampsLayout.xaml rename to RookieStation/ParcelAreaModule/Views/WpfLampsLayout.xaml index a2b28e6..0521c38 100644 --- a/RookieStation/ParcelAreaModule/View/WpfLampsLayout.xaml +++ b/RookieStation/ParcelAreaModule/Views/WpfLampsLayout.xaml @@ -1,5 +1,5 @@  /// WpfLampsLayout.xaml 的交互逻辑 diff --git a/RookieStation/ParcelAreaModule/View/WpfShelfCards.xaml b/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml similarity index 97% rename from RookieStation/ParcelAreaModule/View/WpfShelfCards.xaml rename to RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml index 25dbe51..7c22c06 100644 --- a/RookieStation/ParcelAreaModule/View/WpfShelfCards.xaml +++ b/RookieStation/ParcelAreaModule/Views/WpfShelfCards.xaml @@ -1,5 +1,5 @@  /// WpfShelfCards.xaml 的交互逻辑 @@ -205,7 +205,8 @@ namespace RookieStation.ParcelAreaModule.View var hand = shelf.HandOrientation; var width = shelf.Symbol.GetParameters("宽度").FirstOrDefault().AsDouble(); - Family family = RsRevitUtils.GetLoadedFamily(doc, UserConstant.FamilyLibraryDirectory + "Shelf\\货架端牌.rfa"); + string file = UserConstant.FamilyLibraryDirectory + "Shelf\\货架端牌.rfa"; + Family family = RsRevitUtils.GetLoadedFamily(doc, file); var symbolIds = family.GetFamilySymbolIds(); diff --git a/RookieStation/ParcelAreaModule/View/WpfShelvesLayout.xaml b/RookieStation/ParcelAreaModule/Views/WpfShelvesLayout.xaml similarity index 98% rename from RookieStation/ParcelAreaModule/View/WpfShelvesLayout.xaml rename to RookieStation/ParcelAreaModule/Views/WpfShelvesLayout.xaml index ac6f462..2247236 100644 --- a/RookieStation/ParcelAreaModule/View/WpfShelvesLayout.xaml +++ b/RookieStation/ParcelAreaModule/Views/WpfShelvesLayout.xaml @@ -1,10 +1,10 @@  /// WpfShelvesLayout.xaml 的交互逻辑 diff --git a/RookieStation/ProjectConfig/ExcuteCmd/CmdProjectSettings.cs b/RookieStation/ProjectConfig/ExcuteCmd/CmdProjectSettings.cs index a15e532..605077d 100644 --- a/RookieStation/ProjectConfig/ExcuteCmd/CmdProjectSettings.cs +++ b/RookieStation/ProjectConfig/ExcuteCmd/CmdProjectSettings.cs @@ -1,10 +1,11 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; -using RookieStation.ProjectConfig.View; +using RookieStation.Extension; +using RookieStation.ProjectConfig.Views; using RookieStation.Utils; using System.IO; -namespace RookieStation.ProjectConfig.ExecuteCmd +namespace RookieStation.ProjectConfig.ExecuteCmds { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] @@ -14,11 +15,13 @@ namespace RookieStation.ProjectConfig.ExecuteCmd { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; - Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; - string AddInPath = typeof(CmdProjectSettings).Assembly.Location; - string dirAssembly = Path.GetDirectoryName(AddInPath); - AssemblyLoader loader = new AssemblyLoader(dirAssembly); + Document doc = uidoc.Document; WpfProjectSettings settings = CommonUtils.GenerateWindow(); + doc.Invoke(ts => + { + doc.ProjectInformation.get_Parameter(BuiltInParameter.PROJECT_BUILDING_NAME).Set(Properties.Settings.Default.SchoolName); + doc.ProjectInformation.get_Parameter(BuiltInParameter.PROJECT_NAME).Set(Properties.Settings.Default.ProjectName); + }, "项目设置"); return Result.Succeeded; } diff --git a/RookieStation/ProjectConfig/View/WpfProjectSettings.xaml b/RookieStation/ProjectConfig/Views/WpfProjectSettings.xaml similarity index 67% rename from RookieStation/ProjectConfig/View/WpfProjectSettings.xaml rename to RookieStation/ProjectConfig/Views/WpfProjectSettings.xaml index 65385a9..4f7bf5e 100644 --- a/RookieStation/ProjectConfig/View/WpfProjectSettings.xaml +++ b/RookieStation/ProjectConfig/Views/WpfProjectSettings.xaml @@ -1,5 +1,5 @@  @@ -21,41 +21,71 @@ - + + + + Text="项目名:" /> + + + Text="学校名:" /> + + + +