├── .gitattributes ├── .gitignore ├── README.md ├── 唐僧解瓦.sln └── 唐僧解瓦 ├── BinLibrary ├── Extensions │ ├── BitmapExtension.cs │ ├── ColorExtension.cs │ ├── ConnectorExtension.cs │ ├── CreationExtension.cs │ ├── DocumentExtension.cs │ ├── DoubleExtension.cs │ ├── ElementIdExtension.cs │ ├── GeometryElementExtension.cs │ ├── GeometryObjectExtension.cs │ ├── LineExtension.cs │ ├── MepcurveExtension.cs │ ├── PipeExtension.cs │ ├── PointExtension.cs │ ├── ReferenceExtension.cs │ ├── SelectionFilter.cs │ ├── TransactionExtension.cs │ ├── UIDocumentExtension.cs │ ├── VectorExtension.cs │ ├── WindwoExtension.cs │ └── XYZExtension.cs ├── Geometryalgorithm │ └── PolygonHelper.cs ├── Helpers │ ├── ConnectorHelper.cs │ ├── CurveHelper.cs │ ├── LogHelper.cs │ ├── TransactionHelper.cs │ └── collectorHelper.cs ├── RevitHelper │ └── RevitWindowHelper.cs └── Utils │ └── Utils.cs ├── Class1.cs ├── HWCracApp.cs ├── Properties ├── AssemblyInfo.cs ├── Resource1.Designer.cs ├── Resource1.resx ├── Resource2.Designer.cs └── Resource2.resx ├── Resources ├── hideshow.png ├── sj1.png └── sj2.png ├── Test ├── Cmd_About.cs ├── Cmd_CalculateAreaOfShipment.cs ├── Cmd_CalculateConcreteVolume.cs ├── Cmd_CreateColumnAccordingGridIntersection.cs ├── Cmd_DimLine.cs ├── Cmd_DimPipe.cs ├── Cmd_EncodeElements.cs ├── Cmd_ExternalStorageDataTest.cs ├── Cmd_ExternalStorageTest.cs ├── Cmd_FlipTee.cs ├── Cmd_GetCuttedFace.cs ├── Cmd_InRegionTest.cs ├── Cmd_MeasureTool.cs ├── Cmd_MepcurveDirTest.cs ├── Cmd_RotateTest.cs ├── Cmd_SurfaceTest.cs ├── Cmd_Updatefiles.cs ├── TestCmd_AdaptiveTest.cs ├── TestCmd_FIlterRoom.cs └── UIs │ ├── AboutForm.Designer.cs │ ├── AboutForm.cs │ ├── AboutForm.resx │ ├── ColumnTypesForm.Designer.cs │ ├── ColumnTypesForm.cs │ └── ColumnTypesForm.resx ├── 唐僧解瓦.csproj ├── 工具 └── AssemblyTools1.1 无日期限制版.zip ├── 建筑 ├── Cmd_BeamAlignToRoofAndFloor.cs ├── Cmd_CreateFloorQukly.cs ├── Cmd_CutFloorWithLine.cs ├── Cmd_SetDefaultWallType.cs └── Utils.cs ├── 机电 ├── About │ ├── About.xaml │ ├── About.xaml.cs │ └── AboutCommand.cs ├── Cmd_BreakWire.cs ├── Cmd_ChamferPipes.cs ├── Cmd_ConnectEquipMent.cs ├── Cmd_CutMepsInPieces.cs ├── Cmd_ElementFilterTest.cs ├── Cmd_ExtendWire.cs ├── Cmd_HideSplitWire.cs ├── Cmd_MepCurveBreak.cs ├── Cmd_MepCurveRank.cs ├── Cmd_MepsAlongFloor.cs ├── Cmd_MultiRotateDuctEnds.cs ├── Cmd_RaiseTeeBranch.cs ├── Cmd_Recursion.cs ├── Cmd_SelectLinkedPipes.cs ├── Cmd_VerticalPipeConvert.cs ├── Cmd_changeSystem.cs └── ToolUIs │ ├── FilterWindow.Designer.cs │ ├── FilterWindow.cs │ ├── FilterWindow.resx │ ├── MepcurveRank.xaml │ ├── MepcurveRank.xaml.cs │ ├── ValueSettingUI.xaml │ └── ValueSettingUI.xaml.cs ├── 样例项目 └── 楼板测试.rvt ├── 样板 ├── Cmd_CopyViewCropRegion.cs ├── Cmd_CreateNewCableTrayType.cs ├── Cmd_HideMepCenter.cs ├── Cmd_HideRevitInstance.cs └── UIs │ ├── TypeSelector.xaml │ ├── TypeSelector.xaml.cs │ ├── ViewSelector.xaml │ └── ViewSelector.xaml.cs ├── 注释 ├── Cmd_DimAllDuctsAndNearestGrid.cs ├── Cmd_DimAllPipesAndNearestGrid.cs ├── Cmd_DimPipeAndGrid.cs ├── Cmd_FlipDimension.cs ├── Cmd_LengthAccumulate.cs ├── Cmd_SectionGap.cs └── UIs │ ├── ResultShow.xaml │ └── ResultShow.xaml.cs ├── 通用 ├── Cmd_3DregionView.cs ├── Cmd_CategoryFilter.cs ├── Cmd_ChangeBackGroundColor.cs ├── Cmd_ChangeType.cs ├── Cmd_ElementTest.cs ├── Cmd_Floor3D.cs ├── Cmd_HideElementInfamilyDoc.cs ├── Cmd_MepLineUpDownVisble.cs ├── Cmd_MultipleLinkFile.cs ├── Cmd_PickBox3D.cs ├── Cmd_ReverseBackGroundColor.cs ├── Cmd_UnhideElementsInFamlyDoc.cs ├── Cmd_UpdateFiles.cs ├── Cmd_ViewSimultaneous.cs ├── Cmd_netHeightAnalyses.cs └── UIs │ ├── FloorSelector.xaml │ ├── FloorSelector.xaml.cs │ ├── FloorTypeSelector.xaml │ ├── FloorTypeSelector.xaml.cs │ ├── ViewSemutaneousSelector.xaml │ └── ViewSemutaneousSelector.xaml.cs └── 高级 ├── Cmd_CallSystemCmd.cs ├── Cmd_DragTest.cs └── UIs ├── DragForm.Designer.cs ├── DragForm.cs └── DragForm.resx /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 唐僧解瓦 2 | 3 | 4 | 唐僧不止会念经,还会写代码! 5 | 6 | 项目适用于Revit2018或Revit2019,请在Revit2018或Revit2019环境中调试 7 | 8 | revit二次开发技术交流QQ群:166072827 9 | 10 | 功能列表: 11 | 12 | 通用:**局部三维 13 | **框选三维 14 | **楼层三维 15 | **更改背景颜色 16 | **反转背景颜色 17 | **在族中隐藏元素 18 | **在族中显示隐藏的元素 19 | **净高分析(开发中) 20 | **升级文件 21 | **批量连接文件 22 | **视图同步 23 | ... 24 | 机电: 25 | **管线倒角 26 | **连接设备(开发中) 27 | **管线分段 28 | **打断管线 29 | **管线排列 30 | **管线随板 31 | **从CAD转换立管 32 | 33 | 建筑: 34 | ... 35 | **一键楼板 36 | 37 | 38 | 结构: 39 | ... 40 | -------------------------------------------------------------------------------- /唐僧解瓦.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.271 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "唐僧解瓦", "唐僧解瓦\唐僧解瓦.csproj", "{D21B1165-162A-4569-95C9-D2DBECDBD6C7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D21B1165-162A-4569-95C9-D2DBECDBD6C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D21B1165-162A-4569-95C9-D2DBECDBD6C7}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D21B1165-162A-4569-95C9-D2DBECDBD6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D21B1165-162A-4569-95C9-D2DBECDBD6C7}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {02827F19-F9E5-4A72-8114-DDBECD6012BF} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/BitmapExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows; 4 | using System.Windows.Media.Imaging; 5 | 6 | namespace 唐僧解瓦.BinLibrary.Extensions 7 | { 8 | public static class BitmapExtension 9 | { 10 | public static BitmapSource ToBitmapSource(this Bitmap bitmap) 11 | { 12 | BitmapSource result = null; 13 | IntPtr handle = bitmap.GetHbitmap(); 14 | result = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, 15 | System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); 16 | return result; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/ColorExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class ColorExtension 6 | { 7 | public static Color InversColor(this Color color) 8 | { 9 | var newcolor = default(Color); 10 | 11 | var newR = (byte)(255 - color.Red); 12 | var newG = (byte)(255 - color.Green); 13 | var newB = (byte)(255 - color.Blue); 14 | 15 | newcolor = new Color(newR, newG, newB); 16 | 17 | return newcolor; 18 | } 19 | 20 | public static Color ToRvtColor(this System.Drawing.Color color) 21 | { 22 | var r = color.R; 23 | var g = color.G; 24 | var b = color.B; 25 | 26 | return new Color(r,g,b); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/ConnectorExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class ConnectorExtension 6 | { 7 | public static Connector GetConnectedCon(this Connector connector) 8 | { 9 | var result = default(Connector); 10 | var conectors = connector.AllRefs; 11 | var connectordir = connector.CoordinateSystem.BasisZ; 12 | var connectorOrigin = connector.Origin; 13 | 14 | foreach (Connector con in conectors) 15 | { 16 | if (con.IsConnectedTo(connector) && con.ConnectorType != ConnectorType.Logical) 17 | { 18 | result = con; 19 | } 20 | 21 | //if (con.ConnectorType == ConnectorType.End ) 22 | //{ 23 | // var conOrigin = con.Origin; 24 | // var condir = con.CoordinateSystem.BasisZ; 25 | // if (connectorOrigin.IsAlmostEqualTo(conOrigin) && connectordir.IsOppositeDirection(condir)) 26 | // { 27 | // result = con; 28 | // } 29 | //} 30 | //else if (con.ConnectorType == ConnectorType.Curve) 31 | //{ 32 | // var conOrigin = con.Origin; 33 | // var condir = con.CoordinateSystem.BasisZ; 34 | // if (connectorOrigin.IsAlmostEqualTo(conOrigin) && connectordir.IsOppositeDirection(condir)) 35 | // { 36 | // result = con; 37 | // } 38 | //} 39 | } 40 | return result; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/CreationExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using 唐僧解瓦.BinLibrary.Helpers; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Extensions 5 | { 6 | public static class CreationExtension 7 | { 8 | public static void NewLine_withoutTransaction(this Document doc, Line line) 9 | { 10 | var dir = line.Direction; 11 | var origin = line.Origin; 12 | var norm = default(XYZ); 13 | 14 | norm = dir.getRandomNorm(); 15 | var plan = default(Plane);//.CreateByNormalAndOrigin(norm, origin); 16 | #if Revit2018 17 | plan = Plane.CreateByNormalAndOrigin(norm, origin); 18 | #endif 19 | #if Revit2016 20 | plan =new Plane (norm, origin); 21 | #endif 22 | 23 | var sketchplane = SketchPlane.Create(doc, plan); 24 | doc.Create.NewModelCurve(line, sketchplane); 25 | } 26 | public static void NewLine(this Document doc, Line line) 27 | { 28 | var dir = line.Direction; 29 | var origin = line.Origin; 30 | var norm = default(XYZ); 31 | 32 | norm = dir.getRandomNorm(); 33 | 34 | #region oldFun 35 | 36 | //if (dir.IsParallel(XYZ.BasisX)) 37 | //{ 38 | // norm = dir.CrossProduct(XYZ.BasisY).Normalize(); 39 | // //MessageBox.Show("X"); 40 | //} 41 | //else if (dir.IsParallel(XYZ.BasisY)) 42 | //{ 43 | // norm = dir.CrossProduct(XYZ.BasisX).Normalize(); 44 | // //MessageBox.Show("Y"); 45 | //} 46 | //else if (dir.IsParallel(XYZ.BasisZ)) 47 | //{ 48 | // norm = dir.CrossProduct(XYZ.BasisX); 49 | // //MessageBox.Show("Z"); 50 | //} 51 | //else 52 | //{ 53 | // norm = dir.CrossProduct(XYZ.BasisX); 54 | //} 55 | 56 | #endregion 57 | 58 | var plan = default(Plane); // Plane.CreateByNormalAndOrigin(norm, origin); 59 | 60 | #if Revit2016 61 | plan = new Plane(norm, origin); 62 | #endif 63 | #if Revit2018 64 | plan = Plane.CreateByNormalAndOrigin(norm, origin); 65 | #endif 66 | 67 | 68 | doc.Invoke(m => 69 | { 70 | var sketchplane = SketchPlane.Create(doc, plan); 71 | doc.Create.NewModelCurve(line, sketchplane); 72 | }, "aa"); 73 | } 74 | 75 | public static void Newbox(this Document doc, BoundingBoxXYZ box) 76 | { 77 | var trans = box.Transform; 78 | var min = box.Min; 79 | var max = box.Max; 80 | var x = max.X - min.X; 81 | var y = max.Y - min.Y; 82 | var z = max.Z - min.Z; 83 | 84 | //1、 85 | var endx = min + x * trans.BasisX; 86 | var linex = Line.CreateBound(min, endx); 87 | 88 | var linex_1 = Line.CreateBound(endx, endx + y * trans.BasisY); 89 | var linex_2 = Line.CreateBound(endx, endx + z * trans.BasisZ); 90 | 91 | var endy = min + y * trans.BasisY; 92 | var liney = Line.CreateBound(min, endy); 93 | 94 | var liney_1 = Line.CreateBound(endy, endy + x * trans.BasisX); 95 | var liney_2 = Line.CreateBound(endy, endy + z * trans.BasisZ); 96 | 97 | var endz = min + z * trans.BasisZ; 98 | var linez = Line.CreateBound(min, endz); 99 | 100 | var linez_1 = Line.CreateBound(endz, endz + x * trans.BasisX); 101 | var linez_2 = Line.CreateBound(endz, endz + y * trans.BasisY); 102 | 103 | var _linex = Line.CreateBound(max, max - x * trans.BasisX); 104 | var _liney = Line.CreateBound(max, max - y * trans.BasisY); 105 | var _linez = Line.CreateBound(max, max - z * trans.BasisZ); 106 | doc.Invoke(m => 107 | { 108 | doc.NewLine_withoutTransaction(linex); 109 | doc.NewLine_withoutTransaction(linex_1); 110 | doc.NewLine_withoutTransaction(linex_2); 111 | doc.NewLine_withoutTransaction(liney); 112 | doc.NewLine_withoutTransaction(liney_1); 113 | doc.NewLine_withoutTransaction(liney_2); 114 | doc.NewLine_withoutTransaction(linez); 115 | doc.NewLine_withoutTransaction(linez_1); 116 | doc.NewLine_withoutTransaction(linez_2); 117 | doc.NewLine_withoutTransaction(_linex); 118 | doc.NewLine_withoutTransaction(_liney); 119 | doc.NewLine_withoutTransaction(_linez); 120 | },"创建包围框"); 121 | 122 | } 123 | 124 | public static void NewCoordinate(this Document doc, XYZ po, Transform trs, double dis = 2) 125 | { 126 | var linex = Line.CreateBound(po, po + dis * trs.BasisX); 127 | var liney = Line.CreateBound(po, po + dis * trs.BasisY); 128 | var linez = Line.CreateBound(po, po + dis * trs.BasisZ); 129 | 130 | doc.Invoke(m => 131 | { 132 | doc.NewLine_withoutTransaction(linex); 133 | doc.NewLine_withoutTransaction(liney); 134 | doc.NewLine_withoutTransaction(linez); 135 | }, "创建坐标"); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/DocumentExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.UI; 8 | 9 | namespace 唐僧解瓦.BinLibrary.Extensions 10 | { 11 | public static class DocumentExtension 12 | { 13 | public static UIView ActiveUiview(this UIDocument uidoc) 14 | { 15 | var acview = uidoc.ActiveView; 16 | var uiviews = uidoc.GetOpenUIViews(); 17 | var acuiview = uiviews.Where(m => acview.Id == m.ViewId).FirstOrDefault(); 18 | return acuiview; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/DoubleExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class DoubleExtension 6 | { 7 | public static double precision = 1e-6; 8 | /// 9 | /// 判断双精度数值相等 小于1e-6 就认为相等 10 | /// 11 | /// 12 | /// 13 | /// 14 | public static bool IsEqual(this double num1, double num2) 15 | { 16 | double subtract = num1 - num2; 17 | if (Math.Abs(subtract) < precision) 18 | { 19 | return true; 20 | } 21 | return false; 22 | } 23 | public static double MetricToFeet(this double double1) 24 | { 25 | return double1 / 304.8; 26 | } 27 | public static double FeetToMetric(this double double1) 28 | { 29 | return double1 * 304.8; 30 | } 31 | 32 | public static double RadiusToDegree(this double double1) 33 | { 34 | return double1 * 180 / Math.PI; 35 | } 36 | 37 | public static double DegreeToRadius(this double double1) 38 | { 39 | return double1 * Math.PI / 180; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/ElementIdExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class ElementIdExtension 6 | { 7 | public static Element GetElement(this ElementId eleid,Document doc) 8 | { 9 | return doc.GetElement(eleid); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/GeometryElementExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System.Collections.Generic; 3 | 4 | 5 | namespace 唐僧解瓦.BinLibrary.Extensions 6 | { 7 | public static class GeometryElementExtension 8 | { 9 | public static List GetGeometries(this GeometryElement geoele) 10 | { 11 | List result = new List(); 12 | var enu = geoele.GetEnumerator(); 13 | while (enu.MoveNext()) 14 | { 15 | var geoobj = enu.Current as GeometryObject; 16 | if (geoobj != null) 17 | { 18 | result.Add(geoobj); 19 | } 20 | } 21 | return result; 22 | } 23 | public static List GetFaces(this GeometryElement geoele) 24 | { 25 | List result = new List(); 26 | var geoobjs = geoele.GetGeometries(); 27 | foreach (GeometryObject geoobbj in geoobjs) 28 | { 29 | result.AddRange(geoobbj.GetFacesOfGeometryObject()); 30 | } 31 | return result; 32 | } 33 | public static List GetEdges(this GeometryElement geoele) 34 | { 35 | List result = new List(); 36 | var geoobjs = geoele.GetGeometries(); 37 | foreach (GeometryObject geoobj in geoobjs) 38 | { 39 | result.AddRange(geoobj.GetEdgesofGeometryObject()); 40 | } 41 | return result; 42 | } 43 | public static List GetPoints(this GeometryElement geoele) 44 | { 45 | List result = new List(); 46 | 47 | //var geoobjs = geoele.GetGeometries(); 48 | var geoedges = geoele.GetEdges(); 49 | 50 | var points = new List(); 51 | 52 | foreach (var edge in geoedges) 53 | { 54 | var curve = edge.AsCurve(); 55 | 56 | var startpoint = curve.GetEndPoint(0); 57 | var endpoint = curve.GetEndPoint(1); 58 | 59 | //判断点是否位置上重合 如果不重合 则添加进结果列表 60 | 61 | var startflag = false; 62 | var endflag = false; 63 | points.ForEach(m => 64 | { 65 | if (m.DistanceTo(startpoint) < 1e-6) startflag = true; 66 | if (m.DistanceTo(endpoint) < 1e-6) endflag = true; 67 | }); 68 | 69 | //MessageBox.Show(startflag.ToString() + Environment.NewLine + 70 | // endflag.ToString()); 71 | 72 | if (!startflag) 73 | points.Add(startpoint); 74 | if (!endflag) 75 | points.Add(endpoint); 76 | } 77 | 78 | result = points; 79 | return result; 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/LineExtension.cs: -------------------------------------------------------------------------------- 1 |  2 | using Autodesk.Revit.DB; 3 | using System.Linq; 4 | 5 | namespace 唐僧解瓦.BinLibrary.Extensions 6 | { 7 | public static class LineExtension 8 | { 9 | public static XYZ StartPoint(this Line line) 10 | { 11 | if (line.IsBound) 12 | return line.GetEndPoint(0); 13 | return null; 14 | } 15 | public static XYZ EndPoint(this Line line) 16 | { 17 | if (line.IsBound) 18 | return line.GetEndPoint(1); 19 | return null; 20 | } 21 | 22 | /// 23 | /// 垂直于面 错误 24 | /// 25 | /// 26 | /// 27 | /// 28 | public static XYZ Intersect_cus(this Line line, Plane p) 29 | { 30 | var lineorigin = line.Origin; 31 | var linedir = line.Direction; 32 | 33 | var pointOnLine = lineorigin + linedir; 34 | 35 | var trans = Transform.Identity; 36 | trans.Origin = p.Origin; 37 | trans.BasisX = p.XVec; 38 | trans.BasisY = p.YVec; 39 | trans.BasisZ = p.Normal; 40 | 41 | var point1 = lineorigin; 42 | var point2 = pointOnLine; 43 | 44 | var point1Intrans = trans.Inverse.OfPoint(point1); 45 | var point2Intrans = trans.Inverse.OfPoint(point2); 46 | 47 | point1Intrans = new XYZ(point1Intrans.X,point1Intrans.Y,0); 48 | point2Intrans = new XYZ(point2Intrans.X,point2Intrans.Y,0); 49 | 50 | var point1Inworld = trans.OfPoint(point1Intrans); 51 | var point2Inworld = trans.OfPoint(point2Intrans); 52 | 53 | var newlineInPlan = Line.CreateBound(point1Inworld, point2Inworld); 54 | 55 | var unboundnewLine = newlineInPlan.Clone() as Line; 56 | unboundnewLine.MakeUnbound(); 57 | 58 | var unboundOriginalLine = line.Clone() as Line; 59 | unboundOriginalLine.MakeUnbound(); 60 | 61 | return unboundnewLine.Intersect_cus(unboundOriginalLine); 62 | } 63 | 64 | public static XYZ Intersect_cus(this Line line1, Line line2) 65 | { 66 | var compareResulst = line1.Intersect(line2, out IntersectionResultArray intersectResult); 67 | 68 | if(compareResulst!=SetComparisonResult.Disjoint) 69 | { 70 | var result = intersectResult.get_Item(0).XYZPoint; 71 | return result; 72 | } 73 | 74 | return null; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/MepcurveExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class MepcurveExtension 6 | { 7 | public static Line LocationLine(this MEPCurve mep) 8 | { 9 | Line result = null; 10 | 11 | result = (mep.Location as LocationCurve).Curve as Line; 12 | 13 | return result; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/PipeExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.DB.Plumbing; 8 | 9 | namespace 唐僧解瓦.BinLibrary.Extensions 10 | { 11 | public static class PipeExtension 12 | { 13 | public static FamilyInstance ElbowConnect(this Pipe pipe1, Pipe pipe2) 14 | { 15 | var line1 = pipe1.LocationLine(); 16 | var line2 = pipe2.LocationLine(); 17 | 18 | var line1copy = line1.Clone() as Line; 19 | var line2copy = line2.Clone() as Line; 20 | line2copy.MakeUnbound(); 21 | line1copy.MakeUnbound(); 22 | 23 | var intersection = line1copy.Intersect_cus(line2copy); 24 | 25 | if (intersection == null) return null; 26 | 27 | var newline1 = default(Line); 28 | if (line1.StartPoint().DistanceTo(intersection) <= line1.EndPoint().DistanceTo(intersection)) 29 | { 30 | newline1 = Line.CreateBound(intersection, line1.EndPoint()); 31 | } 32 | else 33 | { 34 | newline1 = Line.CreateBound(line1.StartPoint(), intersection); 35 | } 36 | 37 | var newline2 = default(Line); 38 | if (line2.StartPoint().DistanceTo(intersection) <= line2.EndPoint().DistanceTo(intersection)) 39 | { 40 | newline2 = Line.CreateBound(intersection, line2.EndPoint()); 41 | } 42 | else 43 | { 44 | newline2 = Line.CreateBound(line2.StartPoint(), intersection); 45 | } 46 | 47 | (pipe1.Location as LocationCurve).Curve = newline1; 48 | (pipe2.Location as LocationCurve).Curve = newline2; 49 | 50 | var doc = pipe1.Document; 51 | doc.Regenerate(); 52 | 53 | var con1 = pipe1.ConnectorManager.Connectors.Cast() 54 | .Where(m => m.ConnectorType == ConnectorType.Curve || m.ConnectorType == ConnectorType.End) 55 | .Where(m => m.Origin.IsAlmostEqualTo(intersection)).FirstOrDefault(); 56 | 57 | var con2 = pipe2.ConnectorManager.Connectors.Cast() 58 | .Where(m => m.ConnectorType == ConnectorType.Curve || m.ConnectorType == ConnectorType.End) 59 | .Where(m => m.Origin.IsAlmostEqualTo(intersection)).FirstOrDefault(); 60 | 61 | var result = doc.Create.NewElbowFitting(con1, con2); 62 | 63 | return result; 64 | } 65 | 66 | public static Connector StartCon(this Pipe pipe1) 67 | { 68 | Connector result = null; 69 | 70 | var locationline = pipe1.LocationLine(); 71 | 72 | 73 | var connectors = pipe1.ConnectorManager.Connectors.Cast() 74 | .Where(m => m.ConnectorType == ConnectorType.End).ToList(); 75 | 76 | var startcon = connectors.First(m => m.Origin.IsAlmostEqualTo(locationline.StartPoint())); 77 | result = startcon; 78 | 79 | return result; 80 | } 81 | 82 | public static Connector EndCon(this Pipe pipe1) 83 | { 84 | Connector result = null; 85 | 86 | var locationline = pipe1.LocationLine(); 87 | 88 | 89 | var connectors = pipe1.ConnectorManager.Connectors.Cast() 90 | .Where(m => m.ConnectorType == ConnectorType.End).ToList(); 91 | 92 | var startcon = connectors.First(m => m.Origin.IsAlmostEqualTo(locationline.EndPoint())); 93 | result = startcon; 94 | 95 | return result; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/PointExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Extensions 5 | { 6 | public static class PointExtension 7 | { 8 | 9 | 10 | /// 11 | /// 投影到射线上 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static XYZ ProjectToXLine(this XYZ po, Line l/*有限长度线段*/) 17 | { 18 | Line l1 = l.Clone() as Line; 19 | if (l1.IsBound) 20 | { 21 | l1.MakeUnbound(); 22 | } 23 | return l1.Project(po).XYZPoint; 24 | } 25 | /// 26 | /// 浮点数相等时的精度 27 | /// 28 | private static double precision = 0.000001; 29 | 30 | /// 31 | /// 判断两double数值是否相等 32 | /// 33 | /// 34 | /// 35 | /// 36 | public static bool IsEqual(double d1, double d2) 37 | { 38 | double diff = Math.Abs(d1 - d2); 39 | return diff < precision; 40 | 41 | } 42 | /// 43 | /// 判断点是否在线段上 44 | /// 45 | /// 46 | /// 47 | /// 48 | public static bool IsOnLine(this XYZ p, Line l) 49 | { 50 | XYZ end1 = l.GetEndPoint(0); 51 | XYZ end2 = l.GetEndPoint(1); 52 | 53 | XYZ vec_pToEnd1 = end1 - p; 54 | XYZ vec_pToEnd2 = end2 - p; 55 | 56 | double precision = 0.0000001d; 57 | 58 | if (p.DistanceTo(end1) < precision || p.DistanceTo(end2) < precision) 59 | { 60 | return true; 61 | } 62 | if (vec_pToEnd1.IsOppositeDirection(vec_pToEnd2)) 63 | { 64 | return true; 65 | } 66 | return false; 67 | } 68 | /// 69 | /// 判断点是否在线 或线的延长线上 70 | /// 71 | /// 72 | /// 73 | /// 74 | public static bool IsXOnLine(this XYZ p, Line l) 75 | { 76 | double precision = 0.0000001d; 77 | var l1 = l.Clone() as Line; 78 | l1.MakeUnbound(); 79 | if (p.DistanceTo(l1) < precision) 80 | { 81 | return true; 82 | } 83 | return false; 84 | } 85 | 86 | public static double DistanceTo(this XYZ p1, Line xline) 87 | { 88 | double result = double.NegativeInfinity; 89 | 90 | XYZ p1_onLine = p1.ProjectToXLine(xline); 91 | 92 | result = p1.DistanceTo(p1_onLine); 93 | 94 | return result; 95 | } 96 | 97 | 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/ReferenceExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | 6 | public static class ReferenceExtension 7 | { 8 | public static Element GetElement(this Reference thisref, Document doc) 9 | { 10 | return doc.GetElement(thisref); 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/SelectionFilter.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using Autodesk.Revit.UI.Selection; 3 | using System; 4 | 5 | namespace 唐僧解瓦.BinLibrary.Extensions 6 | { 7 | public class SelectionFilter : ISelectionFilter 8 | { 9 | private Document _doc; 10 | private Type _type; 11 | 12 | public SelectionFilter(Document doc, Type type) 13 | { 14 | _doc = doc; 15 | _type = type; 16 | } 17 | public bool AllowElement(Element elem) 18 | { 19 | if (elem.GetType() == _type) 20 | { 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | public bool AllowReference(Reference reference, XYZ position) 27 | { 28 | return true; 29 | } 30 | } 31 | 32 | public static class SelectionFilterHelper 33 | { 34 | 35 | 36 | public static MultiSelectionFilter GetSelectionFilter(this Document doc, Func func1, Func func2 = null) 37 | { 38 | return new MultiSelectionFilter(func1, func2); 39 | } 40 | } 41 | public class MultiSelectionFilter : ISelectionFilter 42 | { 43 | private Func eleFunc; 44 | private Func refFunc; 45 | 46 | 47 | public MultiSelectionFilter(Func func, Func func1) 48 | { 49 | eleFunc = func; 50 | refFunc = func1; 51 | } 52 | public bool AllowElement(Element elem) 53 | { 54 | return refFunc != null ? true : eleFunc(elem); 55 | } 56 | 57 | public bool AllowReference(Reference reference, XYZ position) 58 | { 59 | return refFunc == null ? false : refFunc(reference); 60 | //return refFunc(reference); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/TransactionExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class TransactionExtension 6 | { 7 | public static void IgnoreFailure(this Transaction trans) 8 | { 9 | var options = trans.GetFailureHandlingOptions(); 10 | options.SetFailuresPreprocessor(new failure_ignore()); 11 | } 12 | 13 | //public static void Invoke(this Document doc, Action action, string transactionName = "aaa") 14 | //{ 15 | // Transaction ts = new Transaction(doc, transactionName); 16 | // LogHelper.LogException(delegate 17 | // { 18 | // ts.Start(); 19 | // action(ts); 20 | // ts.Commit(); 21 | // }, @"c:\transactionException.txt"); 22 | //} 23 | } 24 | 25 | public class failure_ignore : IFailuresPreprocessor 26 | { 27 | public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor) 28 | { 29 | failuresAccessor.DeleteAllWarnings(); 30 | //failuresAccessor.DeleteElements(failuresAccessor.el); 31 | return FailureProcessingResult.Continue; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/UIDocumentExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.UI; 2 | using System.Linq; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Extensions 5 | { 6 | public static class UIDocumentExtension 7 | { 8 | public static UIView ActiveUIView(this UIDocument uidoc) 9 | { 10 | var result = default(UIView); 11 | var doc = uidoc.Document; 12 | var acview = doc.ActiveView; 13 | 14 | var uiviews = uidoc.GetOpenUIViews(); 15 | result = uiviews.FirstOrDefault(m => m.ViewId == acview.Id); 16 | return result; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/VectorExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Extensions 5 | { 6 | public static class VectorExtension 7 | { 8 | private static double precision = 0.000001; 9 | public static bool IsParallel(this XYZ vector1, XYZ vector2) 10 | { 11 | return vector1.IsSameDirection(vector2) || vector1.IsOppositeDirection(vector2); 12 | } 13 | /// 14 | /// 判断同向 15 | /// 16 | /// 17 | /// 18 | /// 19 | public static bool IsSameDirection(this XYZ dir1, XYZ dir2) 20 | { 21 | bool result = false; 22 | 23 | double dotproduct = dir1.Normalize().DotProduct(dir2.Normalize()); 24 | 25 | if (Math.Abs(dotproduct - 1) < precision) 26 | { 27 | result = true; 28 | } 29 | 30 | return result; 31 | } 32 | /// 33 | /// 判断反向 34 | /// 35 | /// 36 | /// 37 | /// 38 | public static bool IsOppositeDirection(this XYZ dir1, XYZ dir2) 39 | { 40 | bool result = false; 41 | 42 | double dotproduct = dir1.Normalize().DotProduct(dir2.Normalize()); 43 | 44 | if (Math.Abs(dotproduct + 1) < precision) 45 | { 46 | result = true; 47 | } 48 | 49 | return result; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/WindwoExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Interop; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Extensions 5 | { 6 | public static class WindwoExtension 7 | { 8 | public static WindowInteropHelper helper(this Window win) 9 | { 10 | var helper = new WindowInteropHelper(win); 11 | return helper; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Extensions/XYZExtension.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace 唐僧解瓦.BinLibrary.Extensions 4 | { 5 | public static class XYZExtension 6 | { 7 | public static XYZ xyComponent(this XYZ po) 8 | { 9 | return new XYZ(po.X, po.Y, 0); 10 | } 11 | 12 | public static XYZ getRandomNorm(this XYZ vec) 13 | { 14 | XYZ norm = new XYZ(-vec.Y + vec.Z, vec.X + vec.Z, -vec.Y - vec.X); 15 | return norm.Normalize(); 16 | } 17 | /// 18 | /// 将点投影到面 19 | /// 20 | /// 21 | /// 22 | /// 23 | public static XYZ ProjectTo(this XYZ po, Plane p) 24 | { 25 | var transform = Transform.Identity; 26 | 27 | transform.Origin = p.Origin; 28 | transform.BasisX = p.XVec; 29 | transform.BasisY = p.YVec; 30 | transform.BasisZ = p.Normal; 31 | 32 | var poInTrans = transform.Inverse.OfPoint(po); 33 | 34 | var po_proj = new XYZ(poInTrans.X,poInTrans.Y,0); 35 | 36 | var po_projInWorld = transform.OfPoint(po_proj); 37 | return po_projInWorld; 38 | } 39 | /// 40 | /// 将点投影到线 41 | /// 42 | /// 43 | /// 44 | /// 45 | public static XYZ ProjectTo(this XYZ po, Line l) 46 | { 47 | var dir = l.Direction; 48 | var transform = Transform.Identity; 49 | 50 | transform.Origin = l.Origin; 51 | transform.BasisX = dir.RandVerticalVec().Normalize(); 52 | transform.BasisY =(l.Direction.CrossProduct(transform.BasisX)).Normalize(); 53 | transform.BasisZ = l.Direction; 54 | 55 | var poInTrans = transform.Inverse.OfPoint(po); 56 | 57 | var poInTransProj = new XYZ(0,0,poInTrans.Z); 58 | 59 | var poInTransProjInWrold = transform.OfPoint(poInTransProj); 60 | 61 | return poInTransProjInWrold; 62 | } 63 | /// 64 | /// 获取任意垂直向量 65 | /// 66 | /// 67 | /// 68 | private static XYZ RandVerticalVec(this XYZ vec) 69 | { 70 | XYZ ret = new XYZ(-vec.Y + vec.Z, vec.X + vec.Z, -vec.Y - vec.X); 71 | return ret; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Geometryalgorithm/PolygonHelper.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using 唐僧解瓦.BinLibrary.Extensions; 6 | 7 | namespace 唐僧解瓦.BinLibrary.Geometryalgorithm 8 | { 9 | public class PolygonHelper 10 | { 11 | /// 12 | /// 判断点在多边形内(包含凹凸多边形) 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | public static bool IsPointInRegion(XYZ po, List points, XYZ planNorm) 19 | { 20 | bool result = false; 21 | var angles = 0.0; 22 | for (int i = 0; i < points.Count; i++) 23 | { 24 | if (i < points.Count - 1) 25 | { 26 | var curpo = points.ElementAt(i); 27 | var nextpo = points.ElementAt(i + 1); 28 | 29 | var line = Line.CreateBound(curpo, nextpo); 30 | if (po.IsOnLine(line)) 31 | { 32 | return true; 33 | } 34 | var angle = Angle(curpo, nextpo, po, planNorm); 35 | //MessageBox.Show(angle.ToString()); 36 | angles += angle; 37 | } 38 | else if (i == points.Count - 1) 39 | { 40 | var curpo = points.ElementAt(i); 41 | var nextpo = points.ElementAt(0); 42 | 43 | var line = Line.CreateBound(curpo, nextpo); 44 | if (po.IsOnLine(line)) 45 | { 46 | return true; 47 | } 48 | var angle = Angle(curpo, nextpo, po, planNorm); 49 | //MessageBox.Show(angle.ToString()); 50 | angles += angle; 51 | } 52 | } 53 | //MessageBox.Show(angles.ToString()); 54 | angles = Math.Abs(angles); 55 | if (angles.IsEqual(2 * Math.PI)) 56 | { 57 | result = true; 58 | } 59 | else 60 | { 61 | result = false; 62 | } 63 | return result; 64 | } 65 | 66 | /// 67 | /// 计算∠point1_point0_point2 的角度 68 | /// 69 | /// 70 | /// 71 | /// 72 | /// 73 | /// 74 | public static double Angle(XYZ point1, XYZ point2, XYZ point0, XYZ planNorm) 75 | { 76 | var line = Line.CreateBound(point1, point2); 77 | if (point0.IsOnLine(line)) 78 | { 79 | throw new Exception("samline Exception"); 80 | } 81 | 82 | var vec1 = (point1 - point0).Normalize(); 83 | var vec2 = (point2 - point0).Normalize(); 84 | if (vec1.IsSameDirection(vec2)) 85 | { 86 | return 0; 87 | } 88 | else if (vec1.IsOppositeDirection(vec2)) 89 | { 90 | return Math.PI; 91 | } 92 | var normal = default(XYZ); 93 | normal = vec1.CrossProduct(vec2).Normalize(); 94 | var angle = vec1.AngleOnPlaneTo(vec2, normal); 95 | if (angle > Math.PI) 96 | { 97 | angle = angle - 2 * Math.PI; 98 | } 99 | return angle * (normal.DotProduct(planNorm)); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Helpers/ConnectorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace 唐僧解瓦.BinLibrary.Helpers 2 | { 3 | public static class ConnectorHelper 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Helpers/CurveHelper.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System.Collections.Generic; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Helpers 5 | { 6 | public static class CurveHelper 7 | { 8 | /// 9 | /// 根据一点 和一条曲线 求得与 点到曲线连线相垂直的切线的切点 10 | /// 11 | /// 12 | /// 13 | /// 14 | public static List GetPerpendicularPoint(Curve curve, XYZ po) 15 | { 16 | var result = default(List); 17 | 18 | //if (curve is Arc arc) 19 | //{ 20 | // arc.ComputeDerivatives() 21 | //} 22 | //else if (curve is Ellipse) 23 | //{ 24 | 25 | 26 | //}else if (curve is NurbSpline) 27 | //{ 28 | 29 | //} 30 | 31 | 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Helpers/LogHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace 唐僧解瓦.BinLibrary.Helpers 5 | { 6 | public static class LogHelper 7 | { 8 | public static void LogException(Action action,string path) 9 | { 10 | try 11 | { 12 | action(); 13 | } 14 | catch (Exception e) 15 | { 16 | LogWrite(e.ToString(),path); 17 | } 18 | } 19 | 20 | public static void LogWrite(string msg, string path,bool append= false) 21 | { 22 | StreamWriter sw = new StreamWriter(path, append); 23 | sw.WriteLine(msg); 24 | sw.Close(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Helpers/TransactionHelper.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | using 唐僧解瓦.BinLibrary.Extensions; 4 | //using BinLibrary.RevitHelper; 5 | //using BinLibrary.WinHelper; 6 | 7 | namespace 唐僧解瓦.BinLibrary.Helpers 8 | { 9 | public static class TransactionHelper 10 | { 11 | public static void Invoke(this Document doc, Action action, string name = "Invoke") 12 | { 13 | #if DEBUG 14 | LogHelper.LogException(delegate 15 | { 16 | #endif 17 | using (Transaction transaction = new Transaction(doc, name)) 18 | { 19 | transaction.Start(); 20 | action(transaction); 21 | bool flag = transaction.GetStatus() == (TransactionStatus)1; 22 | if (flag) 23 | { 24 | transaction.Commit(); 25 | } 26 | } 27 | #if DEBUG 28 | }, "c:\\revitExceptionlog.txt"); 29 | #endif 30 | 31 | } 32 | public static void Invoke(this Document doc, Action action, string name = "Invoke", bool ignorefailure = true) 33 | { 34 | LogHelper.LogException(delegate 35 | { 36 | using (Transaction transaction = new Transaction(doc, name)) 37 | { 38 | transaction.Start(); 39 | 40 | if (ignorefailure) 41 | transaction.IgnoreFailure(); 42 | 43 | action(transaction); 44 | bool flag = transaction.GetStatus() == TransactionStatus.Started; 45 | if (flag) 46 | { 47 | transaction.Commit(); 48 | } 49 | } 50 | }, "c:\\revitExceptionlog.txt"); 51 | } 52 | 53 | public static void SubtranInvoke(this Document doc, Action action) 54 | { 55 | using (SubTransaction subTransaction = new SubTransaction(doc)) 56 | { 57 | subTransaction.Start(); 58 | action(subTransaction); 59 | bool flag = subTransaction.GetStatus() == (TransactionStatus)1; 60 | if (flag) 61 | { 62 | subTransaction.Commit(); 63 | } 64 | 65 | 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/Helpers/collectorHelper.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace 唐僧解瓦.BinLibrary.Helpers 7 | { 8 | public static class CollectorHelper 9 | { 10 | public static IList TCollector(this Document doc) 11 | { 12 | Type type = typeof(T); 13 | return new FilteredElementCollector(doc).OfClass(type).Cast().ToList(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /唐僧解瓦/BinLibrary/RevitHelper/RevitWindowHelper.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Windows; 2 | using System; 3 | using System.Windows.Forms; 4 | namespace 唐僧解瓦.BinLibrary.RevitHelper 5 | { 6 | public static class RevitWindowHelper 7 | { 8 | public static IntPtr GetRevitHandle() 9 | { 10 | return Autodesk.Windows.ComponentManager.ApplicationWindow; 11 | } 12 | 13 | public static Form GetRevitWindow() 14 | { 15 | var handle = ComponentManager.ApplicationWindow; 16 | var window = System.Windows.Forms.Form.FromChildHandle(handle) as Form; 17 | return window; 18 | } 19 | 20 | public static IWin32Window GetRevitWindow_win32() 21 | { 22 | var handle = ComponentManager.ApplicationWindow; 23 | var window = System.Windows.Forms.Form.FromChildHandle(handle) as IWin32Window; 24 | return window; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /唐僧解瓦/Class1.cs: -------------------------------------------------------------------------------- 1 |  2 | using Autodesk.Revit.Attributes; 3 | using Autodesk.Revit.DB; 4 | using Autodesk.Revit.UI; 5 | 6 | namespace 唐僧解瓦 7 | { 8 | [Transaction(TransactionMode.Manual)] 9 | [Regeneration(RegenerationOption.Manual)] 10 | [Journaling(JournalingMode.UsingCommandData)] 11 | class Class1 : IExternalCommand 12 | { 13 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 14 | { 15 | TaskDialog.Show("Revit", "Hello World!"); 16 | return Result.Succeeded; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /唐僧解瓦/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("唐僧解瓦")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("唐僧解瓦")] 12 | [assembly: AssemblyCopyright("Copyright © 2018")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("d21b1165-162a-4569-95c9-d2dbecdbd6c7")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /唐僧解瓦/Properties/Resource1.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace 唐僧解瓦.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resource1 { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resource1() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("唐僧解瓦.Properties.Resource1", typeof(Resource1).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Bitmap hideshow { 67 | get { 68 | object obj = ResourceManager.GetObject("hideshow", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /唐僧解瓦/Properties/Resource2.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace 唐僧解瓦.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resource2 { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resource2() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("唐僧解瓦.Properties.Resource2", typeof(Resource2).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Bitmap sj1 { 67 | get { 68 | object obj = ResourceManager.GetObject("sj1", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 75 | /// 76 | internal static System.Drawing.Bitmap sj2 { 77 | get { 78 | object obj = ResourceManager.GetObject("sj2", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /唐僧解瓦/Resources/hideshow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binbinstrong/tangsengjiewa/a745e66a6eb895a9af6ebaa4d016410987992854/唐僧解瓦/Resources/hideshow.png -------------------------------------------------------------------------------- /唐僧解瓦/Resources/sj1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binbinstrong/tangsengjiewa/a745e66a6eb895a9af6ebaa4d016410987992854/唐僧解瓦/Resources/sj1.png -------------------------------------------------------------------------------- /唐僧解瓦/Resources/sj2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binbinstrong/tangsengjiewa/a745e66a6eb895a9af6ebaa4d016410987992854/唐僧解瓦/Resources/sj2.png -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_About.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using 唐僧解瓦.BinLibrary.RevitHelper; 5 | using 唐僧解瓦.Test.UIs; 6 | 7 | namespace 唐僧解瓦.Test 8 | { 9 | /// 10 | /// 工具说明 11 | /// 12 | [Transaction(TransactionMode.Manual)] 13 | [Journaling(JournalingMode.UsingCommandData)] 14 | [Regeneration(RegenerationOption.Manual)] 15 | class Cmd_About : IExternalCommand 16 | { 17 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 18 | { 19 | var uiapp = commandData.Application; 20 | var uidoc = uiapp.ActiveUIDocument; 21 | var doc = uidoc.Document; 22 | var sel = uidoc.Selection; 23 | 24 | AboutForm form = new AboutForm(); 25 | form.Show(RevitWindowHelper.GetRevitWindow()); 26 | 27 | return Result.Succeeded; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_CalculateAreaOfShipment.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Linq; 7 | using System.Windows.Forms; 8 | using 唐僧解瓦.BinLibrary.Extensions; 9 | 10 | namespace 唐僧解瓦.Test 11 | { 12 | /// 13 | /// 计算墙的两面 面积 14 | /// 15 | [Transaction(TransactionMode.Manual)] 16 | [Journaling(JournalingMode.UsingCommandData)] 17 | [Regeneration(RegenerationOption.Manual)] 18 | class Cmd_CalculateAreaOfShipment : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | var uiapp = commandData.Application; 23 | var uidoc = uiapp.ActiveUIDocument; 24 | var doc = uidoc.Document; 25 | var sel = uidoc.Selection; 26 | 27 | var wall = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Wall)).GetElement(doc) as Wall; 28 | 29 | var facesoutRef= HostObjectUtils.GetSideFaces(wall,ShellLayerType.Exterior); 30 | 31 | var facesinRef = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior); 32 | 33 | var faceout = wall.GetGeometryObjectFromReference(facesoutRef.First()) as Face; 34 | var facein = wall.GetGeometryObjectFromReference(facesinRef.First()) as Face; 35 | 36 | var area = default(double); 37 | area += faceout.Area; 38 | area += facein.Area; 39 | area = UnitUtils.ConvertFromInternalUnits(area, DisplayUnitType.DUT_SQUARE_METERS); 40 | 41 | area = Math.Round(area, 3); 42 | 43 | MessageBox.Show(area.ToString()+"m^2"); 44 | 45 | return Result.Succeeded; 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_CalculateConcreteVolume.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Windows; 7 | using 唐僧解瓦.BinLibrary.Extensions; 8 | 9 | namespace 唐僧解瓦.Test 10 | { 11 | /// 12 | /// 计算元素体积 13 | /// 14 | [Transaction(TransactionMode.Manual)] 15 | [Journaling(JournalingMode.UsingCommandData)] 16 | [Regeneration(RegenerationOption.Manual)] 17 | class Cmd_CalculateConcreteVolume : IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | var uiapp = commandData.Application; 22 | var uidoc = uiapp.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | var sel = uidoc.Selection; 25 | 26 | var ele = sel.PickObject(ObjectType.Element).GetElement(doc); 27 | 28 | var options = new Options(); 29 | options.DetailLevel = ViewDetailLevel.Fine; 30 | 31 | var geometryelement = ele.get_Geometry(options); 32 | 33 | var volume = getVolumes(geometryelement); 34 | var volumestring = Math.Round(volume, 3).ToString(); 35 | 36 | MessageBox.Show(volumestring+"m^3"); 37 | 38 | return Result.Succeeded; 39 | } 40 | 41 | public double getVolumes(GeometryElement geoEle) 42 | { 43 | double result = default(double); 44 | 45 | var geoenu = geoEle.GetEnumerator(); 46 | while (geoenu.MoveNext()) 47 | { 48 | var currentgeo = geoenu.Current; 49 | if (currentgeo is Solid solid) 50 | { 51 | result += solid.Volume; 52 | //MessageBox.Show(result.ToString()); 53 | } 54 | else if (currentgeo is GeometryInstance geoins) 55 | { 56 | var temgeoele = geoins.SymbolGeometry; 57 | var geoenu1 = temgeoele.GetEnumerator(); 58 | while (geoenu1.MoveNext()) 59 | { 60 | //MessageBox.Show("instance is not null"); 61 | var currentgeo1 = geoenu1.Current; 62 | if (currentgeo1 is Solid solid1) 63 | { 64 | result += solid1.Volume; 65 | } 66 | } 67 | } 68 | } 69 | //单位转换 立方英尺 转 立方米 70 | result = UnitUtils.ConvertFromInternalUnits( result, DisplayUnitType.DUT_CUBIC_METERS); 71 | return result; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_CreateColumnAccordingGridIntersection.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Structure; 4 | using Autodesk.Revit.UI; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using 唐僧解瓦.BinLibrary.Helpers; 8 | using 唐僧解瓦.BinLibrary.RevitHelper; 9 | using 唐僧解瓦.Test.UIs; 10 | 11 | namespace 唐僧解瓦.Test 12 | { 13 | /// 14 | /// 在轴线交点处生成柱子 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | [Journaling(JournalingMode.UsingCommandData)] 18 | [Regeneration(RegenerationOption.Manual)] 19 | class Cmd_CreateColumnAccordingGridIntersection : IExternalCommand 20 | { 21 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 22 | { 23 | var uiapp = commandData.Application; 24 | var uidoc = uiapp.ActiveUIDocument; 25 | var doc = uidoc.Document; 26 | var sel = uidoc.Selection; 27 | var acview = doc.ActiveView; 28 | 29 | //filter target columntypes 30 | ElementFilter architectureColumnFilter = new ElementCategoryFilter(BuiltInCategory.OST_Columns); 31 | ElementFilter structuralColumnFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns); 32 | ElementFilter orfilter = new LogicalOrFilter(architectureColumnFilter,structuralColumnFilter); 33 | var collector = new FilteredElementCollector(doc); 34 | var columnstypes = collector.WhereElementIsElementType().WherePasses(orfilter).ToElements(); 35 | 36 | ColumnTypesForm typesform = ColumnTypesForm.Getinstance(columnstypes.ToList());//new ColumnTypesForm(columnstypes.ToList()); 37 | typesform.ShowDialog(RevitWindowHelper.GetRevitWindow()); 38 | 39 | //get selected familysymbol of combobox in columntypesForm 40 | var familysymbol = typesform.symbolCombo.SelectedItem as FamilySymbol; 41 | 42 | //varient for setting bottom and top /*for learners self modifing*/ 43 | var bottomlevel = default(Level); 44 | var bottomoffset = default(double); 45 | 46 | var toplevel = default(Level); 47 | var topoffset = default(double); 48 | 49 | var grids = doc.TCollector(); 50 | var points = new List(); 51 | foreach (var grid in grids) 52 | { 53 | foreach (var grid1 in grids) 54 | { 55 | if (grid.Id == grid1.Id) 56 | { 57 | continue; 58 | } 59 | var curve1 = grid.Curve; 60 | var curve2 = grid1.Curve; 61 | var res = new IntersectionResultArray(); 62 | var intersecRes = curve1.Intersect(curve2, out res); 63 | if (intersecRes != SetComparisonResult.Disjoint) 64 | { 65 | if (res != null) 66 | { 67 | points.Add(res.get_Item(0).XYZPoint); 68 | } 69 | } 70 | } 71 | } 72 | //distinct points on same location 73 | points = points.Where((m, i) => points.FindIndex(n => n.IsAlmostEqualTo(m)) == i).ToList(); 74 | 75 | //MessageBox.Show(points.Count.ToString()); 76 | //CreateColumns as intersection point 77 | 78 | TransactionGroup tsg = new TransactionGroup(doc); 79 | tsg.Start("统一创建柱子"); 80 | foreach (var point in points) 81 | { 82 | doc.Invoke(m => 83 | { 84 | if (!familysymbol.IsActive) familysymbol.Activate(); 85 | var instance = doc.Create.NewFamilyInstance(point, familysymbol, acview.GenLevel, 86 | StructuralType.NonStructural); 87 | }, "创建柱子"); 88 | } 89 | tsg.Assimilate(); 90 | return Result.Succeeded; 91 | } 92 | 93 | public XYZ Intersect_cus(Curve c, Curve c1) 94 | { 95 | XYZ result = null; 96 | IntersectionResultArray resultArray = new IntersectionResultArray(); 97 | 98 | var comparisonResult = c.Intersect(c1, out resultArray); 99 | if (comparisonResult != SetComparisonResult.Disjoint) 100 | { 101 | if (resultArray != null) 102 | result = resultArray.get_Item(0).XYZPoint; 103 | } 104 | return result; 105 | } 106 | } 107 | } 108 | 109 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_DimLine.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Plumbing; 4 | using Autodesk.Revit.UI; 5 | using Autodesk.Revit.UI.Selection; 6 | using 唐僧解瓦.BinLibrary.Extensions; 7 | using 唐僧解瓦.BinLibrary.Helpers; 8 | 9 | namespace 唐僧解瓦.Test 10 | { 11 | [Transaction(TransactionMode.Manual)] 12 | class Cmd_DimLine:IExternalCommand 13 | { 14 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 15 | { 16 | var uiapp = commandData.Application; 17 | var app = uiapp.Application; 18 | var uidoc = uiapp.ActiveUIDocument; 19 | var doc = uidoc.Document; 20 | 21 | var acview = uidoc.ActiveView; 22 | 23 | var pipe = uidoc.Selection.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)) 24 | .GetElement(doc) as Pipe; 25 | 26 | var location = pipe.Location as LocationCurve; 27 | 28 | 29 | var ref1 = location.Curve.GetEndPointReference(0); 30 | var ref2 = location.Curve.GetEndPointReference(1); 31 | 32 | 33 | var referencearray = new ReferenceArray(); 34 | referencearray.Append(ref1); 35 | referencearray.Append(ref2); 36 | 37 | var line = pipe.LocationLine(); 38 | 39 | doc.Invoke(m => 40 | { 41 | 42 | doc.Create.NewDimension(acview, line, referencearray); 43 | 44 | },"dim"); 45 | 46 | 47 | 48 | return Result.Succeeded; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_DimPipe.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Plumbing; 4 | using Autodesk.Revit.UI; 5 | using Autodesk.Revit.UI.Selection; 6 | using System.Linq; 7 | using 唐僧解瓦.BinLibrary.Extensions; 8 | using 唐僧解瓦.BinLibrary.Helpers; 9 | 10 | namespace 唐僧解瓦.Test 11 | { 12 | [Transaction(TransactionMode.Manual)] 13 | [Journaling(JournalingMode.UsingCommandData)] 14 | [Regeneration(RegenerationOption.Manual)] 15 | public class Cmd_DimPipe:IExternalCommand 16 | { 17 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 18 | { 19 | var uidoc = commandData.Application.ActiveUIDocument; 20 | var doc = uidoc.Document; 21 | var sel = uidoc.Selection; 22 | var acview = uidoc.ActiveView; 23 | 24 | var pipe = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc) as Pipe; 25 | 26 | var geoele = pipe.get_Geometry(new Options() 27 | {DetailLevel = ViewDetailLevel.Fine, ComputeReferences = true}); 28 | 29 | var line = pipe.LocationLine(); 30 | 31 | 32 | var refs = GetEndPlanRefs(geoele); 33 | 34 | doc.Invoke(m => 35 | { 36 | doc.Create.NewDimension(acview, line, refs); 37 | 38 | },"创建管道长度标注"); 39 | 40 | return Result.Succeeded; 41 | } 42 | 43 | private ReferenceArray GetEndPlanRefs(GeometryElement geoele) 44 | { 45 | var result = new ReferenceArray(); 46 | 47 | var geometrys = geoele.Cast().ToList(); 48 | 49 | foreach (GeometryObject geo in geometrys) 50 | { 51 | if (geo is Solid so) 52 | { 53 | var faces = so.Faces; 54 | foreach (var face in faces) 55 | { 56 | if (face is PlanarFace pface) 57 | { 58 | result.Append(pface.Reference); 59 | } 60 | } 61 | } 62 | else 63 | continue; 64 | } 65 | 66 | return result; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_EncodeElements.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | 5 | namespace 唐僧解瓦.Test 6 | { 7 | /// 8 | /// 元素编码 9 | /// 10 | [Transaction(TransactionMode.Manual)] 11 | [Journaling(JournalingMode.UsingCommandData)] 12 | [Regeneration(RegenerationOption.Manual)] 13 | class Cmd_EncodeElements : IExternalCommand 14 | { 15 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 16 | { 17 | var uiapp = commandData.Application; 18 | var uidoc = uiapp.ActiveUIDocument; 19 | var doc = uidoc.Document; 20 | var sel = uidoc.Selection; 21 | 22 | 23 | 24 | 25 | 26 | return Result.Succeeded; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_ExternalStorageTest.cs: -------------------------------------------------------------------------------- 1 | namespace TestForGe 2 | { 3 | //[Transaction(TransactionMode.Manual)] 4 | //class OtherTest : IExternalCommand 5 | //{ 6 | // Autodesk.Revit.DB.Document doc = null; 7 | // UIApplication uiapp = null; 8 | // UIDocument uidoc = null; 9 | // string _volume = string.Empty; 10 | // string _area = string.Empty; 11 | // object obj = new object(); 12 | 13 | // public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 14 | // { 15 | // uiapp = commandData.Application; 16 | // uidoc = commandData.Application.ActiveUIDocument; 17 | // doc = commandData.Application.ActiveUIDocument.Document; 18 | // object obj = new object(); 19 | // int a = 0; 20 | // using (Transaction trans = new Transaction(doc, "xxx")) 21 | // { 22 | // trans.Start(); 23 | // VM vm = new VM("小王", 20 /*, Sex.男*/); 24 | // Data data = new Data(); 25 | // FaceRecorder.Instance(doc, data, vm).Recorder(); 26 | // string name = FaceRecorder.Instance(doc, data, vm).Extract("Name"); 27 | // int age = FaceRecorder.Instance(doc, data, vm).Extract("Age"); 28 | // double D = FaceRecorder.Instance(doc, data, vm).Extract("D"); 29 | // float F = FaceRecorder.Instance(doc, data, vm).Extract("F"); 30 | // bool B = FaceRecorder.Instance(doc, data, vm).Extract("B"); 31 | // //string none = FaceRecorder.Instance(doc, data, vm).Extract("None"); 32 | // TaskDialog.Show("1", name.ToString()); 33 | // TaskDialog.Show("1", age.ToString()); 34 | // TaskDialog.Show("1", D.ToString()); 35 | // TaskDialog.Show("1", F.ToString()); 36 | // TaskDialog.Show("1", B.ToString()); 37 | // //TaskDialog.Show("1", none.ToString()); 38 | 39 | // //Remove(); 40 | // //Data data = new Data(); 41 | // //FaceRecorder.Instance(doc, data).Recorder(); 42 | // //double d = FaceRecorder.Instance(doc, data).Extract("a1"); 43 | // //bool d2 = FaceRecorder.Instance(doc, data).Extract("a2"); 44 | // //TaskDialog.Show("1", d2.ToString()); 45 | 46 | // trans.Commit(); 47 | // } 48 | 49 | 50 | // return Result.Succeeded; 51 | // } 52 | 53 | // public void Remove() 54 | // { 55 | // List dss = new FilteredElementCollector(doc).OfClass(typeof(DataStorage)).Cast() 56 | // .ToList(); 57 | // foreach (DataStorage item in dss) 58 | // { 59 | // doc.Delete(item.Id); 60 | // } 61 | 62 | // Schema s = Schema.Lookup(new Guid("d07f0dc5-b028-45c0-b5e7-9583353315d6")); 63 | // Schema.EraseSchemaAndAllEntities(s, true); 64 | // } 65 | 66 | //} 67 | 68 | //public class VM : BaseVM 69 | //{ 70 | // /// 71 | // /// 姓名 72 | // /// 73 | // [Record(true)] 74 | // public string Name { get; set; } 75 | 76 | // /// 77 | // /// 年龄 78 | // /// 79 | // [Record(true)] 80 | // public int Age { get; set; } 81 | 82 | // [Record(true)] public double D { get; set; } 83 | // [Record(true)] public float F { get; set; } 84 | // [Record(true)] public bool B { get; set; } 85 | 86 | 87 | // //[Record(true)] 88 | // //public Sex Sex { get; set; } 89 | 90 | // public string None { get; set; } 91 | 92 | // public VM(string name, int age /*, Sex sex*/) 93 | // { 94 | // this.Name = name; 95 | // this.Age = age; 96 | // //this.Sex = sex; 97 | // } 98 | //} 99 | } -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_FlipTee.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using System.Linq; 5 | using 唐僧解瓦.BinLibrary.Extensions; 6 | 7 | namespace 唐僧解瓦.Test 8 | { 9 | /// 10 | /// just for test 11 | /// 12 | [Transaction(TransactionMode.Manual)] 13 | class Cmd_FlipTee:IExternalCommand 14 | { 15 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 16 | { 17 | var uidoc = commandData.Application.ActiveUIDocument; 18 | var doc = uidoc.Document; 19 | var sel = uidoc.Selection; 20 | 21 | 22 | 23 | var ids = sel.GetElementIds(); 24 | 25 | if (ids.Count>1||ids.Count==0) 26 | { 27 | return Result.Cancelled; 28 | } 29 | 30 | var id = sel.GetElementIds().First(); 31 | 32 | var ele = id.GetElement(doc) as FamilyInstance; 33 | 34 | 35 | 36 | return Result.Succeeded; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_GetCuttedFace.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Linq; 6 | using 唐僧解瓦.BinLibrary.Extensions; 7 | 8 | namespace 唐僧解瓦.Test 9 | { 10 | [Transaction(TransactionMode.Manual)] 11 | [Regeneration(RegenerationOption.Manual)] 12 | [Journaling(JournalingMode.UsingCommandData)] 13 | class Cmd_GetCuttedFace:IExternalCommand 14 | { 15 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 16 | { 17 | 18 | var uiapp = commandData.Application; 19 | var uidoc = uiapp.ActiveUIDocument; 20 | var doc = uidoc.Document; 21 | var sel = uidoc.Selection; 22 | 23 | 24 | var beam = sel.PickObject(ObjectType.Element).GetElement(doc) as FamilyInstance; 25 | 26 | var getcuttingelements = JoinGeometryUtils.GetJoinedElements(doc, beam).ToList(); 27 | 28 | 29 | var beamsolid = beam.get_Geometry(new Options() {DetailLevel = ViewDetailLevel.Fine}).GetSolidOfGeometryObject(); 30 | 31 | var othersolids = getcuttingelements.Select(m => 32 | m.GetElement(doc).get_Geometry(new Options() {DetailLevel = ViewDetailLevel.Fine})); 33 | 34 | var resultsolid = default(Solid); 35 | 36 | foreach (var othersolid in othersolids) 37 | { 38 | //resultsolid = BooleanOperationsUtils.ExecuteBooleanOperation(beamsolid as Solid, othersolids.First(),BooleanOperationsType.Difference) 39 | } 40 | 41 | //doc.DisplayUnitSystem 42 | 43 | 44 | return Result.Succeeded; 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_MeasureTool.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | 5 | namespace 唐僧解瓦.Test 6 | { 7 | /// 8 | /// 测量工具 9 | /// 10 | [Transaction(TransactionMode.Manual)] 11 | [Journaling(JournalingMode.UsingCommandData)] 12 | [Regeneration(RegenerationOption.Manual)] 13 | class Cmd_MeasureTool : IExternalCommand 14 | { 15 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 16 | { 17 | var uiapp = commandData.Application; 18 | var uidoc = uiapp.ActiveUIDocument; 19 | var doc = uidoc.Document; 20 | var sel = uidoc.Selection; 21 | 22 | 23 | 24 | 25 | 26 | return Result.Succeeded; 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_MepcurveDirTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Plumbing; 10 | using Autodesk.Revit.UI; 11 | using Autodesk.Revit.UI.Selection; 12 | using 唐僧解瓦.BinLibrary.Extensions; 13 | 14 | namespace 唐僧解瓦.Test 15 | { 16 | [Transaction(TransactionMode.Manual)] 17 | class Cmd_MepcurveDirTest:IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | var uiapp = commandData.Application; 22 | var uidoc = uiapp.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | var acview = doc.ActiveView; 25 | 26 | var sel = uidoc.Selection; 27 | 28 | 29 | var pipe = 30 | sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc) as Pipe; 31 | 32 | var dir = pipe.LocationLine().Direction; 33 | 34 | 35 | MessageBox.Show(dir.ToString()); 36 | 37 | return Result.Succeeded; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_RotateTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Threading; 9 | using Autodesk.Revit.Attributes; 10 | using Autodesk.Revit.DB; 11 | using Autodesk.Revit.DB.Plumbing; 12 | using Autodesk.Revit.UI; 13 | using Autodesk.Revit.UI.Selection; 14 | using 唐僧解瓦.BinLibrary.Extensions; 15 | 16 | namespace 唐僧解瓦.Test 17 | { 18 | /// 19 | /// 旋转动画 20 | /// 21 | [Transaction(TransactionMode.Manual)] 22 | class Cmd_RotateTest : IExternalCommand 23 | { 24 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 25 | { 26 | var uiapp = commandData.Application; 27 | var uidoc = uiapp.ActiveUIDocument; 28 | var doc = uidoc.Document; 29 | var sel = uidoc.Selection; 30 | var acview = doc.ActiveView; 31 | 32 | 33 | var pipe = 34 | sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc) as Pipe; 35 | var locationline = pipe.LocationLine(); 36 | 37 | var startpo = locationline.StartPoint(); 38 | 39 | var anxisline = Line.CreateUnbound(startpo, XYZ.BasisZ); 40 | 41 | Transaction ts = new Transaction(doc, "rotate"); 42 | ts.Start(); 43 | for (int i = 0; i < 20; i++) 44 | { 45 | 46 | Thread.Sleep(200); 47 | 48 | ElementTransformUtils.RotateElement(doc, pipe.Id, anxisline, Math.PI / 120); 49 | //doc.Regenerate(); 50 | uidoc.RefreshActiveView(); 51 | 52 | } 53 | ts.Commit(); 54 | 55 | //var angle = locationline.Direction.AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ); 56 | //MessageBox.Show(angle.RadiusToDegree().ToString()); 57 | 58 | return Result.Succeeded; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_SurfaceTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.UI; 10 | using Autodesk.Revit.UI.Selection; 11 | using 唐僧解瓦.BinLibrary.Extensions; 12 | 13 | namespace 唐僧解瓦.Test 14 | { 15 | /// 16 | /// 测试楼板顶面数量 17 | /// 18 | [Transaction(TransactionMode.Manual)] 19 | class TestCmd_Surface : IExternalCommand 20 | { 21 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 22 | { 23 | 24 | var uiapp = commandData.Application; 25 | var app = uiapp.Application; 26 | var uidoc = uiapp.ActiveUIDocument; 27 | var doc = uidoc.Document; 28 | 29 | var sel = uidoc.Selection; 30 | var acview = uidoc.ActiveView; 31 | 32 | 33 | var floor = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Floor)).GetElement(doc) as Floor; 34 | 35 | var faces = HostObjectUtils.GetTopFaces(floor); 36 | 37 | MessageBox.Show(faces.Count.ToString()); 38 | 39 | 40 | 41 | return Result.Succeeded; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/Cmd_Updatefiles.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Microsoft.Win32; 5 | 6 | namespace 唐僧解瓦.Test 7 | { 8 | /// 9 | /// 文件升级 10 | /// 11 | [Transaction(TransactionMode.Manual)] 12 | [Journaling(JournalingMode.UsingCommandData)] 13 | [Regeneration(RegenerationOption.Manual)] 14 | class Cmd_Updatefiles:IExternalCommand 15 | { 16 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 17 | { 18 | var uiapp = commandData.Application; 19 | var dbapp = uiapp.Application; 20 | var uidoc = uiapp.ActiveUIDocument; 21 | var doc = uidoc.Document; 22 | var sel = uidoc.Selection; 23 | 24 | OpenFileDialog opdg = new OpenFileDialog(); 25 | opdg.Multiselect = true; 26 | opdg.Filter = "(*.rvt)|*.rvt|(*.rfa)|*.rfa"; 27 | var showResult = opdg.ShowDialog(); 28 | 29 | if (showResult == true) 30 | { 31 | var files = opdg.FileNames; 32 | 33 | foreach (string file in files) 34 | { 35 | var temdoc = dbapp.OpenDocumentFile(file); 36 | temdoc.Save(); 37 | temdoc.Close(); 38 | } 39 | } 40 | else 41 | { 42 | return Result.Cancelled; 43 | } 44 | 45 | return Result.Succeeded; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/TestCmd_AdaptiveTest.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | 5 | namespace 唐僧解瓦.Test 6 | { 7 | [Transaction(TransactionMode.Manual)] 8 | class TestCmd_AdaptiveTest : IExternalCommand 9 | { 10 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 11 | { 12 | 13 | var revitDoc = commandData.Application.ActiveUIDocument.Document; 14 | 15 | //bool modelCurveZhu = revitDoc.LoadFamilySymbol(TempFamily.FamilyPath_first, System.IO.Path.GetFileNameWithoutExtension(TempFamily.FamilyPath_first), out FamilySymbol familySymbol); //这里的族一定要有类型才行 16 | 17 | //familySymbol.Activate(); //激活族类型 18 | //famIns1 = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(revitDoc, familySymbol); //自适应族实例化 19 | //IList placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(famIns1); 20 | //point = revitDoc.GetElement(placePointIds[0]) as ReferencePoint; //自适应构件族的自适应点 21 | 22 | //point.Position = modelCurve.GeometryCurve.GetEndPoint(0); 23 | //PointLocationOnCurve pointLocationOnCurve00 = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, 0, PointOnCurveMeasureFrom.Beginning); 24 | //PointOnEdge poe00 = revitApp.Create.NewPointOnEdge(modelCurve.GeometryCurve.Reference, pointLocationOnCurve00); // 将自适应点和模型线关联起来 25 | //point.SetPointElementReference(poe00 as PointElementReference); 26 | 27 | 28 | 29 | return Result.Succeeded; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/TestCmd_FIlterRoom.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Architecture; 4 | using Autodesk.Revit.DB.ExtensibleStorage; 5 | using Autodesk.Revit.UI; 6 | using System.Linq; 7 | using System.Windows; 8 | using 唐僧解瓦.BinLibrary.Helpers; 9 | 10 | namespace 唐僧解瓦.Test 11 | { 12 | /// 13 | /// 房间过滤测试 14 | /// 15 | [Transaction(TransactionMode.Manual)] 16 | [Journaling(JournalingMode.UsingCommandData)] 17 | [Regeneration(RegenerationOption.Manual)] 18 | class TestCmd_FIlterRoom : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | var uiapp = commandData.Application; 23 | var uidoc = uiapp.ActiveUIDocument; 24 | var doc = uidoc.Document; 25 | var acview = doc.ActiveView; 26 | var sel = uidoc.Selection; 27 | 28 | var roomfilter = new RoomFilter(); 29 | var collector = new FilteredElementCollector(doc); 30 | 31 | var rooms = collector.WherePasses(roomfilter).WhereElementIsNotElementType(); 32 | 33 | foreach (var element in rooms) 34 | { 35 | var location = element.Location; 36 | } 37 | MessageBox.Show(rooms.Count().ToString()); 38 | 39 | 40 | //ParameterFilterElement filterelement = ParameterFilterElement.Create(doc,"喷淋"); 41 | 42 | var wall = doc.TCollector().First(); 43 | 44 | var schemas = Schema.ListSchemas(); 45 | 46 | foreach (var schema in schemas) 47 | { 48 | var guids = wall.GetEntitySchemaGuids(); 49 | var schemas1 = guids.Select(m => Schema.Lookup(m)); 50 | foreach (var schema1 in schemas1) 51 | { 52 | wall.DeleteEntity(schema1); 53 | } 54 | } 55 | 56 | return Result.Succeeded; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/UIs/AboutForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace 唐僧解瓦.Test.UIs 2 | { 3 | partial class AboutForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.label1 = new System.Windows.Forms.Label(); 32 | this.SuspendLayout(); 33 | // 34 | // label1 35 | // 36 | this.label1.AutoSize = true; 37 | this.label1.Location = new System.Drawing.Point(50, 34); 38 | this.label1.Name = "label1"; 39 | this.label1.Size = new System.Drawing.Size(41, 12); 40 | this.label1.TabIndex = 0; 41 | this.label1.Text = "label1"; 42 | // 43 | // AboutForm 44 | // 45 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 46 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 47 | this.ClientSize = new System.Drawing.Size(445, 268); 48 | this.Controls.Add(this.label1); 49 | this.Name = "AboutForm"; 50 | this.Text = "AboutForm"; 51 | this.Load += new System.EventHandler(this.AboutForm_Load); 52 | this.ResumeLayout(false); 53 | this.PerformLayout(); 54 | 55 | } 56 | 57 | #endregion 58 | 59 | private System.Windows.Forms.Label label1; 60 | } 61 | } -------------------------------------------------------------------------------- /唐僧解瓦/Test/UIs/AboutForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace 唐僧解瓦.Test.UIs 5 | { 6 | public partial class AboutForm : Form 7 | { 8 | public AboutForm() 9 | { 10 | InitializeComponent(); 11 | } 12 | 13 | private void AboutForm_Load(object sender, EventArgs e) 14 | { 15 | this.Text = "唐僧工具箱"; 16 | this.label1.Text = $"本工具为**内部工具\n旨在提高bim建模效率\n提升数字化建模水平。"; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /唐僧解瓦/Test/UIs/ColumnTypesForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace 唐僧解瓦.Test.UIs 2 | { 3 | partial class ColumnTypesForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.symbolCombo = new System.Windows.Forms.ComboBox(); 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.SuspendLayout(); 34 | // 35 | // symbolCombo 36 | // 37 | this.symbolCombo.FormattingEnabled = true; 38 | this.symbolCombo.Location = new System.Drawing.Point(65, 40); 39 | this.symbolCombo.Name = "symbolCombo"; 40 | this.symbolCombo.Size = new System.Drawing.Size(258, 20); 41 | this.symbolCombo.TabIndex = 0; 42 | // 43 | // label1 44 | // 45 | this.label1.AutoSize = true; 46 | this.label1.Location = new System.Drawing.Point(6, 44); 47 | this.label1.Name = "label1"; 48 | this.label1.Size = new System.Drawing.Size(65, 12); 49 | this.label1.TabIndex = 1; 50 | this.label1.Text = "柱子族类型"; 51 | // 52 | // ColumnTypesForm 53 | // 54 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 55 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 56 | this.ClientSize = new System.Drawing.Size(337, 129); 57 | this.Controls.Add(this.label1); 58 | this.Controls.Add(this.symbolCombo); 59 | this.Name = "ColumnTypesForm"; 60 | this.Text = "ColumnTypesForm"; 61 | this.Load += new System.EventHandler(this.ColumnTypesForm_Load); 62 | this.ResumeLayout(false); 63 | this.PerformLayout(); 64 | 65 | } 66 | 67 | #endregion 68 | private System.Windows.Forms.Label label1; 69 | public System.Windows.Forms.ComboBox symbolCombo; 70 | } 71 | } -------------------------------------------------------------------------------- /唐僧解瓦/Test/UIs/ColumnTypesForm.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Linq; 7 | using Form = System.Windows.Forms.Form; 8 | 9 | namespace 唐僧解瓦.Test.UIs 10 | { 11 | public partial class ColumnTypesForm : Form 12 | { 13 | private static ColumnTypesForm instance; 14 | 15 | //public static ColumnTypesForm GetInstance() 16 | //{ 17 | 18 | //} 19 | 20 | public static ColumnTypesForm Getinstance(List elements) 21 | { 22 | if (instance == null) 23 | { 24 | instance = new ColumnTypesForm(elements); 25 | } 26 | return instance; 27 | } 28 | 29 | private List symbols; 30 | public ColumnTypesForm() 31 | { 32 | InitializeComponent(); 33 | } 34 | 35 | ColumnTypesForm(List elements) 36 | { 37 | symbols = elements.Cast().ToList(); 38 | InitializeComponent(); 39 | } 40 | 41 | private void ColumnTypesForm_Load(object sender, EventArgs e) 42 | { 43 | this.symbolCombo.Items.Clear(); 44 | this.symbolCombo.DataSource = symbols; 45 | this.symbolCombo.DisplayMember = "Name"; 46 | symbolCombo.SelectedIndex = 0; 47 | } 48 | 49 | protected override void OnClosing(CancelEventArgs e) 50 | { 51 | e.Cancel = true; 52 | Hide(); 53 | //base.OnClosing(e); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /唐僧解瓦/工具/AssemblyTools1.1 无日期限制版.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binbinstrong/tangsengjiewa/a745e66a6eb895a9af6ebaa4d016410987992854/唐僧解瓦/工具/AssemblyTools1.1 无日期限制版.zip -------------------------------------------------------------------------------- /唐僧解瓦/建筑/Cmd_SetDefaultWallType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.UI; 10 | 11 | namespace 唐僧解瓦.建筑 12 | { 13 | /// 14 | /// 设置墙默认类型并创建墙 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | class Cmd_SetDefaultWallType : IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | var uiapp = commandData.Application; 22 | var uidoc = uiapp.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | var acview = doc.ActiveView; 25 | 26 | var sel = uidoc.Selection; 27 | 28 | if (!(acview is ViewPlan)) 29 | { 30 | MessageBox.Show("请在平面视图中运行此命令!"); 31 | return Result.Cancelled; 32 | } 33 | 34 | //获取目标墙类型 35 | var walltypeCollector = new FilteredElementCollector(doc); 36 | var walltype = walltypeCollector.OfClass(typeof(WallType)).Last(); 37 | 38 | //显示墙类型名称 39 | MessageBox.Show(walltype.Name); 40 | 41 | //在事务中设置墙类型,并用设置好的类型创建墙 42 | Transaction ts = new Transaction(doc, "设置墙类型,并创建墙"); 43 | ts.Start(); 44 | doc.SetDefaultElementTypeId(ElementTypeGroup.WallType, walltype.Id); 45 | 46 | doc.Regenerate(); 47 | 48 | 49 | 50 | Wall.Create(doc, Line.CreateBound(new XYZ(), new XYZ(100, 0, 0)), acview.GenLevel.Id, false); 51 | 52 | ts.Commit(); 53 | 54 | return Result.Succeeded; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /唐僧解瓦/建筑/Utils.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | using System; 3 | 4 | namespace 唐僧解瓦.建筑 5 | { 6 | class Utils 7 | { 8 | public static bool CutBeam(FamilyInstance beam, XYZ cutpoint) 9 | { 10 | var result = false; 11 | if (beam.Category.Id.IntegerValue != (int)BuiltInCategory.OST_StructuralFraming) 12 | { 13 | throw new Exception("Element being cut is not Beam!"); 14 | } 15 | 16 | var locationline = beam.Location as LocationCurve; 17 | 18 | 19 | 20 | return result; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/About/About.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/About/About.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Windows; 3 | using System.Windows.Input; 4 | 5 | namespace 唐僧解瓦.机电.About 6 | { 7 | /// 8 | /// About.xaml 的交互逻辑 9 | /// 10 | public partial class About : Window 11 | { 12 | public About() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | private void OnMouseDown(object sender, MouseButtonEventArgs e) 18 | { 19 | Process.Start("Explorer", "https://bimdp.ke.qq.com"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/About/AboutCommand.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using System.Diagnostics; 5 | using System.Windows.Forms; 6 | using System.Windows.Interop; 7 | 8 | namespace 唐僧解瓦.机电.About 9 | { 10 | [Transaction(TransactionMode.Manual)] 11 | class AboutCommand:IExternalCommand 12 | { 13 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 14 | { 15 | 16 | About about = new About(); 17 | var acwinHwd = Process.GetCurrentProcess().MainWindowHandle; 18 | var acwin = NativeWindow.FromHandle(acwinHwd); 19 | 20 | WindowInteropHelper winhelper = new WindowInteropHelper(about); 21 | winhelper.Owner = acwinHwd; 22 | about.Show(); 23 | 24 | return Result.Succeeded; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_BreakWire.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Electrical; 4 | using Autodesk.Revit.UI; 5 | using Autodesk.Revit.UI.Selection; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using 唐僧解瓦.BinLibrary.Extensions; 10 | using 唐僧解瓦.BinLibrary.Helpers; 11 | 12 | namespace 唐僧解瓦.机电 13 | { 14 | [Transaction(TransactionMode.Manual)] 15 | class Cmd_BreakWire : IExternalCommand 16 | { 17 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 18 | { 19 | 20 | UIApplication uiapp = commandData.Application; 21 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 22 | Document doc = uidoc.Document; 23 | Selection sel = uidoc.Selection; 24 | View acview = uidoc.ActiveView; 25 | 26 | 27 | 28 | while (true) 29 | { 30 | try 31 | { 32 | var eleref = sel.PickObject(ObjectType.PointOnElement, doc.GetSelectionFilter(m => true, n => n.GetElement(doc) is Wire)); 33 | var eleref1 = sel.PickObject(ObjectType.PointOnElement, doc.GetSelectionFilter(m => true, n => n.ElementId == eleref.ElementId)); 34 | 35 | var wire = eleref.GetElement(doc) as Wire; 36 | var wiretype = wire.GetTypeId().GetElement(doc) as WireType; 37 | var wiringtype = wire.WiringType; 38 | 39 | var point = eleref.GlobalPoint; 40 | var point1 = eleref1.GlobalPoint; 41 | 42 | var vertexs = new List(); 43 | var count = wire.NumberOfVertices; 44 | 45 | var pointlist1 = new List(); 46 | var pointlist2 = new List(); 47 | 48 | var resultflag = false; 49 | var flag = false; 50 | for (int i = 0; i < count - 1; i++) 51 | { 52 | var curpo = wire.GetVertex(i); 53 | var nextpo = wire.GetVertex(i + 1); 54 | 55 | var line = Line.CreateBound(curpo, nextpo); 56 | //vertexs.Add(wire.GetVertex(i)); 57 | if (!flag) 58 | { 59 | flag = point.IsOnLine(line); 60 | pointlist1.Add(curpo); 61 | } 62 | 63 | if (!resultflag) 64 | resultflag = point1.IsOnLine(line); 65 | 66 | if (flag && resultflag) 67 | { 68 | pointlist2.Add(nextpo); 69 | } 70 | } 71 | 72 | 73 | var firstLinelast = pointlist1.LastOrDefault(); 74 | var secondLinefirst = pointlist2.FirstOrDefault(); 75 | var firstpo = firstLinelast.DistanceTo(point) < firstLinelast.DistanceTo(point1) 76 | ? (point) 77 | : (point1); 78 | pointlist1.Add(firstpo); 79 | 80 | var secondpo = secondLinefirst.DistanceTo(point) < secondLinefirst.DistanceTo(point1) ? point : point1; 81 | 82 | pointlist2.Insert(0, secondpo); 83 | 84 | #region fortest 85 | 86 | //for (int i = 0; i < pointlist1.Count - 1; i++) 87 | //{ 88 | // var curpo = pointlist1.ElementAt(i);//wire.GetVertex(i); 89 | // var nextpo = pointlist1.ElementAt(i + 1);//wire.GetVertex(i + 1); 90 | // var line = Line.CreateBound(curpo, nextpo); 91 | // doc.NewLine(line); 92 | 93 | //} 94 | //for (int i = 0; i < pointlist2.Count - 1; i++) 95 | //{ 96 | // var curpo = pointlist2.ElementAt(i);//wire.GetVertex(i); 97 | // var nextpo = pointlist2.ElementAt(i + 1);//wire.GetVertex(i + 1); 98 | // var line = Line.CreateBound(curpo, nextpo); 99 | // doc.NewLine(line); 100 | //} 101 | 102 | #endregion 103 | 104 | 105 | doc.Invoke(m => 106 | { 107 | Wire.Create(doc, wiretype.Id, acview.Id, wiringtype, pointlist1, null, null); 108 | Wire.Create(doc, wiretype.Id, acview.Id, wiringtype, pointlist2, null, null); 109 | 110 | doc.Delete(wire.Id); 111 | }, "分割导线"); 112 | } 113 | catch (Exception) 114 | { 115 | 116 | break; 117 | } 118 | } 119 | 120 | return Result.Succeeded; 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_ConnectEquipMent.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Linq; 7 | using System.Windows; 8 | using Autodesk.Revit.DB.Plumbing; 9 | using 唐僧解瓦.BinLibrary.Extensions; 10 | 11 | 12 | namespace 唐僧解瓦.机电 13 | { 14 | /// 15 | /// 设备连接 (消火栓) 16 | /// 17 | [Transaction(TransactionMode.Manual)] 18 | [Regeneration(RegenerationOption.Manual)] 19 | [Journaling(JournalingMode.UsingCommandData)] 20 | class Cmd_ConnectEquipMent : IExternalCommand 21 | { 22 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 23 | { 24 | UIApplication uiapp = commandData.Application; 25 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 26 | Document doc = uidoc.Document; 27 | Selection sel = uidoc.Selection; 28 | 29 | View acview = uidoc.ActiveView; 30 | //UIView acuivew = uidoc.Activeuiview(); 31 | 32 | var familyInsRef = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is FamilyInstance)); 33 | var pipeRef = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)); 34 | 35 | var pipe = pipeRef.GetElement(doc) as Pipe; 36 | 37 | 38 | var familyIns = familyInsRef.GetElement(doc) as FamilyInstance; 39 | 40 | var equipmentCons = familyIns.MEPModel.ConnectorManager.Connectors; 41 | 42 | var firstEquipCon = equipmentCons.Cast().First(m => 43 | { 44 | return m.ConnectorType == ConnectorType.Curve || m.ConnectorType == ConnectorType.End; 45 | 46 | }); 47 | 48 | var conRadius = firstEquipCon.Radius; 49 | var condia = conRadius * 2; 50 | var origin = firstEquipCon.Origin; 51 | var conDir = firstEquipCon.CoordinateSystem.BasisZ; 52 | 53 | var pipelocationline = pipe.LocationLine(); 54 | 55 | Transaction ts = new Transaction(doc, "设备连接"); 56 | try 57 | { 58 | 59 | ts.Start(); 60 | //由连接件 水平生成一段管 61 | var firstlineEnd1 = origin; 62 | var firstlineEnd2 = origin + 200d.MetricToFeet() * conDir; 63 | var firsline = Line.CreateBound(firstlineEnd1, firstlineEnd2); 64 | var firstPipe = Pipe.Create(doc, pipe.MEPSystem.GetTypeId(), pipe.GetTypeId(), pipe.ReferenceLevel.Id, firstlineEnd1, firstlineEnd2); 65 | 66 | 67 | 68 | firstPipe.LookupParameter("直径").Set(conRadius * 2); 69 | 70 | 71 | //生成垂直管道 72 | var secondlineEnd1 = firstlineEnd2; 73 | var secondlineEnd2 = secondlineEnd1 + XYZ.BasisZ * (pipelocationline.StartPoint().Z - secondlineEnd1.Z); 74 | 75 | var secondPipe = Pipe.Create(doc, pipe.MEPSystem.GetTypeId(), pipe.GetTypeId(), pipe.ReferenceLevel.Id, secondlineEnd1, secondlineEnd2); 76 | 77 | 78 | 79 | secondPipe.LookupParameter("直径").Set(conRadius * 2); 80 | //生成第三根管道 81 | 82 | var thirdlineEnd1 = secondlineEnd2; 83 | var thirdlineEnd2 = thirdlineEnd1.ProjectToXLine(pipelocationline); 84 | 85 | var thirdPipe = Pipe.Create(doc, pipe.MEPSystem.GetTypeId(), pipe.GetTypeId(), pipe.ReferenceLevel.Id, thirdlineEnd1, thirdlineEnd2); 86 | 87 | 88 | thirdPipe.LookupParameter("直径").Set(conRadius * 2); 89 | 90 | //链接所有管道 91 | 92 | var firstpipeCons = firstPipe.ConnectorManager.Connectors; 93 | foreach (Connector item in firstpipeCons) 94 | { 95 | if (item.ConnectorType == ConnectorType.End || ConnectorType.Curve == item.ConnectorType) 96 | if (firstEquipCon.Origin.IsAlmostEqualTo(item.Origin)) 97 | { 98 | item.ConnectTo(firstEquipCon); 99 | } 100 | } 101 | 102 | firstPipe.ElbowConnect(secondPipe); 103 | secondPipe.ElbowConnect(thirdPipe); 104 | 105 | //链接剩余管道 106 | //Do it yourself!! 107 | //………… 108 | 109 | ts.Commit(); 110 | 111 | } 112 | catch (Exception e) 113 | { 114 | MessageBox.Show(e.ToString()); 115 | 116 | if (ts.GetStatus() == TransactionStatus.Started) 117 | { 118 | ts.RollBack(); 119 | } 120 | //throw; 121 | } 122 | return Result.Succeeded; 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_ElementFilterTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Structure; 10 | using Autodesk.Revit.UI; 11 | using 唐僧解瓦.BinLibrary.Extensions; 12 | using 唐僧解瓦.BinLibrary.Helpers; 13 | using 唐僧解瓦.机电.ToolUIs; 14 | 15 | namespace 唐僧解瓦.机电 16 | { 17 | [Transaction(TransactionMode.Manual)] 18 | class Cmd_ElementFilterTest : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | 23 | var uiapp = commandData.Application; 24 | var uidoc = uiapp.ActiveUIDocument; 25 | var doc = uidoc.Document; 26 | var sel = uidoc.Selection; 27 | 28 | var FilterWin = new FilterWindow(doc); 29 | 30 | FilterWin.ShowDialog(); 31 | 32 | 33 | return Result.Succeeded; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_MepCurveBreak.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Linq; 7 | using System.Windows; 8 | using 唐僧解瓦.BinLibrary.Extensions; 9 | 10 | namespace 唐僧解瓦.机电 11 | { 12 | /// 13 | /// 管线打断 14 | /// 15 | [Transaction(TransactionMode.Manual)] 16 | [Regeneration(RegenerationOption.Manual)] 17 | [Journaling(JournalingMode.UsingCommandData)] 18 | class Cmd_MepCurveBreak : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | UIApplication uiapp = commandData.Application; 23 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 24 | Document doc = uidoc.Document; 25 | Selection sel = uidoc.Selection; 26 | View acview = uidoc.ActiveView; 27 | //UIView acuivew = uidoc.Activeuiview(); 28 | var eleref = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is MEPCurve), 29 | "拾取管线打断点"); 30 | var pickpoint = eleref.GlobalPoint; 31 | var mep = eleref.GetElement(doc) as MEPCurve; 32 | var locationline = (mep.Location as LocationCurve).Curve as Line; 33 | pickpoint = pickpoint.ProjectToXLine(locationline); //ProjectToXLine 方法作用是 获取点投影到直线上的点 34 | var startpo = locationline.StartPoint(); 35 | var endpo = locationline.EndPoint(); 36 | var newstart = startpo; 37 | var newend = pickpoint; 38 | var newstart1 = pickpoint; 39 | var newend1 = endpo; 40 | 41 | Transaction ts = new Transaction(doc, "***********"); 42 | try 43 | { 44 | ts.Start(); 45 | var newmep = ElementTransformUtils.CopyElement(doc, mep.Id, new XYZ()).First().GetElement(doc) as MEPCurve; 46 | chagnemeplen(mep,newstart, newend); 47 | chagnemeplen(newmep, newstart1, newend1); 48 | ts.Commit(); 49 | } 50 | catch (Exception e) 51 | { 52 | MessageBox.Show(e.ToString()); 53 | if (ts.GetStatus() == TransactionStatus.Started) 54 | { 55 | ts.RollBack(); 56 | } 57 | //throw; 58 | } 59 | return Result.Succeeded; 60 | } 61 | void chagnemeplen(MEPCurve mep,XYZ p1,XYZ p2) 62 | { 63 | var locationline = (mep.Location as LocationCurve).Curve as Line; 64 | (mep.Location as LocationCurve).Curve = Line.CreateBound(p1, p2); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_MepCurveRank.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Windows; 9 | //using BinLibrary; 10 | //using BinLibrary.Extensions; 11 | //using BinLibrary.RevitExtension; 12 | //using BinLibrary.RevitHelper; 13 | using 唐僧解瓦.BinLibrary.Extensions; 14 | using 唐僧解瓦.BinLibrary.RevitHelper; 15 | using 唐僧解瓦.机电.ToolUIs; 16 | namespace 唐僧解瓦.机电 17 | { 18 | /// 19 | /// 管线排列 20 | /// 21 | [Transaction(TransactionMode.Manual)] 22 | [Regeneration(RegenerationOption.Manual)] 23 | [Journaling(JournalingMode.UsingCommandData)] 24 | class Cmd_MepCurveRank : IExternalCommand 25 | { 26 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 27 | { 28 | UIApplication uiapp = commandData.Application; 29 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 30 | Document doc = uidoc.Document; 31 | Selection sel = uidoc.Selection; 32 | View acview = uidoc.ActiveView; 33 | 34 | var toolwin = MepcurveRank.Instance; 35 | toolwin.helper().Owner = RevitWindowHelper.GetRevitHandle(); 36 | toolwin.Show(); //显示窗体 当点击窗体的 一键分布的时候 向revit窗体发送esc按键 结束 while循环 37 | var elelist = new List(); 38 | while (true) 39 | { 40 | try 41 | { 42 | var eleref = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is MEPCurve)); 43 | elelist.Add(eleref.ElementId); 44 | } 45 | catch (Exception e) 46 | { 47 | break; 48 | } 49 | } 50 | var dis = default(double); 51 | var parseresult = double.TryParse(toolwin.horizontalDis.Text, out dis); 52 | if (!parseresult) 53 | { 54 | MessageBox.Show("间距设置错误"); 55 | return Result.Cancelled; 56 | } 57 | //以第一根管不动 其他管 紧跟第一根管排列 58 | var meplist = elelist.Select(m => m.GetElement(doc) as MEPCurve).ToList(); 59 | var stablemep = meplist.First(); 60 | Transaction ts = new Transaction(doc, "***********"); 61 | try 62 | { 63 | ts.Start(); 64 | for (int i = 0; i < meplist.Count; i++) 65 | { 66 | if (i == 0) continue; 67 | var temdis = dis.MetricToFeet() * i; 68 | var originaldir = -getprojectdir(meplist[i], stablemep); 69 | var originaldis = getHorizontalDis(meplist[i], stablemep); 70 | var moveVec = (temdis - originaldis) * originaldir; 71 | ElementTransformUtils.MoveElement(doc, meplist[i].Id, moveVec); 72 | } 73 | ts.Commit(); 74 | } 75 | catch (Exception e) 76 | { 77 | MessageBox.Show(e.ToString()); 78 | if (ts.GetStatus() == TransactionStatus.Started) 79 | { 80 | ts.RollBack(); 81 | } 82 | //throw; 83 | } 84 | return Result.Succeeded; 85 | } 86 | /// 87 | /// 获取管线间的方向 由mep 指向 mep2 两条管线须平行 88 | /// 89 | /// 90 | /// 91 | /// 92 | XYZ getprojectdir(MEPCurve mep, MEPCurve mep2) 93 | { 94 | var line1 = mep.LocationLine(); 95 | var line2 = mep2.LocationLine(); 96 | var origin = line1.StartPoint(); 97 | var originprojectonline2 = origin.ProjectToXLine(line2); 98 | var dir = originprojectonline2 - origin; 99 | var horizontaldir = dir.xyComponent().Normalize(); 100 | return horizontaldir; 101 | } 102 | double getHorizontalDis(MEPCurve mep, MEPCurve mep2) 103 | { 104 | var line1 = mep.LocationLine(); 105 | var line2 = mep2.LocationLine(); 106 | var origin = line1.Origin; 107 | var originprojectonline2 = origin.ProjectToXLine(line2); 108 | var dir = originprojectonline2 - origin; 109 | var horizontaldir = dir.xyComponent(); 110 | return horizontaldir.GetLength(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_MepsAlongFloor.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Linq; 6 | using 唐僧解瓦.BinLibrary.Extensions; 7 | 8 | namespace 唐僧解瓦.机电 9 | { 10 | /// 11 | /// 管线随板 12 | /// 13 | [Transaction(TransactionMode.Manual)] 14 | [Journaling(JournalingMode.UsingCommandData)] 15 | [Regeneration(RegenerationOption.Manual)] 16 | class Cmd_MepsAlongFloor : IExternalCommand 17 | { 18 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 19 | { 20 | var uidoc = commandData.Application.ActiveUIDocument; 21 | var doc = uidoc.Document; 22 | var sel = uidoc.Selection; 23 | 24 | //选择管线 25 | var mep = sel.PickObject(ObjectType.Element, 26 | doc.GetSelectionFilter(m => m is MEPCurve && !(m is InsulationLiningBase)),"选择管线").GetElement(doc) as MEPCurve; 27 | 28 | //选择楼板 29 | var floor = 30 | sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Floor),"选择楼板").GetElement(doc) as Floor; 31 | 32 | var bottomfaceref = HostObjectUtils.GetBottomFaces(floor).First(); 33 | 34 | var bottomface = floor.GetGeometryObjectFromReference(bottomfaceref) as Face; 35 | 36 | var planarFace = (bottomface as PlanarFace); 37 | 38 | var planeNorm = planarFace.FaceNormal; 39 | var planeOrigin = planarFace.Origin; 40 | #if Revit2016 41 | var plane =new Plane(planeNorm, planeOrigin); 42 | #endif 43 | #if Revit2018 44 | var plane = Plane.CreateByNormalAndOrigin(planeNorm, planeOrigin); 45 | #endif 46 | 47 | Transform trs = Transform.Identity; 48 | trs.Origin = planeOrigin; 49 | trs.BasisX = planarFace.XVector; 50 | trs.BasisY = planarFace.YVector; 51 | trs.BasisZ = planeNorm; 52 | 53 | var inputboxStr = Microsoft.VisualBasic.Interaction.InputBox("输入距离楼板距离","距离","0"); 54 | 55 | var distance = default(double); 56 | 57 | var parseresult =double.TryParse(inputboxStr, out distance); 58 | if (!parseresult) return Result.Cancelled; 59 | 60 | distance = distance.MetricToFeet(); 61 | 62 | var locationline = mep.LocationLine(); 63 | var startpo = locationline.StartPoint(); 64 | var endpo = locationline.EndPoint(); 65 | 66 | var startpo_intrans = trs.Inverse.OfPoint(startpo); 67 | var endpo_intrans = trs.Inverse.OfPoint(endpo); 68 | 69 | var startpo_proj = new XYZ(startpo_intrans.X, startpo_intrans.Y,0); 70 | var endpo_proj = new XYZ(endpo_intrans.X, endpo_intrans.Y, 0); ; 71 | 72 | startpo_proj = trs.OfPoint(startpo_proj); 73 | endpo_proj = trs.OfPoint(endpo_proj); 74 | 75 | var dir = (endpo - endpo_proj).Normalize(); 76 | 77 | var newstart = startpo_proj + dir * distance; 78 | var newend = endpo_proj + dir * distance; 79 | 80 | Transaction ts = new Transaction(doc, "更改管线到楼板距离"); 81 | 82 | ts.Start(); 83 | 84 | (mep.Location as LocationCurve).Curve = Line.CreateBound(newstart, newend); 85 | 86 | ts.Commit(); 87 | 88 | return Result.Succeeded; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_MultiRotateDuctEnds.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Mechanical; 10 | using Autodesk.Revit.UI; 11 | using 唐僧解瓦.BinLibrary.Extensions; 12 | using 唐僧解瓦.BinLibrary.Helpers; 13 | 14 | namespace 唐僧解瓦.机电 15 | { 16 | /// 17 | /// 旋转指定风口 18 | /// 19 | [Transaction(TransactionMode.Manual)] 20 | class Cmd_MultiRotateDuctEnds : IExternalCommand 21 | { 22 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 23 | { 24 | 25 | var uiapp = commandData.Application; 26 | var uidoc = uiapp.ActiveUIDocument; 27 | var doc = uidoc.Document; 28 | var sel = uidoc.Selection; 29 | 30 | //1.find all ductEnds which needs ratate 31 | 32 | var collector = new FilteredElementCollector(doc); 33 | var familyinstances = collector.OfClass(typeof(FamilyInstance)).WhereElementIsNotElementType().Cast(); 34 | 35 | var ductEnds = familyinstances.Where(m => m.Symbol.FamilyName.Contains("单层百叶风口")); 36 | 37 | MessageBox.Show(ductEnds.Count().ToString()); 38 | 39 | Transaction ts = new Transaction(doc, "旋转风口"); 40 | ts.Start(); 41 | 42 | 43 | foreach (FamilyInstance fi in ductEnds) 44 | { 45 | var rotateAnxis = Line.CreateUnbound((fi.Location as LocationPoint).Point, XYZ.BasisZ); 46 | var facingOrientation = fi.FacingOrientation; 47 | 48 | var mepmodel = fi.MEPModel; 49 | if (mepmodel == null) 50 | { 51 | MessageBox.Show("mepmodel is null"); 52 | 53 | continue; 54 | } 55 | 56 | var conman = mepmodel.ConnectorManager; 57 | var connectors = conman.Connectors; 58 | //MessageBox.Show(connectors.Size.ToString()); 59 | 60 | var firstcon = connectors.Cast().Where(m => m.ConnectorType == ConnectorType.End).First(); 61 | if (firstcon == null) 62 | { 63 | MessageBox.Show("firstcon is null"); 64 | 65 | } 66 | 67 | var connectedcon = firstcon.GetConnectedCon(); 68 | //var allrefs = firstcon.AllRefs; 69 | 70 | //foreach (Connector con in allrefs) 71 | //{ 72 | // MessageBox.Show(con.ConnectorType.ToString()); 73 | 74 | // if (con.ConnectorType == ConnectorType.Curve) 75 | // MessageBox.Show("conMessage:" + con.Origin.ToString() + Environment.NewLine + 76 | // "firstconMsg:" + firstcon.Origin.ToString()); 77 | //} 78 | 79 | //MessageBox.Show("allrefs::" + allrefs.Size.ToString()); 80 | 81 | 82 | var ownerDuct = firstcon.GetConnectedCon().Owner as Duct; 83 | //if (ownerDuct == null) 84 | //{ 85 | // MessageBox.Show("Owner duct is null"); 86 | 87 | // continue; 88 | //} 89 | 90 | var ownerDuctDir = ownerDuct.LocationLine().Direction; 91 | if (!ownerDuctDir.Z.IsEqual(0)) continue; 92 | LogHelper.LogWrite(facingOrientation.ToString(), @"c:\abc.txt",true); 93 | LogHelper.LogWrite(ownerDuctDir.ToString(), @"c:\abc.txt",true); 94 | LogHelper.LogWrite("\n", @"c:\abc.txt",true); 95 | if (!facingOrientation.IsParallel(ownerDuctDir)) 96 | { 97 | //LogHelper.LogWrite(facingOrientation.ToString(), @"c:\abc.txt",true); 98 | ElementTransformUtils.RotateElement(doc, fi.Id, rotateAnxis, Math.PI / 2); 99 | } 100 | 101 | } 102 | 103 | ts.Commit(); 104 | 105 | return Result.Succeeded; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_Recursion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Plumbing; 10 | using Autodesk.Revit.UI; 11 | using Autodesk.Revit.UI.Selection; 12 | using 唐僧解瓦.BinLibrary.Extensions; 13 | 14 | namespace 唐僧解瓦.机电 15 | { 16 | [Transaction(TransactionMode.Manual)] 17 | class Cmd_Recursion : IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | 22 | var uiapp = commandData.Application; 23 | var uidoc = uiapp.ActiveUIDocument; 24 | var doc = uidoc.Document; 25 | var sel = uidoc.Selection; 26 | 27 | var pipe = 28 | sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc) as Pipe; 29 | 30 | 31 | //var closedCon = pipe.ConnectorManager.Connectors.Cast().Where(m => m.IsConnected).FirstOrDefault(); 32 | 33 | var cons = pipe.ConnectorManager.Connectors; 34 | 35 | //foreach (var con in cons) 36 | //{ 37 | // var connector = con as Connector; 38 | // var contype = connector.ConnectorType; 39 | 40 | // //var connectedcon = connector 41 | // MessageBox.Show(contype.ToString()); 42 | //} 43 | 44 | var startcon = pipe.StartCon(); 45 | 46 | var logicalcons = startcon.AllRefs.Cast().Where(m=>m.ConnectorType == ConnectorType.Logical); 47 | 48 | MessageBox.Show("startcon:"+logicalcons.Count().ToString()); 49 | 50 | var endcon = pipe.EndCon(); 51 | 52 | var logicalcons1 = endcon.AllRefs.Cast().Where(m => m.ConnectorType == ConnectorType.Logical); 53 | 54 | MessageBox.Show("endcon:" + logicalcons1.Count().ToString()); 55 | 56 | 57 | 58 | 59 | return Result.Succeeded; 60 | } 61 | 62 | public Connector GetConnectedCon1(Connector con) 63 | { 64 | var result = default(Connector); 65 | 66 | var allrefs = con.AllRefs; 67 | 68 | foreach (Connector con1 in allrefs) 69 | { 70 | var contype = con1.ConnectorType; 71 | MessageBox.Show(contype.ToString()); 72 | 73 | //bool isconnected = false; 74 | 75 | //var position = con.Origin; 76 | 77 | 78 | //MessageBox.Show(contype.ToString() + Environment.NewLine); 79 | 80 | 81 | //var position1 = con1.Origin; 82 | 83 | //isconnected = position.IsAlmostEqualTo(position1); 84 | 85 | 86 | 87 | } 88 | 89 | 90 | return result; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_SelectLinkedPipes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Events; 10 | using Autodesk.Revit.DB.Plumbing; 11 | using Autodesk.Revit.UI; 12 | using Autodesk.Revit.UI.Events; 13 | using Autodesk.Revit.UI.Selection; 14 | using 唐僧解瓦.BinLibrary.Extensions; 15 | 16 | namespace 唐僧解瓦.机电 17 | { 18 | [Transaction(TransactionMode.Manual)] 19 | [Journaling(JournalingMode.UsingCommandData)] 20 | class Cmd_SelectLinkedPipes : IExternalCommand 21 | { 22 | private static bool eventSwitch; 23 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 24 | { 25 | var uiapp = commandData.Application; 26 | var uidoc = uiapp.ActiveUIDocument; 27 | var doc = uidoc.Document; 28 | var sel = uidoc.Selection; 29 | 30 | var acview = uidoc.ActiveView; 31 | var acview1 = doc.ActiveView; 32 | 33 | //uidoc.ActiveUIView(); 34 | 35 | var uiviews = uidoc.GetOpenUIViews(); 36 | 37 | //MessageBox.Show(uiviews.Count.ToString()+Environment.NewLine+ 38 | // uiviews[0].ViewId.GetElement(doc).Name + Environment.NewLine + 39 | // uiviews[1].ViewId.GetElement(doc).Name); 40 | 41 | //uidoc.ActiveUIView().GetZoomCorners(); 42 | 43 | //var ele = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe || m is FamilyInstance)) 44 | // .GetElement(doc); 45 | 46 | //var pipe = default(Pipe); 47 | //var pipefitting = default(FamilyInstance); 48 | 49 | //if (ele is Pipe) pipe = ele as Pipe; 50 | //else if(ele is FamilyInstance) pipefitting = ele as FamilyInstance; 51 | 52 | //var connectors = pipe.ConnectorManager.Connectors.Cast(). 53 | 54 | 55 | return Result.Succeeded; 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/Cmd_changeSystem.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.DB.Plumbing; 4 | using Autodesk.Revit.UI; 5 | using System.Linq; 6 | using 唐僧解瓦.BinLibrary.Helpers; 7 | 8 | namespace 唐僧解瓦.机电 9 | { 10 | [Transaction(TransactionMode.Manual)] 11 | [Journaling(JournalingMode.UsingCommandData)] 12 | [Regeneration(RegenerationOption.Manual)] 13 | 14 | class Cmd_changeSystem : IExternalCommand 15 | { 16 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 17 | { 18 | var uiapp = commandData.Application; 19 | var dbapp = uiapp.Application; 20 | var uidoc = uiapp.ActiveUIDocument; 21 | var doc = uidoc.Document; 22 | var sel = uidoc.Selection; 23 | 24 | 25 | #region deletepipes without pipingsystem 26 | 27 | var collector = new FilteredElementCollector(doc); 28 | var pipes = collector.OfClass(typeof(Pipe)).ToElements().Cast(); 29 | 30 | var nullpipes = pipes.Where(m => m.MEPSystem == null).Select(m=>m.Id); 31 | 32 | doc.Invoke(m => { doc.Delete(nullpipes.ToList()); },"delete"); 33 | #endregion 34 | 35 | //var mepsyscollector = new FilteredElementCollector(doc); 36 | //var mepsysTypes = mepsyscollector.OfClass(typeof(MEPSystemType)).Cast().ToList(); 37 | 38 | //var ldg = mepsysTypes.Where(m => m.Name == "空调循环供水").First(); 39 | //var ldh = mepsysTypes.Where(m => m.Name == "空调循环回水").First(); 40 | 41 | //var collector = new FilteredElementCollector(doc); 42 | //var pipes = collector.OfClass(typeof(Pipe)).ToElements().Cast(); 43 | 44 | //Transaction trs = new Transaction(doc, "genggaixitong"); 45 | //trs.Start(); 46 | 47 | //int count = 0; 48 | ////MessageBox.Show(pipes.Count().ToString()); 49 | 50 | ////foreach (var pipe in pipes) 51 | //for (int i = 0; i < pipes.Count(); i++) 52 | //{ 53 | // var pipe = pipes.ElementAt(i); 54 | 55 | // //var para = pipe.LookupParameter("管段编号"); 56 | // //var paravalueStr = para.AsString(); 57 | // //if (string.IsNullOrEmpty(paravalueStr)) continue; 58 | // #region MyRegion 59 | 60 | // var mepsystem = pipe.MEPSystem; 61 | 62 | // var cons = pipe.ConnectorManager.Connectors.Cast().Where(m => 63 | // { 64 | // return m.ConnectorType == ConnectorType.End || m.ConnectorType == ConnectorType.Curve; 65 | // }).ToList(); 66 | 67 | // var connectedcons = cons.Select(m => m.GetConnectedCon()).Where(m => m != null).ToList(); 68 | 69 | // var newpipe = ElementTransformUtils.CopyElement(doc, pipe.Id, new XYZ()).First().GetElement(doc) as Pipe; 70 | 71 | // var newcons = newpipe.ConnectorManager.Connectors.Cast().Where(m => 72 | // { 73 | // return m.ConnectorType == ConnectorType.End || m.ConnectorType == ConnectorType.Curve; 74 | // }).ToList(); 75 | 76 | // foreach (var connector in newcons) 77 | // { 78 | // foreach (var connectedcon in connectedcons) 79 | // { 80 | // if (connectedcon.Origin.IsAlmostEqualTo(connector.Origin)) 81 | // { 82 | // connector.ConnectTo(connectedcon); 83 | // } 84 | // } 85 | // } 86 | 87 | // #endregion 88 | 89 | // //if (paravalueStr.Contains("LDG")) 90 | // //{ 91 | // // MessageBox.Show("ldh"); 92 | // // pipe.SetSystemType(ldg.Id); 93 | // //} 94 | // //else if (paravalueStr.Contains("LDH")) 95 | // //{ 96 | // // pipe.SetSystemType(ldh.Id); 97 | // //} 98 | // //else if (paravalueStr.Contains("LQG")) 99 | // //{ 100 | // // pipe.SetSystemType(ldg.Id); 101 | // //} 102 | // //else if (paravalueStr.Contains("LQH")) 103 | // //{ 104 | // // pipe.SetSystemType(ldh.Id); 105 | // //} 106 | 107 | //} 108 | //trs.Commit(); 109 | 110 | return Result.Succeeded; 111 | 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/ToolUIs/FilterWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using Autodesk.Revit.DB; 11 | using Autodesk.Revit.UI; 12 | using 唐僧解瓦.BinLibrary.Extensions; 13 | using Form = System.Windows.Forms.Form; 14 | 15 | namespace 唐僧解瓦.机电.ToolUIs 16 | { 17 | public partial class FilterWindow : Form 18 | { 19 | private Document _doc; 20 | 21 | 22 | public FilterWindow() 23 | { 24 | InitializeComponent(); 25 | } 26 | 27 | public FilterWindow(Document doc) 28 | { 29 | _doc = doc; 30 | InitializeComponent(); 31 | } 32 | 33 | private void FilterWindow_Load(object sender, EventArgs e) 34 | { 35 | var uidoc = new UIDocument(_doc); 36 | 37 | var sel = uidoc.Selection; 38 | 39 | var elementids = sel.GetElementIds(); 40 | 41 | var elements = elementids.Select(m => 42 | { 43 | return m.GetElement(_doc); 44 | 45 | }); 46 | 47 | //MessageBox.Show("nums :" + elements.Count().ToString()); 48 | 49 | 50 | List catelist = new List(); 51 | 52 | //listView_CateList.Clear(); 53 | 54 | foreach (Element ele in elements) 55 | { 56 | var thiscate = ele.Category; 57 | if (!catelist.Contains(thiscate)) 58 | { 59 | catelist.Add(thiscate); 60 | //MessageBox.Show(thiscate.Name); 61 | listView_CateList.Items.Add(thiscate.Name); 62 | } 63 | } 64 | 65 | //MessageBox.Show(listView_CateList.Items.Count.ToString()); 66 | 67 | } 68 | 69 | private void button_Ok_Click(object sender, EventArgs e) 70 | { 71 | var uidoc = new UIDocument(_doc); 72 | 73 | var sel = uidoc.Selection; 74 | 75 | var elementids = sel.GetElementIds(); 76 | 77 | var newElementIds = new List(); 78 | 79 | var catesChecks = listView_CateList.Items.Cast().Where(m => m.Checked); 80 | //MessageBox.Show("checks count:"+catesChecks.Count().ToString()); 81 | 82 | if (catesChecks.Count() > 0) 83 | { 84 | var cateNames = catesChecks.Select(m => m.Text); 85 | 86 | var names = string.Join("\n", cateNames); 87 | //MessageBox.Show(names); 88 | 89 | 90 | foreach (var id in elementids) 91 | { 92 | var ele = id.GetElement(_doc); 93 | var cate = ele.Category; 94 | //MessageBox.Show(cate.Name); 95 | 96 | if (cateNames.Contains(cate.Name)) 97 | { 98 | newElementIds.Add(id); 99 | } 100 | } 101 | 102 | } 103 | 104 | //MessageBox.Show(elementids.Count.ToString()); 105 | 106 | 107 | if (newElementIds.Count > 0) 108 | { 109 | sel.SetElementIds(newElementIds); 110 | //MessageBox.Show("executed!"); 111 | 112 | } 113 | 114 | this.Close(); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/ToolUIs/MepcurveRank.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /唐僧解瓦/机电/ToolUIs/ValueSettingUI.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Navigation; 15 | using System.Windows.Shapes; 16 | 17 | namespace 唐僧解瓦.机电.ToolUIs 18 | { 19 | /// 20 | /// ValueSettingUI.xaml 的交互逻辑 21 | /// 22 | public partial class ValueSettingUI : Window 23 | { 24 | public ValueSettingUI() 25 | { 26 | InitializeComponent(); 27 | } 28 | 29 | protected override void OnClosing(CancelEventArgs e) 30 | { 31 | e.Cancel = true; 32 | base.OnClosing(e); 33 | } 34 | 35 | private void Okbtn_Click(object sender, RoutedEventArgs e) 36 | { 37 | this.Hide(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /唐僧解瓦/样例项目/楼板测试.rvt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binbinstrong/tangsengjiewa/a745e66a6eb895a9af6ebaa4d016410987992854/唐僧解瓦/样例项目/楼板测试.rvt -------------------------------------------------------------------------------- /唐僧解瓦/样板/Cmd_CopyViewCropRegion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Controls; 7 | using System.Windows.Forms; 8 | using Autodesk.Revit.Attributes; 9 | using Autodesk.Revit.DB; 10 | using Autodesk.Revit.UI; 11 | using 唐僧解瓦.样板.UIs; 12 | using View = Autodesk.Revit.DB.View; 13 | 14 | namespace 唐僧解瓦.样板 15 | { 16 | /// 17 | /// 复制视图裁剪 18 | /// 19 | [Transaction(TransactionMode.Manual)] 20 | class Cmd_CopyViewCropRegion : IExternalCommand 21 | { 22 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 23 | { 24 | try 25 | { 26 | var uiapp = commandData.Application; 27 | var uidoc = uiapp.ActiveUIDocument; 28 | var doc = uidoc.Document; 29 | var acview = doc.ActiveView; 30 | 31 | var collecor = new FilteredElementCollector(doc); 32 | var planviews = collecor.OfClass(typeof(ViewPlan)).Where(m => !(m as ViewPlan).IsTemplate).OrderBy(m => m.Name); 33 | 34 | ViewSelector selector = new ViewSelector(); 35 | selector.sourceView.ItemsSource = planviews; 36 | selector.sourceView.DisplayMemberPath = "Name"; 37 | selector.sourceView.SelectedIndex = 0; 38 | 39 | selector.targetViewList.ItemsSource = planviews; 40 | selector.targetViewList.DisplayMemberPath = "Name"; 41 | 42 | selector.ShowDialog(); 43 | 44 | var sourceview = selector.sourceView.SelectionBoxItem as View; 45 | var targetviews = selector.targetViewList.SelectedItems.Cast(); 46 | 47 | Transaction ts = new Transaction(doc, "复制裁剪"); 48 | ts.Start(); 49 | 50 | var boundingbox = sourceview.CropBox; 51 | 52 | //MessageBox.Show(boundingbox.Max.ToString() + Environment.NewLine+ 53 | // boundingbox.Min.ToString()); 54 | 55 | foreach (var targetview in targetviews) 56 | { 57 | var boundingbox1 = new BoundingBoxXYZ(); 58 | boundingbox1.Transform = targetview.CropBox.Transform; 59 | boundingbox1.Max = boundingbox.Max; 60 | boundingbox1.Min = boundingbox.Min; 61 | targetview.CropBox = boundingbox1; 62 | 63 | var para_crop = targetview.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION); 64 | var para_crop_visible = targetview.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION_VISIBLE); 65 | para_crop.Set(1); 66 | para_crop_visible.Set(1); 67 | } 68 | ts.Commit(); 69 | selector.Close(); 70 | } 71 | catch (Exception e) 72 | { 73 | return Result.Cancelled; 74 | } 75 | 76 | return Result.Succeeded; 77 | } 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/Cmd_CreateNewCableTrayType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Electrical; 10 | using Autodesk.Revit.UI; 11 | using 唐僧解瓦.BinLibrary.Extensions; 12 | using 唐僧解瓦.样板.UIs; 13 | 14 | namespace 唐僧解瓦.样板 15 | { 16 | /// 17 | /// 创建桥架类型 18 | /// 19 | [Transaction(TransactionMode.Manual)] 20 | class Cmd_CreateNewCableTrayType : IExternalCommand 21 | { 22 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 23 | { 24 | var uidoc = commandData.Application.ActiveUIDocument; 25 | var doc = uidoc.Document; 26 | 27 | 28 | var collector = new FilteredElementCollector(doc); 29 | var cabletrytypes = collector.OfClass(typeof(CableTrayType)).Cast().ToList(); 30 | 31 | TypeSelector selector = new TypeSelector(); 32 | 33 | selector.typecombo.ItemsSource = cabletrytypes; 34 | selector.typecombo.DisplayMemberPath = "Name"; 35 | selector.typecombo.SelectedIndex = 0; 36 | 37 | selector.ShowDialog(); 38 | 39 | var targettypeName = selector.typeName.Text; 40 | var typeNoteText = selector.noteText.Text; 41 | if (string.IsNullOrWhiteSpace(targettypeName) || targettypeName == "新类型名称") 42 | { 43 | MessageBox.Show("名称错误"); 44 | return Result.Cancelled; 45 | } 46 | 47 | var targettype = selector.typecombo.SelectedItem as CableTrayType; 48 | 49 | var elbowpara = targettype.LookupParameter("水平弯头"); 50 | var teepara = targettype.LookupParameter("T 形三通"); 51 | var verticalElbowParaIN = targettype.LookupParameter("垂直内弯头"); 52 | var verticalElbowParaOUT = targettype.LookupParameter("垂直外弯头"); 53 | var transitionPara = targettype.LookupParameter("过渡件"); 54 | var unionPara = targettype.LookupParameter("活接头"); 55 | 56 | var elbow = elbowpara.AsElementId().GetElement(doc) as FamilySymbol; 57 | var tee = teepara.AsElementId().GetElement(doc) as FamilySymbol; 58 | 59 | var verticalElbowIn = verticalElbowParaIN.AsElementId().GetElement(doc) as FamilySymbol; 60 | var verticalElbowOUT = verticalElbowParaOUT.AsElementId().GetElement(doc) as FamilySymbol; 61 | 62 | var transition = transitionPara.AsElementId().GetElement(doc) as FamilySymbol; 63 | var union = unionPara.AsElementId().GetElement(doc) as FamilySymbol; 64 | 65 | Transaction ts = new Transaction(doc, "创建新桥架类型"); 66 | ts.Start(); 67 | //创建新的连接件类型 68 | 69 | var newelbow = elbow.Duplicate(targettypeName); 70 | var newtee = tee.Duplicate(targettypeName); 71 | var newverticalelbowIn = verticalElbowIn.Duplicate(targettypeName); 72 | var newverticalelbowOut = verticalElbowOUT.Duplicate(targettypeName); 73 | var newtransition = transition.Duplicate(targettypeName); 74 | var newunion = union.Duplicate(targettypeName); 75 | 76 | doc.Regenerate(); 77 | 78 | var newtype = targettype.Duplicate(targettypeName); 79 | 80 | var list = new List(){newelbow,newtee,newverticalelbowOut,newverticalelbowIn,newtransition,newunion,newtype}; 81 | 82 | foreach (var element in list) 83 | { 84 | var typeNotePara = element.LookupParameter("类型注释"); 85 | typeNotePara.Set(typeNoteText); 86 | } 87 | 88 | var newelbowpara = newtype.LookupParameter("水平弯头"); 89 | var newteepara = newtype.LookupParameter("T 形三通"); 90 | var newverticalElbowParaIN = newtype.LookupParameter("垂直内弯头"); 91 | var newverticalElbowParaOUT = newtype.LookupParameter("垂直外弯头"); 92 | var newtransitionPara = newtype.LookupParameter("过渡件"); 93 | var newunionPara = newtype.LookupParameter("活接头"); 94 | 95 | newelbowpara.Set(newelbow.Id); 96 | newteepara.Set(newtee.Id); 97 | newverticalElbowParaIN.Set(newverticalelbowIn.Id); 98 | newverticalElbowParaOUT.Set(newverticalelbowOut.Id); 99 | newtransitionPara.Set(newtransition.Id); 100 | newunionPara.Set(newunion.Id); 101 | 102 | ts.Commit(); 103 | 104 | selector.Close(); 105 | return Result.Succeeded; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/Cmd_HideMepCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.Attributes; 7 | using Autodesk.Revit.DB; 8 | using Autodesk.Revit.UI; 9 | using 唐僧解瓦.BinLibrary.Helpers; 10 | 11 | namespace 唐僧解瓦.样板 12 | { 13 | /// 14 | /// 隐藏管线立面中心线 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | class Cmd_HideMepCenter:IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | var uidoc = commandData.Application.ActiveUIDocument; 22 | var doc = uidoc.Document; 23 | 24 | var acview = doc.ActiveView; 25 | 26 | var ductrizedrop = Category.GetCategory(doc, BuiltInCategory.OST_DuctCurvesRiseDrop); 27 | var ductrdrop = Category.GetCategory(doc, BuiltInCategory.OST_DuctCurvesDrop); 28 | 29 | var cablerizedrop = Category.GetCategory(doc, BuiltInCategory.OST_CableTrayRiseDrop); 30 | var cabledrop = Category.GetCategory(doc, BuiltInCategory.OST_CableTrayDrop); 31 | 32 | var conduitrizedrop = Category.GetCategory(doc, BuiltInCategory.OST_ConduitRiseDrop); 33 | var conduitdrop = Category.GetCategory(doc, BuiltInCategory.OST_ConduitDrop); 34 | 35 | var piperizedrop = Category.GetCategory(doc, BuiltInCategory.OST_PipeCurvesRiseDrop); 36 | var pipedrop = Category.GetCategory(doc, BuiltInCategory.OST_PipeCurvesDrop); 37 | 38 | doc.Invoke(m => 39 | { 40 | #if Revit2016 41 | acview.SetVisibility(ductrizedrop, false); 42 | acview.SetVisibility(cablerizedrop, false); 43 | acview.SetVisibility(conduitrizedrop, false); 44 | acview.SetVisibility(piperizedrop, false); 45 | 46 | acview.SetVisibility(ductrdrop, false); 47 | acview.SetVisibility(cabledrop, false); 48 | acview.SetVisibility(conduitdrop, false); 49 | acview.SetVisibility(pipedrop, false); 50 | #endif 51 | #if Revit2018 52 | acview.SetCategoryHidden(ductrizedrop.Id,false); 53 | acview.SetCategoryHidden(cablerizedrop.Id,false); 54 | acview.SetCategoryHidden(conduitrizedrop.Id,false); 55 | acview.SetCategoryHidden(piperizedrop.Id,false); 56 | 57 | acview.SetCategoryHidden(ductrdrop.Id,false); 58 | acview.SetCategoryHidden(cabledrop.Id,false); 59 | acview.SetCategoryHidden(conduitdrop.Id,false); 60 | acview.SetCategoryHidden(pipedrop.Id,false); 61 | #endif 62 | 63 | }, "隐藏立面中心线"); 64 | 65 | 66 | return Result.Succeeded; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/Cmd_HideRevitInstance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.UI; 10 | 11 | namespace 唐僧解瓦.样板 12 | { 13 | /// 14 | /// 隐藏revit链接 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | class Cmd_HideRevitInstance:IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | var uiapp = commandData.Application; 22 | var uidoc = uiapp.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | 25 | var acview = doc.ActiveView; 26 | 27 | var collector = new FilteredElementCollector(doc); 28 | var revitlinktypes = collector.OfClass(typeof(RevitLinkType)).ToList(); 29 | 30 | 31 | Transaction ts = new Transaction(doc, "hide revitlink"); 32 | ts.Start(); 33 | acview.HideElements(revitlinktypes.Select(m => m.Id).ToList()); 34 | ts.Commit(); 35 | return Result.Succeeded; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/UIs/TypeSelector.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/UIs/TypeSelector.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace 唐僧解瓦.样板.UIs 17 | { 18 | /// 19 | /// TypeSelector.xaml 的交互逻辑 20 | /// 21 | public partial class TypeSelector : Window 22 | { 23 | public TypeSelector() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /唐僧解瓦/样板/UIs/ViewSelector.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /唐僧解瓦/注释/UIs/ResultShow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | using Autodesk.Revit.DB; 16 | using 唐僧解瓦.BinLibrary.Extensions; 17 | 18 | namespace 唐僧解瓦.注释.UIs 19 | { 20 | /// 21 | /// ResultShow.xaml 的交互逻辑 22 | /// 23 | public partial class ResultShow : Window 24 | { 25 | private static ResultShow instance; 26 | 27 | ResultShow() 28 | { 29 | InitializeComponent(); 30 | } 31 | 32 | public static ResultShow Instance 33 | { 34 | get 35 | { 36 | if (instance == null) 37 | { 38 | instance = new ResultShow(); 39 | } 40 | return instance; 41 | } 42 | } 43 | 44 | protected override void OnClosed(EventArgs e) 45 | { 46 | base.OnClosed(e); 47 | instance = null; 48 | } 49 | 50 | private void OnClicked(object sender, RoutedEventArgs e) 51 | { 52 | var ids = Cmd_LengthAccumulate.addedIds; 53 | var doc = Cmd_LengthAccumulate._doc; 54 | 55 | var modellines = ids.Select(m => m.GetElement(doc) as ModelLine); 56 | 57 | var totallen = default(double); 58 | foreach (ModelLine mline in modellines) 59 | { 60 | var para = mline.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH); 61 | var lenth = para.AsDouble().FeetToMetric(); 62 | totallen += lenth; 63 | } 64 | 65 | this.totalLen.Text = totallen.ToString(); 66 | //MessageBox.Show(ids.Count.ToString()); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_3DregionView.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Linq; 6 | using System.Windows; 7 | using 唐僧解瓦.BinLibrary.Extensions; 8 | using 唐僧解瓦.BinLibrary.Helpers; 9 | using View = Autodesk.Revit.DB.View; 10 | 11 | namespace 唐僧解瓦.通用 12 | { 13 | /// 14 | /// 局部三维视图(从当前平面视图 向上4000mm的高度上生成三维视图) 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | [Regeneration(RegenerationOption.Manual)] 18 | [Journaling(JournalingMode.UsingCommandData)] 19 | class Cmd_3DregionView : IExternalCommand 20 | { 21 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 22 | { 23 | UIApplication uiapp = commandData.Application; 24 | UIDocument uidoc = uiapp.ActiveUIDocument; 25 | Document doc = uidoc.Document; 26 | Selection sel = uidoc.Selection; 27 | 28 | var acview = doc.ActiveView; 29 | 30 | 31 | if (!(acview is ViewPlan)) 32 | { 33 | MessageBox.Show("请在平面视图使用此命令!"); 34 | return Result.Cancelled; 35 | } 36 | 37 | var collector = new FilteredElementCollector(doc); 38 | 39 | var pickedbox = sel.PickBox(PickBoxStyle.Directional); 40 | var min = pickedbox.Min; 41 | var max = pickedbox.Max; 42 | 43 | Transform transf = Transform.Identity; 44 | transf.Origin = XYZ.Zero; 45 | transf.BasisX = XYZ.BasisX; 46 | transf.BasisY = XYZ.BasisY; 47 | transf.BasisZ = XYZ.BasisZ; 48 | 49 | var newmin = new XYZ(min.X, min.Y, acview.GenLevel.Elevation); 50 | var newmax = new XYZ(max.X, max.Y, acview.GenLevel.Elevation + 4000d.MetricToFeet()); 51 | 52 | BoundingBoxXYZ box = new BoundingBoxXYZ(); 53 | box.Transform = transf; 54 | box.Min = newmin; 55 | box.Max = newmax; 56 | 57 | //var temline = Line.CreateBound(box.Min, box.Max); 58 | //doc.NewLine(temline); 59 | 60 | var view = default(View3D); 61 | doc.Invoke(m => 62 | { 63 | view = Create3DView(doc, pickedbox) as View3D; 64 | doc.Regenerate(); 65 | if (view == null) MessageBox.Show("view_3d is null"); 66 | view.SetSectionBox(box); 67 | view.LookupParameter("剖面框").Set(1); 68 | }, "创建三维视图"); 69 | 70 | uidoc.ActiveView = view; 71 | 72 | return Result.Succeeded; 73 | } 74 | 75 | public View Create3DView(Document doc, PickedBox pickedbox) 76 | { 77 | var viewfamilytypes = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) 78 | .Cast().Where(m => m.ViewFamily == ViewFamily.ThreeDimensional); 79 | var targetviewfamilytypeId = viewfamilytypes.First().Id; 80 | var result = View3D.CreateIsometric(doc, targetviewfamilytypeId); 81 | return result; 82 | } 83 | 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_CategoryFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.Attributes; 7 | using Autodesk.Revit.DB; 8 | using Autodesk.Revit.UI; 9 | 10 | namespace 唐僧解瓦.通用 11 | { 12 | [Transaction(TransactionMode.Manual)] 13 | class Cmd_CategoryFilter : IExternalCommand 14 | { 15 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 16 | { 17 | var uiapp = commandData.Application; 18 | var uidoc = uiapp.ActiveUIDocument; 19 | var doc = uidoc.Document; 20 | var sel = uidoc.Selection; 21 | 22 | 23 | //方法一 24 | var categories = doc.Settings.Categories; 25 | 26 | var categoryFilters = new List(); 27 | 28 | foreach (Category cate in categories) 29 | { 30 | var categoryType = cate.CategoryType; 31 | if (categoryType == CategoryType.Model) 32 | { 33 | var categoryfilter = new ElementCategoryFilter(cate.Id); 34 | categoryFilters.Add(categoryfilter); 35 | } 36 | } 37 | 38 | var logicalOrFilter = new LogicalOrFilter(categoryFilters); 39 | 40 | 41 | var collector = new FilteredElementCollector(doc); 42 | 43 | 44 | var targetCollector = collector.WherePasses(logicalOrFilter); 45 | 46 | //collector.WhereElementIsNotElementType().Where(m => m.Category.CategoryType == CategoryType.Model); 47 | 48 | 49 | //方法二 50 | 51 | foreach (BuiltInCategory builtInid in Enum.GetValues(typeof(BuiltInCategory))) 52 | { 53 | var cate = Category.GetCategory(doc, builtInid); 54 | 55 | var categoryType = cate.CategoryType; 56 | if (categoryType == CategoryType.Model) 57 | { 58 | ////// 59 | } 60 | } 61 | 62 | 63 | 64 | 65 | return Result.Succeeded; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_ChangeBackGroundColor.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using System.Windows.Forms; 5 | using 唐僧解瓦.BinLibrary.Extensions; 6 | using Color = System.Drawing.Color; 7 | 8 | namespace 唐僧解瓦.通用 9 | { 10 | /// 11 | /// 更改视图背景颜色 12 | /// 13 | [Transaction(TransactionMode.Manual)] 14 | [Journaling(JournalingMode.UsingCommandData)] 15 | [Regeneration(RegenerationOption.Manual)] 16 | public class Cmd_ChangeBackGroundColor : IExternalCommand 17 | { 18 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 19 | { 20 | var uiapp = commandData.Application; 21 | var uidoc = uiapp.ActiveUIDocument; 22 | var doc = uidoc.Document; 23 | var sel = uidoc.Selection; 24 | 25 | ColorDialog colordialog = new ColorDialog(); 26 | var colorResult = colordialog.ShowDialog(); 27 | var targetColor = default(Color); 28 | if (colorResult == DialogResult.OK) 29 | { 30 | targetColor = colordialog.Color; 31 | } 32 | else 33 | { 34 | return Result.Cancelled; 35 | } 36 | 37 | uiapp.Application.BackgroundColor = targetColor.ToRvtColor();// uiapp.Application.BackgroundColor.InversColor(); 38 | 39 | return Result.Succeeded; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_ChangeType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.Attributes; 7 | using Autodesk.Revit.DB; 8 | using Autodesk.Revit.DB.Plumbing; 9 | using Autodesk.Revit.UI; 10 | using Autodesk.Revit.UI.Selection; 11 | using 唐僧解瓦.BinLibrary.Extensions; 12 | using 唐僧解瓦.BinLibrary.Helpers; 13 | 14 | namespace 唐僧解瓦.通用 15 | { 16 | /// 17 | /// 修改元素类型 18 | /// 19 | [Transaction(TransactionMode.Manual)] 20 | [Regeneration(RegenerationOption.Manual)] 21 | class Cmd_ChangeType : IExternalCommand 22 | { 23 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 24 | { 25 | var uidoc = commandData.Application.ActiveUIDocument; 26 | var doc = uidoc.Document; 27 | var sel = uidoc.Selection; 28 | 29 | var acview = uidoc.ActiveView; 30 | 31 | var firstEle = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc); 32 | 33 | var secondEle = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Pipe)).GetElement(doc); 34 | 35 | var collector = new FilteredElementCollector(doc); 36 | var pipecollector = collector.OfClass(typeof(Pipe)); 37 | 38 | var targets = pipecollector.Where(m => m.GetTypeId().IntegerValue == firstEle.GetTypeId().IntegerValue); 39 | 40 | Transaction ts = new Transaction(doc, "修改类型"); 41 | ts.Start(); 42 | foreach (var element in targets) 43 | { 44 | element.ChangeTypeId(secondEle.GetTypeId()); 45 | } 46 | ts.Commit(); 47 | 48 | return Result.Succeeded; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_ElementTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.DB.Mechanical; 10 | using Autodesk.Revit.UI; 11 | using Autodesk.Revit.UI.Selection; 12 | using 唐僧解瓦.BinLibrary.Extensions; 13 | 14 | namespace 唐僧解瓦.通用 15 | { 16 | [Transaction(TransactionMode.Manual)] 17 | //[Journaling(JournalingMode.UsingCommandData)] 18 | //[Regeneration(RegenerationOption.Manual)] 19 | class Cmd_ElementTest:IExternalCommand 20 | { 21 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 22 | { 23 | var uiapp = commandData.Application; 24 | var uidoc = uiapp.ActiveUIDocument; 25 | var doc = uidoc.Document; 26 | 27 | var sel = uidoc.Selection; 28 | 29 | 30 | 31 | //var refence = sel.PickObject(ObjectType.Element, 32 | // doc.GetSelectionFilter(m => m.Category.CategoryType == CategoryType.Model || m.Category.CategoryType == CategoryType.Internal)); 33 | 34 | //var element = doc.GetElement(refence); 35 | 36 | //var name = element.Name; 37 | //var id = element.Id; 38 | 39 | //var category = element.Category; 40 | 41 | //var familyName = element.LookupParameter("族").AsValueString(); 42 | 43 | //MessageBox.Show("name:" + name + Environment.NewLine + 44 | // "id:" + id + Environment.NewLine + 45 | // "category:" + category.Name + Environment.NewLine + 46 | // "familyName:" + familyName); 47 | 48 | 49 | var collector = new FilteredElementCollector(doc); 50 | 51 | var ductCollector = collector.OfClass(typeof(Duct)); 52 | 53 | 54 | var ductlist = new List(); 55 | 56 | foreach (Duct duct in ductCollector) 57 | { 58 | var lenth = duct.LocationLine().Length.FeetToMetric(); 59 | 60 | if (lenth < 200) 61 | { 62 | ductlist.Add(duct); 63 | } 64 | 65 | } 66 | 67 | sel.SetElementIds(ductlist.Select(m => m.Id).ToList()); 68 | 69 | 70 | return Result.Succeeded; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_Floor3D.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using 唐僧解瓦.BinLibrary.Helpers; 8 | using 唐僧解瓦.通用.UIs; 9 | 10 | namespace 唐僧解瓦.通用 11 | { 12 | /// 13 | /// 楼层三维 14 | /// 15 | [Transaction(TransactionMode.Manual)] 16 | [Regeneration(RegenerationOption.Manual)] 17 | [Journaling(JournalingMode.UsingCommandData)] 18 | class Cmd_Floor3D : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | UIApplication uiapp = commandData.Application; 23 | UIDocument uidoc = uiapp.ActiveUIDocument; 24 | Document doc = uidoc.Document; 25 | Selection sel = uidoc.Selection; 26 | var acview = doc.ActiveView; 27 | 28 | var viewfamilytypes = doc.TCollector(); 29 | var viewplanfamilytype = viewfamilytypes.Where(m => m.ViewFamily == ViewFamily.FloorPlan).First(); 30 | var view3Dfamilytype = viewfamilytypes.Where(m => m.ViewFamily == ViewFamily.ThreeDimensional).First(); 31 | 32 | var levels = doc.TCollector(); 33 | 34 | FloorSelector fsui = FloorSelector.Instance; 35 | fsui.FloorBox.ItemsSource = levels; 36 | fsui.FloorBox.DisplayMemberPath = "Name"; 37 | fsui.FloorBox.SelectedIndex = 0; 38 | fsui.ShowDialog(); 39 | 40 | var targetfloor = fsui.FloorBox.SelectionBoxItem as Level; 41 | var upperfloor = levels.Where(m => m.Elevation > targetfloor.Elevation)?.OrderBy(m => m.Elevation)?.FirstOrDefault(); 42 | 43 | var categories = doc.Settings.Categories; 44 | var modelcategories = categories.Cast().Where(m => m.CategoryType == CategoryType.Model).ToList(); 45 | 46 | var filterslist = new List(); 47 | foreach (var modelcategory in modelcategories) 48 | { 49 | var categoryfilter = new ElementCategoryFilter(modelcategory.Id); 50 | filterslist.Add(categoryfilter); 51 | } 52 | var logicOrFilter = new LogicalOrFilter(filterslist); 53 | var collector = new FilteredElementCollector(doc); 54 | var modelelements = collector.WherePasses(logicOrFilter).WhereElementIsNotElementType().Where(m => m.Category.CategoryType == CategoryType.Model); 55 | 56 | var modelelementsids = modelelements.Select(m => m.Id).ToList(); 57 | 58 | var temboundingbox = default(BoundingBoxXYZ); 59 | 60 | Transaction temtran = new Transaction(doc, "temtransaction"); 61 | temtran.Start(); 62 | var temgroup = doc.Create.NewGroup(modelelementsids); 63 | var temview = ViewPlan.Create(doc, viewplanfamilytype.Id, targetfloor.Id); 64 | temboundingbox = temgroup.get_BoundingBox(temview); 65 | temtran.RollBack(); 66 | 67 | var zMin = targetfloor.Elevation; 68 | var zMax = upperfloor?.Elevation ?? temboundingbox.Max.Z; 69 | 70 | var oldmin = temboundingbox.Min; 71 | var oldmax = temboundingbox.Max; 72 | 73 | BoundingBoxXYZ newbox = new BoundingBoxXYZ(); 74 | newbox.Min = new XYZ(oldmin.X, oldmin.Y, zMin); 75 | newbox.Max = new XYZ(oldmax.X, oldmax.Y, zMax); 76 | var new3dview = default(View3D); 77 | 78 | doc.Invoke(m => 79 | { 80 | new3dview = View3D.CreateIsometric(doc, view3Dfamilytype.Id); 81 | new3dview.SetSectionBox(newbox); 82 | },"楼层三维"); 83 | 84 | uidoc.ActiveView = new3dview; 85 | 86 | return Result.Succeeded; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_HideElementInfamilyDoc.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Collections.ObjectModel; 7 | 8 | 9 | namespace 唐僧解瓦.通用 10 | { 11 | /// 12 | /// 隐藏族文档中的元素 13 | /// 14 | [Transaction(TransactionMode.Manual)] 15 | [Regeneration(RegenerationOption.Manual)] 16 | [Journaling(JournalingMode.UsingCommandData)] 17 | 18 | class Cmd_HideElementInfamilyDoc : IExternalCommand 19 | { 20 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 21 | { 22 | UIApplication uiapp = commandData.Application; 23 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 24 | Document doc = uidoc.Document; 25 | Selection sel = uidoc.Selection; 26 | 27 | View acview = uidoc.ActiveView; 28 | //UIView acuivew = uidoc.Activeuiview(); 29 | 30 | var ele = sel.PickObject(ObjectType.Element); 31 | 32 | Transaction ts = new Transaction(doc, "***********"); 33 | try 34 | { 35 | ts.Start(); 36 | 37 | acview.HideElements(new Collection() {ele.ElementId}); 38 | 39 | ts.Commit(); 40 | } 41 | catch (Exception) 42 | { 43 | if (ts.GetStatus() == TransactionStatus.Started) 44 | { 45 | ts.RollBack(); 46 | } 47 | //throw; 48 | } 49 | return Result.Succeeded; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_MepLineUpDownVisble.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Autodesk.Revit.Attributes; 8 | using Autodesk.Revit.DB; 9 | using Autodesk.Revit.UI; 10 | using 唐僧解瓦.BinLibrary.Helpers; 11 | namespace 唐僧解瓦.通用 12 | { 13 | [Transaction(TransactionMode.Manual)] 14 | [Regeneration(RegenerationOption.Manual)] 15 | class Cmd_MepLineUpDownVisble : IExternalCommand 16 | { 17 | public static bool Switch = false; 18 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 19 | { 20 | var uiapp = commandData.Application; 21 | var app = uiapp.Application; 22 | var uidoc = uiapp.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | var sel = uidoc.Selection; 25 | var cate_ducts = Category.GetCategory(doc, BuiltInCategory.OST_DuctCurves); 26 | var cate_pipes = Category.GetCategory(doc, BuiltInCategory.OST_PipeCurves); 27 | var cate_cabletras = Category.GetCategory(doc, BuiltInCategory.OST_CableTray); 28 | //var subCates1 = cate_ducts.SubCategories. 29 | var cate1 = BuiltInCategory.OST_DuctCurvesRiseDrop; 30 | var cate2 = BuiltInCategory.OST_DuctCurvesDrop; 31 | var cate3 = BuiltInCategory.OST_PipeCurvesRiseDrop; 32 | var cate4 = BuiltInCategory.OST_PipeCurvesDrop; 33 | var cate5 = BuiltInCategory.OST_CableTrayDrop; 34 | var cate6 = BuiltInCategory.OST_CableTrayRiseDrop; 35 | 36 | var cateList = new List(); 37 | cateList.Add(Category.GetCategory(doc, cate1)); 38 | cateList.Add(Category.GetCategory(doc, cate2)); 39 | cateList.Add(Category.GetCategory(doc, cate3)); 40 | cateList.Add(Category.GetCategory(doc, cate4)); 41 | cateList.Add(Category.GetCategory(doc, cate5)); 42 | cateList.Add(Category.GetCategory(doc, cate6)); 43 | var acview = uidoc.ActiveView; 44 | Switch = acview.GetCategoryHidden(cateList.ElementAt(0).Id); 45 | if (!Switch) 46 | { 47 | MessageBox.Show("已关闭"); 48 | } 49 | else 50 | { 51 | MessageBox.Show("已开启"); 52 | } 53 | doc.Invoke(m => 54 | { 55 | foreach (Category category in cateList) 56 | { 57 | if (Switch) 58 | acview.SetCategoryHidden(category.Id, false); 59 | else 60 | acview.SetCategoryHidden(category.Id, true); 61 | } 62 | }, "隐藏/显示升降符号", true); 63 | return Result.Succeeded; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_MultipleLinkFile.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using Microsoft.Win32; 6 | using 唐僧解瓦.BinLibrary.Helpers; 7 | 8 | namespace 唐僧解瓦.通用 9 | { 10 | /// 11 | /// 批量链接 12 | /// 13 | [Transaction(TransactionMode.Manual)] 14 | [Regeneration(RegenerationOption.Manual)] 15 | [Journaling(JournalingMode.UsingCommandData)] 16 | 17 | class Cmd_MultipleLinkFile : IExternalCommand 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | UIApplication uiapp = commandData.Application; 22 | UIDocument uidoc = uiapp.ActiveUIDocument; 23 | Document doc = uidoc.Document; 24 | Selection sel = uidoc.Selection; 25 | 26 | var acview = doc.ActiveView; 27 | // pop up dialog let users to select files 28 | // 未完待续 29 | 30 | var opdg = new OpenFileDialog(); 31 | opdg.Multiselect = true; 32 | opdg.Filter = "(*.rvt)|*.rvt"; 33 | var dialogresult = opdg.ShowDialog(); 34 | 35 | var count = opdg.FileNames.Length; 36 | string[] files = new string[count]; 37 | 38 | if (dialogresult == true) 39 | { 40 | files = opdg.FileNames; 41 | } 42 | doc.Invoke(m => 43 | { 44 | foreach (var file in files) 45 | { 46 | var linktypeId = CreateRevitLink(doc, file); 47 | CreateLinkInstances(doc, linktypeId); 48 | } 49 | }, "批量链接"); 50 | 51 | return Result.Succeeded; 52 | } 53 | 54 | public ElementId CreateRevitLink(Document doc, string pathName) 55 | { 56 | FilePath path = new FilePath(pathName); 57 | RevitLinkOptions options = new RevitLinkOptions(false); 58 | // Create new revit link storing absolute path to file 59 | #if Revit2018 60 | LinkLoadResult result = RevitLinkType.Create(doc, path, options); 61 | return (result.ElementId); 62 | #endif 63 | #if Revit2016 64 | return null; 65 | #endif 66 | } 67 | 68 | public void CreateLinkInstances(Document doc, ElementId linkTypeId) 69 | { 70 | // Create revit link instance at origin 71 | //RevitLinkInstance.Create(doc, linkTypeId); 72 | RevitLinkInstance instance2 = RevitLinkInstance.Create(doc, linkTypeId); 73 | // Offset second instance by 100 feet 74 | //Location location = instance2.Location; 75 | //location.Move(new XYZ(0, -100, 0)); 76 | } 77 | 78 | 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_PickBox3D.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Linq; 6 | using 唐僧解瓦.BinLibrary.Extensions; 7 | using 唐僧解瓦.BinLibrary.Helpers; 8 | 9 | namespace 唐僧解瓦.通用 10 | { 11 | /// 12 | /// 框选三维 13 | /// 14 | [Transaction(TransactionMode.Manual)] 15 | [Journaling(JournalingMode.UsingCommandData)] 16 | [Regeneration(RegenerationOption.Manual)] 17 | class Cmd_PickBox3D:IExternalCommand ,IExternalCommandAvailability 18 | { 19 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 20 | { 21 | UIApplication uiapp = commandData.Application; 22 | UIDocument uidoc = uiapp.ActiveUIDocument; 23 | Document doc = uidoc.Document; 24 | Selection sel = uidoc.Selection; 25 | 26 | var acview = doc.ActiveView; 27 | 28 | var viewfamilytype = doc.TCollector() 29 | .Where(m => m.ViewFamily == ViewFamily.ThreeDimensional).First(); 30 | 31 | var elementRefs = sel.PickObjects(ObjectType.Element, 32 | doc.GetSelectionFilter(m =>{ return m.Category.CategoryType == CategoryType.Model; })); 33 | var eles = elementRefs.Select(m => m.ElementId.GetElement(doc)); 34 | var eleids = elementRefs.Select(m => m.ElementId).ToList(); 35 | 36 | var tembox = default(BoundingBoxXYZ); 37 | 38 | Transaction temtran = new Transaction(doc, "temTran"); 39 | temtran.Start(); 40 | var group = doc.Create.NewGroup(eleids); 41 | tembox = group.get_BoundingBox(acview); 42 | temtran.RollBack(); 43 | 44 | var newAcview = default(View); 45 | doc.Invoke(m => 46 | { 47 | var _3dview = View3D.CreateIsometric(doc, viewfamilytype.Id); 48 | _3dview.SetSectionBox(tembox); 49 | newAcview = _3dview; 50 | }, "框选三维"); 51 | 52 | uidoc.ActiveView = newAcview; 53 | return Result.Succeeded; 54 | } 55 | 56 | public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) 57 | { 58 | //throw new NotImplementedException(); 59 | 60 | return true; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_ReverseBackGroundColor.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using 唐僧解瓦.BinLibrary.Extensions; 5 | 6 | namespace 唐僧解瓦.通用 7 | { 8 | /// 9 | /// 反转视图背景颜色 10 | /// 11 | [Transaction(TransactionMode.Manual)] 12 | [Journaling(JournalingMode.UsingCommandData)] 13 | [Regeneration(RegenerationOption.Manual)] 14 | public class Cmd_ReverseBackGroundColor : IExternalCommand 15 | { 16 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 17 | { 18 | var uiapp = commandData.Application; 19 | var uidoc = uiapp.ActiveUIDocument; 20 | var doc = uidoc.Document; 21 | var sel = uidoc.Selection; 22 | 23 | uiapp.Application.BackgroundColor = uiapp.Application.BackgroundColor.InversColor(); 24 | 25 | return Result.Succeeded; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_UnhideElementsInFamlyDoc.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Windows; 9 | using 唐僧解瓦.BinLibrary.Helpers; 10 | 11 | namespace 唐僧解瓦.通用 12 | { 13 | /// 14 | /// 隐藏族中元素 15 | /// 16 | [Transaction(TransactionMode.Manual)] 17 | [Regeneration(RegenerationOption.Manual)] 18 | [Journaling(JournalingMode.UsingCommandData)] 19 | 20 | class Cmd_UnideElementInFamilyDoc : IExternalCommand 21 | { 22 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 23 | { 24 | UIApplication uiapp = commandData.Application; 25 | UIDocument uidoc = commandData.Application.ActiveUIDocument; 26 | Document doc = uidoc.Document; 27 | Selection sel = uidoc.Selection; 28 | 29 | if (!doc.IsFamilyDocument) 30 | { 31 | MessageBox.Show("当前不是族文档,请到族文档使用该命令"); 32 | } 33 | 34 | var views = doc.TCollector().Where(m=>!(m.IsTemplate));//doc.ViewCollector(); 35 | 36 | FilteredElementCollector collector = new FilteredElementCollector(doc); 37 | 38 | var elelist = collector.WhereElementIsNotElementType(); 39 | 40 | Transaction ts = new Transaction(doc, "显示族元素"); 41 | try 42 | { 43 | ts.Start(); 44 | foreach (var view in views) 45 | { 46 | if (view is ViewPlan || view is ViewSection || view is View3D) 47 | //ele.IsHidden(acview); 48 | //acview.HideElements(new List(){ele.Id}); 49 | foreach (var item in elelist) 50 | { 51 | if (item.IsHidden(view)) 52 | { 53 | view.UnhideElements(new List() { item.Id }); 54 | } 55 | } 56 | } 57 | ts.Commit(); 58 | } 59 | catch (Exception) 60 | { 61 | if (ts.GetStatus() == TransactionStatus.Started) 62 | { 63 | ts.RollBack(); 64 | } 65 | //throw; 66 | } 67 | return Result.Succeeded; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/Cmd_UpdateFiles.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Microsoft.Win32; 5 | using System.ComponentModel; 6 | 7 | namespace 唐僧解瓦.通用 8 | { 9 | /// 10 | /// 升级文件 11 | /// 12 | [Transaction(TransactionMode.Manual)] 13 | [Journaling(JournalingMode.UsingCommandData)] 14 | [Regeneration(RegenerationOption.Manual)] 15 | class Cmd_UpdateFiles : IExternalCommand 16 | { 17 | private string folderpath = default(string); 18 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 19 | { 20 | var uiapp = commandData.Application; 21 | var dbapp = uiapp.Application; 22 | var uidoc = commandData.Application.ActiveUIDocument; 23 | var doc = uidoc.Document; 24 | var sel = uidoc.Selection; 25 | var acview = doc.ActiveView; 26 | 27 | var filepath = default(string); 28 | 29 | OpenFileDialog opdg = new OpenFileDialog(); 30 | //opdg.Filter = "(rvtfiles)|*.rvt()|*.rfa"; 31 | opdg.Filter = "(*.rfa)|*.rfa|(*.rvt)|*.rvt"; 32 | 33 | opdg.Multiselect = true; 34 | opdg.FileOk += OnfileOk; 35 | var dialogresult = opdg.ShowDialog(); 36 | 37 | var count = opdg.FileNames.Length; 38 | string[] files = new string[count]; 39 | 40 | if (dialogresult == true) 41 | { 42 | files = opdg.FileNames; 43 | } 44 | foreach (var file in files) 45 | { 46 | var temdoc = dbapp.OpenDocumentFile(file); 47 | temdoc.Save(); 48 | temdoc.Close(); 49 | } 50 | return Result.Succeeded; 51 | } 52 | private void OnfileOk(object sender, CancelEventArgs e) 53 | { 54 | (sender as OpenFileDialog).RestoreDirectory = true; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/FloorSelector.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/FloorSelector.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | 4 | namespace 唐僧解瓦.通用.UIs 5 | { 6 | /// 7 | /// FloorSelector.xaml 的交互逻辑 8 | /// 9 | public partial class FloorSelector : Window 10 | { 11 | private static FloorSelector instance; 12 | 13 | public static FloorSelector Instance 14 | { 15 | get 16 | { 17 | if (instance == null) 18 | { 19 | instance =new FloorSelector(); 20 | } 21 | return instance; 22 | } 23 | } 24 | private FloorSelector() 25 | { 26 | InitializeComponent(); 27 | } 28 | 29 | protected override void OnClosing(CancelEventArgs e) 30 | { 31 | e.Cancel = true; 32 | this.Hide(); 33 | //base.OnClosing(e); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/FloorTypeSelector.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/FloorTypeSelector.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | 4 | namespace 唐僧解瓦.通用.UIs 5 | { 6 | /// 7 | /// FloorTypeSelector.xaml 的交互逻辑 8 | /// 9 | public partial class FloorTypeSelector : Window 10 | { 11 | public FloorTypeSelector() 12 | { 13 | InitializeComponent(); 14 | } 15 | 16 | private static FloorTypeSelector instance; 17 | 18 | public static FloorTypeSelector Instance 19 | { 20 | get 21 | { 22 | if (instance == null) 23 | { 24 | instance = new FloorTypeSelector(); 25 | } 26 | return instance; 27 | } 28 | } 29 | 30 | 31 | 32 | protected override void OnClosing(CancelEventArgs e) 33 | { 34 | e.Cancel = true; 35 | this.Hide(); 36 | //base.OnClosing(e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/ViewSemutaneousSelector.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /唐僧解瓦/通用/UIs/ViewSemutaneousSelector.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | 4 | namespace 唐僧解瓦.通用.UIs 5 | { 6 | /// 7 | /// ViewSemutaneousSelector.xaml 的交互逻辑 8 | /// 9 | public partial class ViewSemutaneousSelector : Window 10 | { 11 | private static ViewSemutaneousSelector instance; 12 | 13 | public static ViewSemutaneousSelector Instance 14 | { 15 | get 16 | { 17 | if (instance == null) 18 | { 19 | instance= new ViewSemutaneousSelector(); 20 | } 21 | 22 | return instance; 23 | } 24 | } 25 | 26 | public ViewSemutaneousSelector() 27 | { 28 | InitializeComponent(); 29 | } 30 | 31 | protected override void OnClosing(CancelEventArgs e) 32 | { 33 | e.Cancel = true; 34 | this.Hide(); 35 | //base.OnClosing(e); 36 | } 37 | 38 | private void Clicked(object sender, RoutedEventArgs e) 39 | { 40 | this.Hide(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /唐僧解瓦/高级/Cmd_CallSystemCmd.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.Attributes; 2 | using Autodesk.Revit.DB; 3 | using Autodesk.Revit.UI; 4 | using Autodesk.Revit.UI.Selection; 5 | using System.Collections.Generic; 6 | using UIFrameworkServices; 7 | 8 | namespace 唐僧解瓦.高级 9 | { 10 | /// 11 | /// 调用revit 本身命令 模拟手动操作 打断剖切符号 12 | /// 13 | [Transaction(TransactionMode.Manual)] 14 | class Cmd_CallSystemCmd:IExternalCommand 15 | { 16 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 17 | { 18 | 19 | var uidoc = commandData.Application.ActiveUIDocument; 20 | 21 | var sel = uidoc.Selection; 22 | var doc = uidoc.Document; 23 | 24 | var acview = doc.ActiveView as ViewSection; 25 | 26 | 27 | var ele = sel.PickObject(ObjectType.Element); 28 | 29 | sel.SetElementIds(new List() {ele.ElementId}); //选中剖面符号 30 | 31 | CommandHandlerService.invokeCommandHandler("ID_SECTION_GAP"); //打断剖面符号 32 | 33 | 34 | sel.SetElementIds(new List()); 35 | 36 | return Result.Succeeded; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /唐僧解瓦/高级/Cmd_DragTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Autodesk.Revit.Attributes; 7 | using Autodesk.Revit.DB; 8 | using Autodesk.Revit.UI; 9 | using 唐僧解瓦.BinLibrary.RevitHelper; 10 | using 唐僧解瓦.高级.UIs; 11 | 12 | namespace 唐僧解瓦.高级 13 | { 14 | [Transaction(TransactionMode.Manual)] 15 | class Cmd_DragTest:IExternalCommand 16 | { 17 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) 18 | { 19 | 20 | var uiapp = commandData.Application; 21 | var uidoc = uiapp.ActiveUIDocument; 22 | var doc = uidoc.Document; 23 | 24 | DragForm toolform = DragForm.Instance; 25 | toolform.Show(RevitWindowHelper.GetRevitWindow()); 26 | 27 | 28 | return Result.Succeeded; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /唐僧解瓦/高级/UIs/DragForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace 唐僧解瓦.高级.UIs 2 | { 3 | partial class DragForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.listView1 = new System.Windows.Forms.ListView(); 32 | this.SuspendLayout(); 33 | // 34 | // listView1 35 | // 36 | this.listView1.HideSelection = false; 37 | this.listView1.Location = new System.Drawing.Point(12, 9); 38 | this.listView1.Name = "listView1"; 39 | this.listView1.Size = new System.Drawing.Size(503, 330); 40 | this.listView1.TabIndex = 0; 41 | this.listView1.UseCompatibleStateImageBehavior = false; 42 | this.listView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseMove); 43 | // 44 | // DragForm 45 | // 46 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 47 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 48 | this.ClientSize = new System.Drawing.Size(527, 347); 49 | this.Controls.Add(this.listView1); 50 | this.Name = "DragForm"; 51 | this.Text = "DragForm"; 52 | this.ResumeLayout(false); 53 | 54 | } 55 | 56 | #endregion 57 | 58 | private System.Windows.Forms.ListView listView1; 59 | } 60 | } -------------------------------------------------------------------------------- /唐僧解瓦/高级/UIs/DragForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using Autodesk.Revit.DB; 11 | using Autodesk.Revit.UI; 12 | using Form = System.Windows.Forms.Form; 13 | 14 | namespace 唐僧解瓦.高级.UIs 15 | { 16 | public partial class DragForm : Form 17 | { 18 | private static DragForm instance; 19 | private UIDocument _uidoc; 20 | public static DragForm Instance 21 | { 22 | get { 23 | if (instance == null) 24 | { 25 | instance= new DragForm(); 26 | } 27 | 28 | return instance; 29 | } 30 | } 31 | 32 | public static DragForm GetInstance(UIDocument uidoc) 33 | { 34 | return new DragForm(uidoc); 35 | } 36 | 37 | public DragForm() 38 | { 39 | InitializeComponent(); 40 | } 41 | 42 | public DragForm(UIDocument uidoc) 43 | { 44 | InitializeComponent(); 45 | _uidoc = uidoc; 46 | 47 | } 48 | 49 | private void listView1_MouseMove(object sender, MouseEventArgs e) 50 | { 51 | UIApplication.DoDragDrop( null,new handler()); 52 | 53 | } 54 | 55 | 56 | 57 | } 58 | 59 | public class handler : IDropHandler 60 | { 61 | public void Execute(UIDocument document, object data) 62 | { 63 | 64 | 65 | } 66 | } 67 | } 68 | --------------------------------------------------------------------------------