├── CypherToPowerBI.pbix
├── HLApps.MEPGraph
├── packages.config
├── Model
│ ├── MEPEdgeTypes.cs
│ ├── Edge.cs
│ ├── Node.cs
│ └── pocos.cs
├── IGraphDBClient.cs
├── Properties
│ └── AssemblyInfo.cs
├── HLApps.MEPGraph.csproj
└── Neo4j
│ └── Neo4jClient.cs
├── README.md
├── HLApps.Revit.Graph
├── Parameters
│ ├── IHLPeramiter.cs
│ ├── HLRevitElementName.cs
│ ├── HLRevitElementProperty.cs
│ ├── HLRevitReadonlyTextData.cs
│ └── HLRevitParameter.cs
├── Graph
│ ├── ConnectorPointGeometrySegment.cs
│ ├── MEPConnector.cs
│ ├── Parsers
│ │ ├── IMEPGraphElementScanner.cs
│ │ ├── MEPGraphParserBase.cs
│ │ ├── FaceIntersectRay.cs
│ │ ├── MEPGraphParserElectrical.cs
│ │ └── SpaceToDoorPathScanner.cs
│ ├── MEPPathWriteCache.cs
│ ├── MEPPathDirectionEnum.cs
│ ├── MEPPathSection.cs
│ ├── MEPGraphUtils.cs
│ ├── MEPRevitGraphWriter.cs
│ ├── MEPNodeEdge.cs
│ ├── MEPPathNode.cs
│ └── MEPGraphWriter.cs
├── Utils
│ ├── MEPUtils.cs
│ ├── DocUtils.cs
│ ├── RevitElementExtensions.cs
│ └── GeoUtils.cs
├── Geometry
│ ├── GeometrySegment.cs
│ ├── SolidGeometrySegment.cs
│ ├── PointGeometrySegment.cs
│ ├── CurveGeometrySegment.cs
│ ├── Octree
│ │ ├── PointOctreeElementWriter.cs
│ │ ├── BoundsOctreeElementWriter.cs
│ │ ├── PointOctree.cs
│ │ └── BoundsOctree.cs
│ └── HLBoundingBoxXYZ.cs
├── RevitToGraphPublisherSettings.cs
├── Properties
│ └── AssemblyInfo.cs
├── RevitToGraphPublisher.cs
└── HLApps.Revit.Graph.csproj
├── HLApps.Revit.Graph.UIAddin
├── HLApps.Revit.Graph.addin
├── UI
│ ├── GraphAppWindow.xaml.cs
│ ├── ViewModel
│ │ ├── BaseViewModel.cs
│ │ ├── GraphAppViewModel.cs
│ │ └── Command.cs
│ └── GraphAppWindow.xaml
├── GraphAppShowCommand.cs
├── Properties
│ └── AssemblyInfo.cs
├── GraphApp.cs
└── HLApps.Revit.Graph.UIAddin.csproj
├── HLApps.RevitBuildConfigurations
├── RevitBuildConfigurations.projitems
├── HLApps.RevitBuildConfigurations.shproj
├── Imports.targets
├── LocalDebugAddin.targets
└── BuildConfigurations.targets
├── LICENSE
├── .gitignore
└── RevitToGraphDB.sln
/CypherToPowerBI.pbix:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willhl/GraphData-MEP/HEAD/CypherToPowerBI.pbix
--------------------------------------------------------------------------------
/HLApps.MEPGraph/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # SUPERSEDED
4 |
5 | **This repository has been superseded by the Building Graph:**
6 |
7 | https://github.com/willhl/BuildingGraph-Client-Revit
8 |
9 | This is a new(er) initiative which includes a GraphQL server built using GRANDstack, as well as the same direct Neo4j connections from this project.
10 |
11 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Parameters/IHLPeramiter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace HLApps.Revit.Parameters
7 | {
8 | public interface IHLPeramiter
9 | {
10 |
11 | string Name { get; }
12 |
13 | object Value { get; set; }
14 |
15 | Type ExpectedType { get; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Model/MEPEdgeTypes.cs:
--------------------------------------------------------------------------------
1 | namespace HLApps.MEPGraph.Model
2 | {
3 | public enum MEPEdgeTypes
4 | {
5 | IS_IN,
6 | IS_IN_SPACE,
7 | IS_OF,
8 | IS_ON,
9 | CABLETRAY_FLOW_TO,
10 | ELECTRICAL_FLOW_TO,
11 | AIR_FLOW_TO,
12 | HYDRONIC_FLOW_TO,
13 | FLOWS_TO,
14 | FLOWS_TO_SPACE,
15 | BOUNDED_BY,
16 | DERIVED_BY,
17 | REALIZED_BY,
18 | ABSTRACTED_BY
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/IGraphDBClient.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using HLApps.MEPGraph.Model;
3 |
4 | namespace HLApps.MEPGraph
5 | {
6 | public interface IGraphDBClient
7 | {
8 | void Dispose();
9 | long Push(Node node, Dictionary variables);
10 | void Relate(long fromNodeId, long toNodeId, MEPEdgeTypes relType, Dictionary variables);
11 | void Relate(Node fromNode, Node toNode, string relType, Dictionary variables);
12 | }
13 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/HLApps.Revit.Graph.addin:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Revit To Graph
5 | HLApps.Revit\HLApps.Revit.Graph.UIAddin.dll
6 | 5EE88C10-F682-4A48-8975-CB5652917F6B
7 | HLApps.Revit.Graph.UIAddin.GraphApp
8 | HLEA
9 | Will Reynolds @ Hoare Lea
10 |
11 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/ConnectorPointGeometrySegment.cs:
--------------------------------------------------------------------------------
1 |
2 | using Autodesk.Revit.DB;
3 | using HLApps.Revit.Geometry;
4 |
5 | namespace HLApps.Revit.Graph
6 | {
7 |
8 | public class ConnectorPointGeometrySegment : PointGeometrySegment
9 | {
10 | public ConnectorPointGeometrySegment(ElementId element, XYZ point, int Connectorindex) : base(element, point)
11 | {
12 | ConnectorIndex = Connectorindex;
13 | }
14 |
15 | public int ConnectorIndex { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPConnector.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | using Autodesk.Revit.DB;
8 |
9 | namespace HLApps.Revit.Graph
10 | {
11 | public abstract class MEPConnector
12 | {
13 |
14 | public XYZ Origin { get; set; }
15 |
16 | }
17 |
18 |
19 |
20 | public class RevitConnector : MEPConnector
21 | {
22 |
23 |
24 | }
25 |
26 | public class VirtualConnector : MEPConnector
27 | {
28 |
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/Parsers/IMEPGraphElementScanner.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Autodesk.Revit.DB;
3 | using HLApps.Revit.Geometry;
4 | using HLApps.Revit.Geometry.Octree;
5 |
6 | namespace HLApps.Revit.Graph.Parsers
7 | {
8 | public interface IMEPGraphElementScanner
9 | {
10 | void Initialise(ICollection geoSerchElements, BoundsOctree geo);
11 | void ScanFromDocument(Document doc, MEPRevitGraph graph, int maxDepth);
12 | void ScanFromElement(Element elm, MEPRevitGraph graph, int maxDepth);
13 | }
14 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/Parsers/MEPGraphParserBase.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Autodesk.Revit.DB;
3 |
4 | namespace HLApps.Revit.Graph.Parsers
5 | {
6 | public interface IRevitGraphParser
7 | {
8 | bool CanParse(Element elm);
9 | ElementFilter GetFilter();
10 |
11 | void ParseFrom(Element elm, MEPRevitGraphWriter writer);
12 | void ParseFrom(ICollection elm, MEPRevitGraphWriter writer);
13 |
14 | void FinalizeGraph(MEPRevitGraphWriter writer);
15 | void InitializeGraph(MEPRevitGraphWriter writer);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPPathWriteCache.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using HLApps.Revit.Geometry.Octree;
3 | using HLApps.Revit.Geometry;
4 | using HLApps.Revit.Graph.Parsers;
5 |
6 | namespace HLApps.Revit.Graph
7 | {
8 |
9 | public class MEPPathWriteCache
10 | {
11 | public BoundsOctree geoCache;
12 | public BoundsOctreeElementWriter geoCacheWriter;
13 | public PointOctree connectorsCache;
14 | public PointOctree rayhitCache;
15 | public HashSet ParsedElements;
16 | public double MaxDepth;
17 | }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Utils/MEPUtils.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.DB;
2 |
3 | namespace HLApps.Revit.Utils
4 | {
5 | class MEPUtils
6 | {
7 | public static ConnectorManager GetConnectionManager(Element elm)
8 | {
9 | if (elm is FamilyInstance)
10 | {
11 | return (elm as FamilyInstance).MEPModel.ConnectorManager;
12 | }
13 | else if (elm is MEPCurve)
14 | {
15 | return (elm as MEPCurve).ConnectorManager;
16 | }
17 | else
18 | {
19 | return null;
20 | }
21 | }
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/Parsers/FaceIntersectRay.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.DB;
2 |
3 | using HLApps.Revit.Geometry;
4 |
5 | namespace HLApps.Revit.Graph.Parsers
6 | {
7 | public class FaceIntersectRay
8 | {
9 | public string IntermediatDocIdent;
10 | public ElementId IntermeidateElement;
11 | public SolidGeometrySegment HittingSegment;
12 | public Element SourceElement;
13 | public Face SourceFace;
14 | public Face HittingFace;
15 | public XYZ RayVecotor;
16 | public UV SourceUV;
17 | public UV HittingUV;
18 | public XYZ SourceXYZ;
19 | public XYZ HittingXYZ;
20 | public SubfaceType SubFaceType;
21 | public double AreaWeight;
22 | public double Distance;
23 | public bool Ignore;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/GeometrySegment.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.DB;
2 |
3 |
4 | namespace HLApps.Revit.Geometry
5 | {
6 |
7 | public abstract class GeometrySegment
8 | {
9 |
10 | public HLBoundingBoxXYZ Bounds { get; set; }
11 |
12 | public string OriginatingDocIdent { get; set; }
13 | public ElementId OriginatingElement { get; set; }
14 | public ElementId OriginatingElementCategory { get; set; }
15 |
16 | public bool Removed { get; set; }
17 |
18 | protected string segId = string.Empty;
19 | public string SegmentId
20 | {
21 | get
22 | {
23 | return segId.ToString();
24 | }
25 | }
26 | public virtual void Invalidate()
27 | {
28 | Removed = true;
29 | }
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/UI/GraphAppWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 |
7 | using HLApps.Revit.Graph.UIAddin.ViewModel;
8 |
9 | namespace HLApps.Revit.Graph.UIAddin
10 | {
11 | internal partial class GraphAppWindow : Window
12 | {
13 | GraphAppViewModel _gappVM;
14 | public GraphAppWindow(GraphAppViewModel gappVM)
15 | {
16 | InitializeComponent();
17 |
18 | _gappVM = gappVM;
19 | this.DataContext = gappVM;
20 |
21 | pwBox.PasswordChanged += PwBox_PasswordChanged;
22 | }
23 |
24 | private void PwBox_PasswordChanged(object sender, RoutedEventArgs e)
25 | {
26 | _gappVM.Password = pwBox.Password;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/UI/ViewModel/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.ComponentModel;
5 |
6 | namespace HLApps.Revit.Graph.UIAddin.ViewModel
7 | {
8 | class BaseViewModel : INotifyPropertyChanged
9 | {
10 |
11 | public event PropertyChangedEventHandler PropertyChanged;
12 |
13 | ///
14 | /// Raises the property changed event.
15 | ///
16 | /// Name of the property.
17 | public virtual void NotifyPropertyChanged(string propertyName)
18 | {
19 | // If the event has been subscribed to, fire it.
20 | if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
21 | }
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/HLApps.RevitBuildConfigurations/RevitBuildConfigurations.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 59589e76-d411-4579-810d-a08074e453e7
7 |
8 |
9 | HLApps.RevitBuildConfigurations
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Model/Edge.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace HLApps.MEPGraph.Model
4 | {
5 | public class Edge
6 | {
7 | public virtual string TypeLabel
8 | {
9 | get; set;
10 | }
11 |
12 | public MEPEdgeTypes EdgeType { get; set; }
13 |
14 |
15 | Dictionary _extendedProperties = new Dictionary();
16 | public Dictionary ExtendedProperties { get => _extendedProperties; }
17 | public virtual Dictionary GetAllProperties()
18 | {
19 | var allProps = new Dictionary();
20 |
21 | foreach (var kvp in ExtendedProperties)
22 | {
23 | allProps.Add(kvp.Key, kvp.Value);
24 | }
25 |
26 | return allProps;
27 |
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/RevitToGraphPublisherSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace HLApps.Revit.Graph
8 | {
9 | public class RevitToGraphPublisherSettings
10 | {
11 | public RevitToGraphPublisherSettings()
12 | {
13 | IncludeElectrical = true;
14 | IncludeMechanical = true;
15 | DBHost = "localhost";
16 | DBPort = 7687;
17 | DBUsername = "neo4j";
18 | }
19 |
20 | public bool IncludeBoundaries { get; set; }
21 | public bool IncludeMechanical { get; set; }
22 | public bool IncludeElectrical { get; set; }
23 |
24 | public string DBPassword { get; set; }
25 | public string DBUsername { get; set; }
26 | public string DBHost { get; set; }
27 | public int DBPort { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/SolidGeometrySegment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using HLApps.Revit.Utils;
3 | using Autodesk.Revit.DB;
4 |
5 |
6 | namespace HLApps.Revit.Geometry
7 | {
8 | public class SolidGeometrySegment : GeometrySegment
9 | {
10 | public SolidGeometrySegment(Solid geo, Element element, HLBoundingBoxXYZ bounds)
11 | {
12 | Geometry = geo;
13 | OriginatingElement = element.Id;
14 | OriginatingDocIdent = DocUtils.GetDocumentIdent(element.Document);
15 | if (element.Category != null) OriginatingElementCategory = element.Category.Id;
16 |
17 | Bounds = bounds;
18 |
19 | Removed = false;
20 | segId = Guid.NewGuid().ToString();
21 | }
22 |
23 | public Solid Geometry { get; set; }
24 | public override void Invalidate()
25 | {
26 | Geometry = null;
27 | Removed = true;
28 | }
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPPathDirectionEnum.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace HLApps.Revit.Graph
8 | {
9 | public enum MEPPathDirection
10 | {
11 | Indeterminate,
12 | In,
13 | Out,
14 |
15 | }
16 |
17 |
18 | public enum MEPPathConnectionType
19 | {
20 | Phyiscal,
21 | Proximity,
22 | Analytical,
23 | ProximityNoConnector,
24 | SectionOf,
25 | }
26 |
27 |
28 | public enum MEPPathSectionType
29 | {
30 | Section,
31 | Equipment,
32 | Terminal,
33 | Transition,
34 | Accessory,
35 | Space,
36 | Wall,
37 | Window,
38 | Door,
39 | Floor,
40 | Roof,
41 | Lighting,
42 | Electrical,
43 | Data,
44 | Security,
45 | Safety,
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/PointGeometrySegment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.DB;
3 |
4 |
5 | namespace HLApps.Revit.Geometry
6 | {
7 | public class PointGeometrySegment : GeometrySegment
8 | {
9 | public PointGeometrySegment(ElementId element, XYZ point)
10 | {
11 | OriginatingElement = element;
12 | Point = point;
13 | Removed = false;
14 | segId = Guid.NewGuid().ToString();
15 | }
16 |
17 | public PointGeometrySegment(ElementId element, XYZ point, XYZ facing, XYZ hand, bool fflip, bool hflip) : this(element, point)
18 | {
19 | Facing = facing;
20 | Hand = hand;
21 | FacingFlipped = fflip;
22 | HandFlipped = hflip;
23 | }
24 |
25 | public XYZ Point { get; set; }
26 | public XYZ Facing { get; set; }
27 | public XYZ Hand { get; set; }
28 | public bool FacingFlipped { get; private set; }
29 | public bool HandFlipped { get; private set; }
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/GraphAppShowCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.DB;
3 | using Autodesk.Revit.UI;
4 |
5 | using HLApps.Revit.Graph.UIAddin.ViewModel;
6 |
7 |
8 | namespace HLApps.Revit.Graph.UIAddin
9 | {
10 | [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
11 | [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
12 | public class GraphAppShowCommand : IExternalCommand
13 | {
14 | public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
15 | {
16 | Document rDoc = cmdData.Application.ActiveUIDocument.Document;
17 | var gdApp = GraphApp.Instance;
18 | var publisher = new RevitToGraphPublisher(rDoc);
19 | GraphAppViewModel gvm = new GraphAppViewModel(publisher, gdApp);
20 | gdApp.GraphAppWindow = new GraphAppWindow(gvm);
21 | gdApp.GraphAppWindow.ShowDialog();
22 |
23 | return Result.Succeeded;
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Model/Node.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace HLApps.MEPGraph.Model
4 | {
5 | public class Node
6 | {
7 |
8 | public string UniqueId { get; set; }
9 |
10 | public virtual string Label
11 | {
12 | get
13 | {
14 | return GetType().Name;
15 | }
16 | }
17 |
18 | public string Name { get; set; }
19 |
20 | Dictionary _extendedProperties = new Dictionary();
21 | public Dictionary ExtendedProperties { get => _extendedProperties; }
22 |
23 |
24 | public virtual Dictionary GetAllProperties()
25 | {
26 | var allProps = new Dictionary();
27 |
28 | foreach(var kvp in ExtendedProperties)
29 | {
30 | allProps.Add(kvp.Key, kvp.Value);
31 | }
32 |
33 | if(!allProps.ContainsKey("Name")) allProps.Add("Name", Name);
34 |
35 | return allProps;
36 |
37 | }
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/HLApps.RevitBuildConfigurations/HLApps.RevitBuildConfigurations.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 59589e76-d411-4579-810d-a08074e453e7
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Utils/DocUtils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Autodesk.Revit.DB;
4 |
5 | namespace HLApps.Revit.Utils
6 | {
7 | class DocUtils
8 | {
9 | public static string GetDocumentIdent(Document doc)
10 | {
11 | if (doc.IsFamilyDocument)
12 | {
13 | return doc.PathName;
14 | }
15 | else
16 | {
17 | return string.Format("{0}:{1}", doc.ProjectInformation != null ? doc.ProjectInformation.UniqueId.ToString() : "", doc.PathName);
18 | }
19 | }
20 |
21 | public static Document GetDocument(string docIdent, Autodesk.Revit.ApplicationServices.Application revitApp)
22 | {
23 | Document doc = null;
24 | if (!string.IsNullOrEmpty(docIdent))
25 | {
26 | doc = revitApp.Documents.OfType()
27 | .FirstOrDefault(dc => GetDocumentIdent(dc) == docIdent);
28 |
29 | }
30 |
31 | return doc;
32 | }
33 |
34 | public static IEnumerable GetLinkInstances(Document _document)
35 | {
36 | var liColl = new FilteredElementCollector(_document);
37 | return liColl.OfClass(typeof(RevitLinkInstance)).ToElements().OfType();
38 |
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MEPGraphToNeo4j")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Hoare Lea")]
12 | [assembly: AssemblyProduct("MEPGraphToNeo4j")]
13 | [assembly: AssemblyCopyright("Copyright © Hoare Lea 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("400e1964-b716-4ea4-b21e-15c1f2135888")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RevitToGraphDB")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Hoare Lea")]
12 | [assembly: AssemblyProduct("RevitToGraphDB")]
13 | [assembly: AssemblyCopyright("Copyright © Hoare Lea 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("93280ff6-c2cc-4ece-8c26-d6794f7121d3")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RevitToGraphAddin")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Hoare Lea")]
12 | [assembly: AssemblyProduct("RevitToGraphAddin")]
13 | [assembly: AssemblyCopyright("Copyright © Hoare Lea 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("f5fecc1a-9803-43ea-a217-e9d321a7c2d2")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/GraphApp.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.UI;
7 | using Autodesk.Revit.DB;
8 |
9 | namespace HLApps.Revit.Graph.UIAddin
10 | {
11 |
12 | [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
13 | public class GraphApp : IExternalApplication
14 | {
15 | public static GraphApp Instance;
16 |
17 | public GraphApp()
18 | {
19 | Instance = this;
20 | }
21 |
22 | public Result OnShutdown(UIControlledApplication application)
23 | {
24 |
25 | return Result.Succeeded;
26 | }
27 |
28 | public Result OnStartup(UIControlledApplication application)
29 | {
30 |
31 | var appPanel = application.CreateRibbonPanel(Tab.AddIns, "HLApps");
32 | var showAppBtn = new PushButtonData("hleaPublishToGraph", "Publish to Graph", System.Reflection.Assembly.GetExecutingAssembly().Location, typeof(GraphAppShowCommand).FullName);
33 | showAppBtn.ToolTip = "Publish the current Revit model to a graph database";
34 | appPanel.AddItem(showAppBtn);
35 |
36 | //TODO: persist settings with local storage
37 | SessionSettings = new RevitToGraphPublisherSettings();
38 |
39 | return Result.Succeeded;
40 | }
41 |
42 | public System.Windows.Window GraphAppWindow { get; set; }
43 | public RevitToGraphPublisherSettings SessionSettings { get; private set; }
44 | }
45 | }
--------------------------------------------------------------------------------
/HLApps.RevitBuildConfigurations/Imports.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | C:\Program Files\Autodesk\Revit 2018\RevitAPI.dll
8 | False
9 |
10 |
11 |
12 | C:\Program Files\Autodesk\Revit 2019\RevitAPI.dll
13 | False
14 |
15 |
16 |
17 | C:\Program Files\Autodesk\Revit 2018\RevitAPIUI.dll
18 | False
19 |
20 |
21 |
22 | C:\Program Files\Autodesk\Revit 2019\RevitAPIUI.dll
23 | False
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/visualstudio
3 | # Edit at https://www.gitignore.io/?templates=visualstudio
4 |
5 | ### VisualStudio ###
6 | ## Ignore Visual Studio temporary files, build results, and
7 | ## files generated by popular Visual Studio add-ons.
8 | ##
9 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
10 |
11 | # User-specific files
12 | *.rsuser
13 | *.suo
14 | *.user
15 | *.userosscache
16 | *.sln.docstates
17 |
18 | # User-specific files (MonoDevelop/Xamarin Studio)
19 | *.userprefs
20 |
21 | # Build results
22 | [Dd]ebug/
23 | [Dd]ebugPublic/
24 | [Rr]elease/
25 | [Rr]eleases/
26 | x64/
27 | x86/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 |
33 | # Visual Studio 2015/2017 cache/options directory
34 | .vs/
35 | # Uncomment if you have tasks that create the project's static files in wwwroot
36 | #wwwroot/
37 |
38 | # Visual Studio 2017 auto generated files
39 | Generated\ Files/
40 |
41 | # Files built by Visual Studio
42 | *_i.c
43 | *_p.c
44 | *_h.h
45 | *.ilk
46 | *.meta
47 | *.obj
48 | *.iobj
49 | *.pch
50 | *.pdb
51 | *.ipdb
52 | *.pgc
53 | *.pgd
54 | *.rsp
55 | *.sbr
56 | *.tlb
57 | *.tli
58 | *.tlh
59 | *.tmp
60 | *.tmp_proj
61 | *_wpftmp.csproj
62 | *.log
63 | *.vspscc
64 | *.vssscc
65 | .builds
66 | *.pidb
67 | *.svclog
68 | *.scc
69 |
70 | # NuGet Packages
71 | *.nupkg
72 | # The packages folder can be ignored because of Package Restore
73 | **/[Pp]ackages/*
74 | # except build/, which is used as an MSBuild target.
75 | !**/[Pp]ackages/build/
76 | # Uncomment if necessary however generally it will be regenerated when needed
77 | #!**/[Pp]ackages/repositories.config
78 | # NuGet v3's project.json files produces more ignorable files
79 | *.nuget.props
80 | *.nuget.targets
81 |
82 | # Visual Studio cache files
83 | # files ending in .cache can be ignored
84 | *.[Cc]ache
85 | # but keep track of directories ending in .cache
86 | !*.[Cc]ache/
87 |
88 | # Local History for Visual Studio
89 | .localhistory/
90 |
91 | # End of https://www.gitignore.io/api/visualstudio
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Utils/RevitElementExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Autodesk.Revit.DB;
5 |
6 | namespace HLApps.Revit.Utils
7 | {
8 | static class RevitElementExtensions
9 | {
10 |
11 |
12 | public static Parameter HLGetParameter(this Element elm, string name)
13 | {
14 |
15 | var foundPramams = elm.GetParameters(name);
16 |
17 | if (foundPramams.Count == 0)
18 | {
19 | foundPramams = elm.Parameters.OfType().Where(p => string.Equals(p.Definition.Name, name, StringComparison.CurrentCultureIgnoreCase)).ToList();
20 | }
21 |
22 |
23 | var firstValidParam = foundPramams.FirstOrDefault(p => p.HasValue);
24 |
25 | return firstValidParam != null ? firstValidParam : foundPramams.FirstOrDefault();
26 |
27 | }
28 |
29 | public static Parameter HLGetParameter(this Element elm, BuiltInParameter bip)
30 | {
31 |
32 | return elm.get_Parameter(bip);
33 |
34 | }
35 |
36 |
37 | public static Parameter HLGetParameter(this Element elm, Guid Id)
38 | {
39 |
40 | return elm.get_Parameter(Id);
41 |
42 | }
43 |
44 |
45 | public static Parameter HLGetParameter(this Element elm, ElementId parameterId)
46 | {
47 | if (parameterId.IntegerValue == -1) return null;
48 |
49 | Parameter param = null;
50 | if (parameterId.IntegerValue < -1)
51 | {
52 | param = elm.get_Parameter((BuiltInParameter)parameterId.IntegerValue);
53 | }
54 | else
55 | {
56 | param = elm.Parameters.OfType().FirstOrDefault(pr => GetParameterId(pr).IntegerValue == parameterId.IntegerValue);
57 | }
58 |
59 | return param;
60 | }
61 |
62 | public static ElementId GetParameterId(Parameter param)
63 | {
64 | return param.Id;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/RevitToGraphPublisher.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 |
8 | namespace HLApps.Revit.Graph
9 | {
10 | public class RevitToGraphPublisher
11 | {
12 | Document _rdoc;
13 | public RevitToGraphPublisher(Document doc)
14 | {
15 | _rdoc = doc;
16 | }
17 |
18 | public void Publish(RevitToGraphPublisherSettings settings, MEPGraph.IGraphDBClient client)
19 | {
20 | var meGraph = new MEPRevitGraph();
21 | MEPRevitGraphWriter mps = new MEPRevitGraphWriter(meGraph);
22 |
23 | if (settings.IncludeElectrical) mps.Parsers.Add(new Parsers.MEPGraphParserElectrical());
24 | if (settings.IncludeMechanical) mps.Parsers.Add(new Parsers.MEPGraphParserConnectors());
25 | if (settings.IncludeBoundaries) mps.Parsers.Add(new Parsers.MEPGraphParserSpaces());
26 |
27 | if (mps.Parsers.Count == 0) return;
28 |
29 | var mecFEc = new FilteredElementCollector(_rdoc);
30 | var mecFilter = mps.GetFilterForAllParsers;
31 | var mecElements = mecFEc.WherePasses(mecFilter).WhereElementIsNotElementType().ToElements();
32 |
33 | var wfic = new FilteredElementCollector(_rdoc);
34 | var geoElementsFilter = new ElementMulticategoryFilter(new BuiltInCategory[] { BuiltInCategory.OST_Floors, BuiltInCategory.OST_Roofs, BuiltInCategory.OST_Windows, BuiltInCategory.OST_Doors, BuiltInCategory.OST_MEPSpaces, BuiltInCategory.OST_Rooms });
35 | var geoElements = wfic.WherePasses(geoElementsFilter).WhereElementIsNotElementType().ToElements();
36 |
37 |
38 | using (Transaction tx = new Transaction(_rdoc, "Build graph"))
39 | {
40 | tx.Start("Build graph");
41 | mps.Write(mecElements, geoElements, -1, true, _rdoc);
42 | tx.Commit();
43 | }
44 |
45 | MEPGraphWriter wre = new MEPGraphWriter(client);
46 | wre.Write(meGraph, _rdoc);
47 |
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/HLApps.RevitBuildConfigurations/LocalDebugAddin.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
15 |
16 |
17 |
18 |
19 | xcopy /y "$(TargetDir)*.dll" "C:\ProgramData\Autodesk\Revit\Addins\2018\HLApps.Revit\"
20 |
21 |
22 |
23 | xcopy /y "$(TargetDir)*.dll" "C:\ProgramData\Autodesk\Revit\Addins\2019\HLApps.Revit\"
24 |
25 |
26 |
27 |
28 | xcopy /y/S "$(SolutionDir)HLApps.Revit.Graph.UIAddin\HLApps.Revit.Graph.addin" "C:\ProgramData\Autodesk\Revit\Addins\2018\"
29 |
30 |
31 |
32 | xcopy /y/S "$(SolutionDir)HLApps.Revit.Graph.UIAddin\HLApps.Revit.Graph.addin" "C:\ProgramData\Autodesk\Revit\Addins\2019\"
33 |
34 |
35 |
36 |
37 | Program
38 | C:\Program Files\Autodesk\Revit 2018\Revit.exe
39 |
40 |
41 | C:\Program Files\Autodesk\Revit 2019\Revit.exe
42 | Program
43 |
44 |
45 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/CurveGeometrySegment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using HLApps.Revit.Utils;
3 | using Autodesk.Revit.DB;
4 |
5 |
6 | namespace HLApps.Revit.Geometry
7 | {
8 | public class CurveGeometrySegment : GeometrySegment
9 | {
10 | public CurveGeometrySegment(Curve curve, Element element)
11 | {
12 | Geometry = curve;
13 |
14 | OriginatingElement = element.Id;
15 | OriginatingDocIdent = DocUtils.GetDocumentIdent(element.Document);
16 | if (element.Category != null) OriginatingElementCategory = element.Category.Id;
17 |
18 | var min = curve.GetEndPoint(0);
19 | var max = curve.GetEndPoint(1);
20 | MidPoint = (min + max) / 2;
21 | Bounds = new HLBoundingBoxXYZ(min, max, false);
22 | Removed = false;
23 | segId = Guid.NewGuid().ToString();
24 |
25 | if (element is MEPCurve)
26 | {
27 | var dParam = element.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM);
28 | if (dParam != null)
29 | {
30 | Radius = dParam.AsDouble() * 0.5;
31 | }
32 | else
33 | {
34 | var wParam = element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
35 | if (wParam != null) Width = wParam.AsDouble();
36 | var hParam = element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
37 | if (hParam != null) Height = hParam.AsDouble();
38 | }
39 |
40 | }
41 | }
42 |
43 | public double MaxDimension
44 | {
45 | get
46 | {
47 | if (Radius > Height) return Radius;
48 | if (Radius > Width) return Radius;
49 | if (Height > Width) return Height;
50 | return Width;
51 | }
52 | }
53 |
54 | public Curve Geometry { get; set; }
55 |
56 | public override void Invalidate()
57 | {
58 | Geometry = null;
59 | Removed = true;
60 | }
61 |
62 | public double Width { private set; get; }
63 | public double Height { private set; get; }
64 | public double Radius { private set; get; }
65 |
66 | public XYZ MidPoint { get; private set; }
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Parameters/HLRevitElementName.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.DB;
3 |
4 | namespace HLApps.Revit.Parameters
5 | {
6 | public class HLRevitElementName : HLRevitElementData
7 | {
8 | Element _elm;
9 |
10 | public HLRevitElementName(Element elm)
11 | {
12 | _elm = elm;
13 | }
14 |
15 | public override string Name
16 | {
17 | get { return "Name"; }
18 | }
19 |
20 | public override object Value
21 | {
22 | get
23 | {
24 | return _elm.Name;
25 | }
26 | set
27 | {
28 | if (value != null)
29 | {
30 | _elm.Name = value.ToString();
31 | }
32 | }
33 | }
34 |
35 | public override Type ExpectedType
36 | {
37 | get { return typeof(string); }
38 | }
39 |
40 | public override string StringValue
41 | {
42 | get
43 | {
44 | return _elm.Name;
45 | }
46 | set
47 | {
48 | if (!string.IsNullOrEmpty(value)) _elm.Name = value;
49 | }
50 | }
51 |
52 | public override StorageType StorageType
53 | {
54 | get { return Autodesk.Revit.DB.StorageType.String; }
55 | }
56 |
57 | public override bool IsReadOnly
58 | {
59 | get { return false; }
60 | }
61 |
62 | public override int IntElementId
63 | {
64 | get
65 | {
66 | return _elm.Id.IntegerValue;
67 | }
68 | }
69 |
70 | protected override void OnDisposing()
71 | {
72 |
73 | }
74 | }
75 |
76 | /*
77 | *Name property on element has no Get?? this soultion didn't work
78 | public static class ObjectExtensions
79 | {
80 | public static Object GetPropertyValue(this Object obj, String propertyName)
81 | {
82 | if (obj == null) throw new ArgumentNullException("obj", "`obj` cannot be null");
83 |
84 | var fields = from f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
85 | where f.Name.Contains(String.Format("<{0}>", propertyName))
86 | select f;
87 |
88 | if (fields.Any())
89 | {
90 | return fields.First().GetValue(obj);
91 | }
92 |
93 | return null;
94 | }
95 | } */
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/Octree/PointOctreeElementWriter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | using Autodesk.Revit.DB;
4 |
5 |
6 | namespace HLApps.Revit.Geometry.Octree
7 | {
8 | public class PointOctreeElementWriter
9 | {
10 | PointOctree _pointStree;
11 | Dictionary> SegmentCache = new Dictionary>();
12 |
13 |
14 | public PointOctreeElementWriter(PointOctree pointStree)
15 | {
16 | _pointStree = pointStree;
17 | }
18 |
19 | public void AddElement(ICollection elements)
20 | {
21 | foreach (var elm in elements)
22 | {
23 | AddElement(elm);
24 | }
25 | }
26 |
27 | public void AddElement(Element elm)
28 | {
29 |
30 | if (_pointStree == null) return;
31 |
32 | var elmid = elm.Id.IntegerValue;
33 |
34 | HashSet segList;
35 |
36 | if (SegmentCache.ContainsKey(elmid))
37 | {
38 | segList = SegmentCache[elmid];
39 | }
40 | else
41 | {
42 | segList = new HashSet();
43 | }
44 |
45 | if (elm.Location is LocationPoint)
46 | {
47 | var lpoint = elm.Location as LocationPoint;
48 | PointGeometrySegment psg = null;
49 | if (elm is FamilyInstance)
50 | {
51 | var fi = elm as FamilyInstance;
52 | psg = new PointGeometrySegment(elm.Id, lpoint.Point, fi.FacingOrientation, fi.HandOrientation, fi.FacingFlipped, fi.HandFlipped);
53 | }
54 | else
55 | {
56 | psg = new PointGeometrySegment(elm.Id, lpoint.Point);
57 | }
58 |
59 | _pointStree.Add(psg, lpoint.Point);
60 | }
61 | else if (elm.Location is LocationCurve)
62 | {
63 | var curve = elm.Location as LocationCurve;
64 | if (curve == null) return;
65 |
66 | var cseg = new CurveGeometrySegment(curve.Curve, elm);
67 | segList.Add(cseg);
68 | _pointStree.Add(cseg, cseg.MidPoint);
69 | }
70 |
71 |
72 | if (!SegmentCache.ContainsKey(elmid))
73 | {
74 | SegmentCache.Add(elmid, segList);
75 | }
76 |
77 |
78 | }
79 |
80 | public PointOctree OcTree
81 | {
82 | get
83 | {
84 | return _pointStree;
85 | }
86 | }
87 |
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/HLApps.RevitBuildConfigurations/BuildConfigurations.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 | bin\x64\Debug\2018
7 | TRACE;DEBUG;REVIT2012,REVIT2013,REVIT2014,REVIT2015,REVIT2016,REVIT2017,REVIT2018
8 | full
9 | x64
10 | prompt
11 | MinimumRecommendedRules.ruleset
12 | $(MSBuildProjectName)
13 | false
14 | v4.6.1
15 |
16 |
17 | bin\x64\Release\2018
18 | TRACE;REVIT2012,REVIT2013,REVIT2014,REVIT2015,REVIT2016,REVIT2017,REVIT2018
19 | true
20 | pdbonly
21 | x64
22 | prompt
23 | MinimumRecommendedRules.ruleset
24 | $(MSBuildProjectName)
25 | false
26 | v4.6.1
27 |
28 |
29 |
30 | true
31 | bin\x64\Debug\2019\
32 | TRACE;DEBUG;REVIT2012,REVIT2013,REVIT2014,REVIT2015,REVIT2016,REVIT2017,REVIT2018,REVIT2019
33 | full
34 | x64
35 | prompt
36 | MinimumRecommendedRules.ruleset
37 | $(MSBuildProjectName)
38 | v4.7
39 |
40 |
41 | bin\x64\Release\2019\
42 | TRACE;REVIT2012,REVIT2013,REVIT2014,REVIT2015,REVIT2016,REVIT2017,REVIT2018,REVIT2019
43 | true
44 | pdbonly
45 | x64
46 | prompt
47 | MinimumRecommendedRules.ruleset
48 | $(MSBuildProjectName)
49 | v4.7
50 |
51 |
52 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/Parsers/MEPGraphParserElectrical.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | using Autodesk.Revit.DB;
4 |
5 |
6 | namespace HLApps.Revit.Graph.Parsers
7 | {
8 | public class MEPGraphParserElectrical : MEPGraphParserConnectors
9 | {
10 | public override bool CanParse(Element elm)
11 | {
12 | var cats = new BuiltInCategory[] {BuiltInCategory.OST_ElectricalEquipment, BuiltInCategory.OST_ElectricalFixtures, BuiltInCategory.OST_LightingDevices, BuiltInCategory.OST_LightingFixtures, BuiltInCategory.OST_SecurityDevices, BuiltInCategory.OST_DataDevices, BuiltInCategory.OST_FireAlarmDevices, BuiltInCategory.OST_CommunicationDevices, BuiltInCategory.OST_NurseCallDevices, BuiltInCategory.OST_TelephoneDevices };
13 | return elm.Category != null ? cats.Contains((BuiltInCategory)elm.Category.Id.IntegerValue) : false;
14 | }
15 |
16 | public override ElementFilter GetFilter()
17 | {
18 | var cats = new BuiltInCategory[] {BuiltInCategory.OST_ElectricalEquipment, BuiltInCategory.OST_ElectricalFixtures, BuiltInCategory.OST_LightingDevices, BuiltInCategory.OST_LightingFixtures, BuiltInCategory.OST_SecurityDevices, BuiltInCategory.OST_DataDevices, BuiltInCategory.OST_FireAlarmDevices, BuiltInCategory.OST_CommunicationDevices, BuiltInCategory.OST_NurseCallDevices, BuiltInCategory.OST_TelephoneDevices };
19 | var emcf = new ElementMulticategoryFilter(cats);
20 | return emcf;
21 | }
22 |
23 | public override void ParseFrom(Element elm, MEPRevitGraphWriter writer)
24 | {
25 |
26 | //connect db panels to their circuits
27 | if (elm is FamilyInstance)
28 | {
29 | var fi = elm as FamilyInstance;
30 | var sysElm = fi.MEPModel;
31 | if (sysElm != null && sysElm.ElectricalSystems != null)
32 | {
33 | var panleSystems = sysElm.ElectricalSystems.OfType().Where(sy => sy.BaseEquipment != null && sy.BaseEquipment.Id == elm.Id);
34 |
35 | foreach (var sys in panleSystems)
36 | {
37 | writer.Graph.AddConnection(elm, sys, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO);
38 |
39 | try
40 | {
41 | var elmsINSys = sys.Elements.OfType();
42 |
43 | foreach (var emms in elmsINSys)
44 | {
45 | writer.Graph.AddConnection(sys, emms, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO);
46 |
47 | ParseFrom(emms, writer);
48 | }
49 | }
50 | catch
51 | {
52 | //log exception
53 | }
54 | }
55 | }
56 | }
57 |
58 | base.ParseFrom(elm, writer);
59 |
60 | }
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/HLApps.Revit.Graph.UIAddin.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}
8 | Library
9 | Properties
10 | HLApps.Revit.Graph.UIAddin
11 | HLApps.Revit.Graph.UIAddin
12 | v4.6.1
13 | 512
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | GraphAppWindow.xaml
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | {400e1964-b716-4ea4-b21e-15c1f2135888}
48 | HLApps.MEPGraph
49 |
50 |
51 | {93280ff6-c2cc-4ece-8c26-d6794f7121d3}
52 | HLApps.Revit.Graph
53 |
54 |
55 |
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPPathSection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.ObjectModel;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | using Autodesk.Revit.DB;
9 |
10 |
11 | namespace HLApps.Revit.Graph
12 | {
13 |
14 |
15 |
16 |
17 | public class MEPPathSection
18 | {
19 |
20 | public MEPPathSection()
21 | {
22 |
23 | }
24 |
25 | public MEPPathSection(int orgId)
26 | {
27 |
28 | }
29 |
30 | public MEPPathSection(int orgId, double pathlength, MEPPathSection parent)
31 | {
32 | _ordId = orgId;
33 | _In = parent;
34 | _pathLength = pathlength;
35 | }
36 |
37 | public MEPPathSection(Element elm, double pathlength, MEPPathSection parent) : this(elm, pathlength)
38 | {
39 | _In = parent;
40 | }
41 |
42 |
43 | public MEPPathSection(Element elm, double pathlength)
44 | {
45 | _ordId = elm.Id.IntegerValue;
46 | _pathLength = pathlength;
47 | _name = elm.Name;
48 |
49 | if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal) _sectionType = MEPPathSectionType.Terminal;
50 | if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MechanicalEquipment) _sectionType = MEPPathSectionType.Equipment;
51 |
52 | }
53 |
54 | string _name;
55 | public string Name
56 | {
57 | get
58 | {
59 | return _name;
60 | }
61 | }
62 |
63 | MEPPathSectionType _sectionType = MEPPathSectionType.Section;
64 | public MEPPathSectionType SectionType
65 | {
66 | get { return _sectionType; }
67 | }
68 |
69 | double _pathLength = 0;
70 | public double PathLength
71 | {
72 | get { return _pathLength; }
73 | }
74 |
75 | public double TotalPathLeghth
76 | {
77 | get
78 | {
79 | return PathLength + (_In != null ? _In.TotalPathLeghth : 0);
80 | }
81 | }
82 |
83 | int _ordId = -1;
84 | int OriginId
85 | {
86 | get { return _ordId; }
87 | }
88 |
89 | MEPPathSection _In;
90 | public MEPPathSection In
91 | {
92 | get { return _In; }
93 | }
94 |
95 | List _out = new List();
96 | public IEnumerable Out { get { return _out; } }
97 |
98 | public void Connect(MEPPathSection section, MEPPathDirection direction)
99 | {
100 | if (direction == MEPPathDirection.Out) _out.Add(section);
101 | if (direction == MEPPathDirection.In) _In = section;
102 | }
103 |
104 | public double GetLengthTo(string search)
105 | {
106 | if (_In != null && !_In.Name.Contains(search))
107 | {
108 | return _In.PathLength + _In.GetLengthTo(search);
109 | }
110 |
111 | return 0;
112 | }
113 |
114 | }
115 |
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPGraphUtils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Autodesk.Revit.DB;
4 | using HLApps.MEPGraph.Model;
5 | using HLApps.Revit.Parameters;
6 |
7 | namespace HLApps.Revit.Graph
8 | {
9 | public static class MEPGraphUtils
10 | {
11 | public static object RevitToGraphValue(HLRevitElementData elmData)
12 | {
13 | var val = elmData.Value;
14 | if (val is ElementId) return (val as ElementId).IntegerValue;
15 |
16 | if (val is Element) return (val as Element).Name;
17 |
18 | return val;
19 | }
20 |
21 | public static Dictionary GetNodePropsWithElementProps(Node node, Element elm)
22 | {
23 | var elmParms = node.GetAllProperties();
24 |
25 |
26 | if (elm != null && elm.Location is Autodesk.Revit.DB.LocationPoint)
27 | {
28 | var lpt = (elm.Location as Autodesk.Revit.DB.LocationPoint);
29 | var insPt = lpt.Point;
30 | if (!elmParms.ContainsKey("LocationX")) elmParms.Add("LocationX", insPt.X);
31 | if (!elmParms.ContainsKey("LocationY")) elmParms.Add("LocationY", insPt.Y);
32 | if (!elmParms.ContainsKey("LocationZ")) elmParms.Add("LocationZ", insPt.Z);
33 | //if (!elmParms.ContainsKey("LocationRotation")) elmParms.Add("LocationRotation", lpt.Rotation);
34 | }
35 | else if (elm != null && elm.Location is Autodesk.Revit.DB.LocationCurve)
36 | {
37 | //just start and end points for now
38 | var insPt = (elm.Location as Autodesk.Revit.DB.LocationCurve).Curve.GetEndPoint(0);
39 | if (!elmParms.ContainsKey("LocationX")) elmParms.Add("LocationX", insPt.X);
40 | if (!elmParms.ContainsKey("LocationY")) elmParms.Add("LocationY", insPt.Y);
41 | if (!elmParms.ContainsKey("LocationZ")) elmParms.Add("LocationZ", insPt.Z);
42 |
43 | insPt = (elm.Location as Autodesk.Revit.DB.LocationCurve).Curve.GetEndPoint(1);
44 | if (!elmParms.ContainsKey("LocationX2")) elmParms.Add("LocationX2", insPt.X);
45 | if (!elmParms.ContainsKey("LocationY2")) elmParms.Add("LocationY2", insPt.Y);
46 | if (!elmParms.ContainsKey("LocationZ2")) elmParms.Add("LocationZ2", insPt.Z);
47 | }
48 |
49 |
50 | foreach (var param in elm.Parameters.OfType())
51 | {
52 | var hp = new HLRevitParameter(param);
53 | var val = RevitToGraphValue(hp);
54 |
55 | if (!elmParms.ContainsKey(param.Definition.Name))
56 | {
57 | elmParms.Add(param.Definition.Name, val);
58 | }
59 |
60 | if (!elmParms.ContainsKey(param.Definition.Name))
61 | {
62 | elmParms.Add(param.Definition.Name, val);
63 | }
64 | }
65 |
66 | return elmParms;
67 | }
68 |
69 | public static Dictionary GetEdgeProps(Element elm)
70 | {
71 | var eprops = new Dictionary();
72 | if (elm != null)
73 | {
74 | eprops.Add("UniqueId", elm.UniqueId);
75 | eprops.Add("ModelId", elm.Id.IntegerValue);
76 | }
77 |
78 | return eprops;
79 |
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/HLApps.MEPGraph.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {400E1964-B716-4EA4-B21E-15C1F2135888}
8 | Library
9 | Properties
10 | HLApps.MEPGraph
11 | HLApps.MEPGraph
12 | v4.6.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 | x64
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 | true
35 | bin\x64\Debug\
36 | DEBUG;TRACE
37 | full
38 | x64
39 | prompt
40 | MinimumRecommendedRules.ruleset
41 |
42 |
43 | bin\x64\Release\
44 | TRACE
45 | true
46 | pdbonly
47 | x64
48 | prompt
49 | MinimumRecommendedRules.ruleset
50 |
51 |
52 |
53 | ..\packages\Neo4j.Driver.1.7.0\lib\net452\Neo4j.Driver.dll
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/RevitToGraphDB.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2027
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HLApps.Revit.Graph", "HLApps.Revit.Graph\HLApps.Revit.Graph.csproj", "{93280FF6-C2CC-4ECE-8C26-D6794F7121D3}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HLApps.MEPGraph", "HLApps.MEPGraph\HLApps.MEPGraph.csproj", "{400E1964-B716-4EA4-B21E-15C1F2135888}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HLApps.Revit.Graph.UIAddin", "HLApps.Revit.Graph.UIAddin\HLApps.Revit.Graph.UIAddin.csproj", "{F5FECC1A-9803-43EA-A217-E9D321A7C2D2}"
11 | EndProject
12 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "HLApps.RevitBuildConfigurations", "HLApps.RevitBuildConfigurations\HLApps.RevitBuildConfigurations.shproj", "{59589E76-D411-4579-810D-A08074E453E7}"
13 | EndProject
14 | Global
15 | GlobalSection(SharedMSBuildProjectFiles) = preSolution
16 | HLApps.RevitBuildConfigurations\RevitBuildConfigurations.projitems*{59589e76-d411-4579-810d-a08074e453e7}*SharedItemsImports = 13
17 | EndGlobalSection
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug2018|x64 = Debug2018|x64
20 | Debug2019|x64 = Debug2019|x64
21 | Release2018|x64 = Release2018|x64
22 | Release2019|x64 = Release2019|x64
23 | EndGlobalSection
24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
25 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Debug2018|x64.ActiveCfg = RV2018DBDebug|x64
26 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Debug2018|x64.Build.0 = RV2018DBDebug|x64
27 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Debug2019|x64.ActiveCfg = RV2019DBDebug|x64
28 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Debug2019|x64.Build.0 = RV2019DBDebug|x64
29 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Release2018|x64.ActiveCfg = RV2018DBRelease|x64
30 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Release2018|x64.Build.0 = RV2018DBRelease|x64
31 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Release2019|x64.ActiveCfg = RV2019DBRelease|x64
32 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}.Release2019|x64.Build.0 = RV2019DBRelease|x64
33 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Debug2018|x64.ActiveCfg = Debug|x64
34 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Debug2018|x64.Build.0 = Debug|x64
35 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Debug2019|x64.ActiveCfg = Debug|x64
36 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Debug2019|x64.Build.0 = Debug|x64
37 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Release2018|x64.ActiveCfg = Release|x64
38 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Release2018|x64.Build.0 = Release|x64
39 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Release2019|x64.ActiveCfg = Release|x64
40 | {400E1964-B716-4EA4-B21E-15C1F2135888}.Release2019|x64.Build.0 = Release|x64
41 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Debug2018|x64.ActiveCfg = RV2018Debug|x64
42 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Debug2018|x64.Build.0 = RV2018Debug|x64
43 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Debug2019|x64.ActiveCfg = RV2019Debug|x64
44 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Debug2019|x64.Build.0 = RV2019Debug|x64
45 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Release2018|x64.ActiveCfg = RV2018Release|x64
46 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Release2018|x64.Build.0 = RV2018Release|x64
47 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Release2019|x64.ActiveCfg = RV2019Release|x64
48 | {F5FECC1A-9803-43EA-A217-E9D321A7C2D2}.Release2019|x64.Build.0 = RV2019Release|x64
49 | EndGlobalSection
50 | GlobalSection(SolutionProperties) = preSolution
51 | HideSolutionNode = FALSE
52 | EndGlobalSection
53 | GlobalSection(ExtensibilityGlobals) = postSolution
54 | SolutionGuid = {D56EF679-D1D3-4CB1-BE53-7981591D6E5E}
55 | EndGlobalSection
56 | EndGlobal
57 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Model/pocos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Text;
4 | using System.Threading.Tasks;
5 |
6 | namespace HLApps.MEPGraph.Model
7 | {
8 |
9 | public class ElementType : Node
10 | {
11 | public string Category { get; set; }
12 |
13 |
14 |
15 | }
16 |
17 | public class ModelElement : Node
18 | {
19 | public string Category { get; set; }
20 |
21 | }
22 |
23 | public class Space : Node
24 | {
25 |
26 | }
27 |
28 | public class Project : Node
29 | {
30 | public string number { get; set; }
31 | }
32 |
33 | public class RevitModel : Node
34 | {
35 | public string uri { get; set; }
36 | }
37 |
38 | public class ForgeModel : Node
39 | {
40 | public string uri { get; set; }
41 | }
42 |
43 | public class Surface : Node
44 | {
45 | public double area { get; set; }
46 | }
47 |
48 | public class VoidVolume : Node
49 | {
50 |
51 | }
52 |
53 | public class Wall : Node
54 | {
55 |
56 | }
57 |
58 | public class Door : Node
59 | {
60 |
61 | }
62 |
63 | public class Window : Node
64 | {
65 |
66 | }
67 |
68 | public class Ceiling : Node
69 | {
70 |
71 | }
72 |
73 | public class Column : Node
74 | {
75 |
76 | }
77 |
78 |
79 | public class Roof : Node
80 | {
81 |
82 | }
83 |
84 | public class Floor : Node
85 | {
86 |
87 | }
88 |
89 | public class Section : Node
90 | {
91 |
92 | }
93 |
94 | public class Duct : Section
95 | {
96 |
97 | }
98 |
99 | public class Pipe : Section
100 | {
101 |
102 | }
103 |
104 | public class CableTray : Section
105 | {
106 |
107 | }
108 |
109 | public class Transition : Node
110 | {
111 |
112 | }
113 |
114 | public class DuctTransition : Transition
115 | {
116 |
117 | }
118 | public class PipeTransition : Transition
119 | {
120 |
121 | }
122 |
123 | public class CableTrayTransition : Transition
124 | {
125 |
126 | }
127 |
128 | public class Terminal : Node
129 | {
130 |
131 | }
132 |
133 | public class Accessory : Node
134 | {
135 |
136 | }
137 |
138 | public class DuctAccessory : Accessory
139 | {
140 |
141 | }
142 | public class PipeAccessory : Accessory
143 | {
144 |
145 | }
146 | public class Equipment : Node
147 | {
148 |
149 | }
150 |
151 | public class Level : Node
152 | {
153 |
154 | }
155 |
156 |
157 | public class System : Node
158 | {
159 |
160 | }
161 |
162 | public class Circuit : Node
163 | {
164 |
165 | }
166 |
167 |
168 | public class DBPanel : Node
169 | {
170 |
171 | }
172 |
173 | public class ElectricalLoad : Node
174 | {
175 |
176 | }
177 |
178 | public class ElectricalSource : Node
179 | {
180 |
181 | }
182 |
183 | public class ElectricalDevice : Node
184 | {
185 |
186 | }
187 |
188 | public class Data : Node
189 | {
190 |
191 | }
192 |
193 | public class Security : Node
194 | {
195 |
196 | }
197 |
198 | public class Safety : Node
199 | {
200 |
201 | }
202 |
203 | public class Sprinkler : Safety
204 | {
205 |
206 | }
207 |
208 | public class FireAlarm : Safety
209 | {
210 |
211 | }
212 |
213 |
214 | public class Lighting : Node
215 | {
216 |
217 | }
218 | public class Environment : Node
219 | {
220 |
221 | }
222 |
223 |
224 | public class Realisable : Node
225 | {
226 |
227 | }
228 |
229 |
230 | public class RealisableType : Node
231 | {
232 |
233 | }
234 |
235 | }
236 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/Parsers/SpaceToDoorPathScanner.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Autodesk.Revit.DB;
5 | using HLApps.Revit.Geometry;
6 | using HLApps.Revit.Geometry.Octree;
7 | using HLApps.Revit.Utils;
8 |
9 | namespace HLApps.Revit.Graph.Parsers
10 | {
11 | public class SpaceNetworkPathScanner : IMEPGraphElementScanner
12 | {
13 | BoundsOctree _geoTree;
14 |
15 | public void Initialise(ICollection geoSerchElements, BoundsOctree geo)
16 | {
17 | _geoTree = geo;
18 |
19 |
20 | }
21 |
22 |
23 | public void ScanFromDocument(Document doc, MEPRevitGraph graph, int maxDepth)
24 | {
25 | Dictionary> spaceToDoors = new Dictionary>();
26 |
27 | scanFromDocument(graph, doc, Transform.Identity, doc);
28 |
29 | //get linked documents
30 | foreach (RevitLinkInstance linkedInstance in DocUtils.GetLinkInstances(doc))
31 | {
32 |
33 | //RevitLinkType linkType = (RevitLinkType)doc.GetElement(linkedInstance.GetTypeId()) as RevitLinkType;
34 |
35 | //ExternalFileReference exfRef = linkType.GetExternalFileReference();
36 |
37 | //if (exfRef.GetLinkedFileStatus() != LinkedFileStatus.Loaded) continue;
38 |
39 |
40 | var ldoc = linkedInstance.GetLinkDocument();
41 | if (ldoc == null) continue;
42 | scanFromDocument(graph, ldoc, linkedInstance.GetTotalTransform().Inverse, doc);
43 | }
44 |
45 | }
46 |
47 | public void ScanFromElement(Element elm, MEPRevitGraph graph, int maxDepth)
48 | {
49 | //TODO: actually scan from the supplied element
50 | ScanFromDocument(elm.Document, graph, maxDepth);
51 |
52 | }
53 |
54 | void scanFromDocument(MEPRevitGraph graph, Document doc, Transform tr, Document spaceSourceDoc)
55 | {
56 | var doorCol = new FilteredElementCollector(doc);
57 | var doors = doorCol.OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements().OfType();
58 |
59 | foreach (var door in doors)
60 | {
61 | if (door.Location == null) continue;
62 |
63 | var ho = door.FacingFlipped ? door.FacingOrientation.Negate() : door.FacingOrientation;
64 | //var bbox = door.get_BoundingBox(null);
65 | var midPoint = (door.Location as LocationPoint).Point + new XYZ(0, 0, 1);
66 | //if (bbox != null)
67 | //{
68 | // midPoint = (bbox.Min + bbox.Max) / 2;
69 | //}
70 |
71 | //get point in front
72 | var hfOrt = ho.Normalize();
73 | var frontPos = midPoint + hfOrt.Multiply(1.64042); //stub is 1.64042 feet (0.5 meters)
74 | var lpFrontPoint = tr.OfPoint(frontPos);
75 | var spFront = spaceSourceDoc.GetSpaceAtPoint(lpFrontPoint);//, phase);
76 |
77 |
78 | //get point behind
79 | var hbOrt = ho.Negate().Normalize();
80 | var behindPos = midPoint + hbOrt.Multiply(1.64042); //stub is 1.64042 feet (0.5 meters)
81 | var lpBehindPoint = tr.OfPoint(behindPos);
82 | var spBehind = spaceSourceDoc.GetSpaceAtPoint(lpBehindPoint);//, phase);
83 |
84 |
85 |
86 | if (spFront != null)
87 | {
88 | var edges = graph.AddConnection(spFront, door, midPoint, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO);
89 | edges.ThisNode.OrginTransform = tr;
90 | }
91 |
92 | if (spBehind != null)
93 | {
94 | var edges = graph.AddConnection(door, spBehind, midPoint, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO);
95 | edges.ThisNode.OrginTransform = tr;
96 | }
97 |
98 |
99 | }
100 | }
101 |
102 |
103 |
104 | }
105 |
106 | }
107 |
108 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/HLApps.Revit.Graph.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {93280FF6-C2CC-4ECE-8C26-D6794F7121D3}
8 | Library
9 | Properties
10 | HLApps.Revit.Graph
11 | HLApps.Revit.Graph
12 | v4.5.1
13 | 512
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 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | {400e1964-b716-4ea4-b21e-15c1f2135888}
76 | HLApps.MEPGraph
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/UI/ViewModel/GraphAppViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 |
8 | namespace HLApps.Revit.Graph.UIAddin.ViewModel
9 | {
10 | class GraphAppViewModel : BaseViewModel
11 | {
12 | GraphApp _app;
13 | RevitToGraphPublisherSettings _settings;
14 | RevitToGraphPublisher _publisher;
15 | public GraphAppViewModel(RevitToGraphPublisher pubisher, GraphApp app)
16 | {
17 | _publishToGraphCommand = new Command(PublishToGraph);
18 | _cancelCommand = new Command(Close);
19 | _publisher = pubisher;
20 | _settings = app.SessionSettings;
21 | _app = app;
22 | }
23 |
24 | public string Username
25 | {
26 | get
27 | {
28 | return _settings.DBUsername;
29 | }
30 | set
31 | {
32 | _settings.DBUsername = value;
33 | NotifyPropertyChanged("Username");
34 | }
35 | }
36 |
37 |
38 | public string Password
39 | {
40 | get
41 | {
42 | return _settings.DBPassword;
43 | }
44 | set
45 | {
46 | _settings.DBPassword = value;
47 | NotifyPropertyChanged("Password");
48 | }
49 | }
50 |
51 | public string Host
52 | {
53 | get
54 | {
55 | return _settings.DBHost;
56 | }
57 | set
58 | {
59 | _settings.DBHost = value;
60 | NotifyPropertyChanged("Host");
61 | }
62 | }
63 | public int Port
64 | {
65 | get
66 | {
67 | return _settings.DBPort;
68 | }
69 | set
70 | {
71 | _settings.DBPort = value;
72 | NotifyPropertyChanged("Port");
73 | }
74 | }
75 |
76 | public bool IncludeBoundaries
77 | {
78 | get
79 | {
80 | return _settings.IncludeBoundaries;
81 | }
82 | set
83 | {
84 | _settings.IncludeBoundaries = value;
85 | NotifyPropertyChanged("IncludeBoundaries");
86 | NotifyPropertyChanged("CanPublish");
87 | }
88 | }
89 | public bool IncludeMechanical
90 | {
91 | get
92 | {
93 | return _settings.IncludeMechanical;
94 | }
95 | set
96 | {
97 | _settings.IncludeMechanical = value;
98 | NotifyPropertyChanged("IncludeMechanical");
99 | NotifyPropertyChanged("CanPublish");
100 | }
101 | }
102 | public bool IncludeElectrical
103 | {
104 | get
105 | {
106 | return _settings.IncludeElectrical;
107 | }
108 | set
109 | {
110 | _settings.IncludeElectrical = value;
111 | NotifyPropertyChanged("IncludeElectrical");
112 | NotifyPropertyChanged("CanPublish");
113 | }
114 | }
115 |
116 | public bool CanPublish
117 | {
118 | get
119 | {
120 | return IncludeBoundaries || IncludeMechanical || IncludeElectrical;
121 | }
122 | }
123 |
124 | Command _publishToGraphCommand;
125 | public Command PublishToGraphCommand
126 | {
127 | get
128 | {
129 | return _publishToGraphCommand;
130 | }
131 | }
132 |
133 | Command _cancelCommand;
134 | public Command CancelCommand
135 | {
136 | get
137 | {
138 | return _cancelCommand;
139 | }
140 | }
141 |
142 | void PublishToGraph()
143 | {
144 | var client = new MEPGraph.Neo4jClient(new Uri(string.Format("bolt://{0}:{1}", Host, Port)), Username, Password);
145 | _publisher.Publish(_settings, client);
146 | Autodesk.Revit.UI.TaskDialog.Show("Publish complete", "The current revit model has been successfully published to the graph database.");
147 | Close();
148 | }
149 |
150 | void Close()
151 | {
152 | var appWindow = _app.GraphAppWindow;
153 | if (appWindow != null && appWindow.IsVisible) appWindow.Close();
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPRevitGraphWriter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | using Autodesk.Revit.DB;
5 | using HLApps.Revit.Geometry;
6 | using HLApps.Revit.Geometry.Octree;
7 | using HLApps.Revit.Graph.Parsers;
8 | using HLApps.Revit.Utils;
9 |
10 | namespace HLApps.Revit.Graph
11 | {
12 | public class MEPRevitGraphWriter
13 | {
14 | MEPRevitGraph graph = new MEPRevitGraph();
15 |
16 | public MEPRevitGraphWriter(MEPRevitGraph graph)
17 | {
18 | Cache = new MEPPathWriteCache();
19 | Graph = graph;
20 | Parsers = new List();
21 |
22 | }
23 |
24 | public List Parsers { get; private set; }
25 | public MEPPathWriteCache Cache { get; private set; }
26 |
27 | public MEPRevitGraph Graph { get; private set; }
28 |
29 | public ElementFilter GetFilterForAllParsers
30 | {
31 | get
32 | {
33 | var orFlre = new LogicalOrFilter(Parsers.Select(p => p.GetFilter()).ToList());
34 | return orFlre;
35 | }
36 | }
37 |
38 | public void Write(ICollection scanElements, ICollection geoSerchElements, int maxDepth, bool doGeometryMatch, Document doc)
39 | {
40 |
41 | Cache.connectorsCache = new PointOctree(6.56168F, XYZ.Zero, 2F);
42 | Cache.MaxDepth = maxDepth;
43 | Cache.geoCache = new BoundsOctree(2, XYZ.Zero, 2F, 1.001f);
44 | Cache.geoCacheWriter = new BoundsOctreeElementWriter(Cache.geoCache);
45 | Cache.ParsedElements = new HashSet();
46 | Cache.rayhitCache = new PointOctree(2, XYZ.Zero, 2F);
47 |
48 | var dsCount = geoSerchElements.Count;
49 |
50 | foreach (var elm in geoSerchElements)
51 | {
52 | var cmn = MEPUtils.GetConnectionManager(elm);
53 | if (cmn != null)
54 | {
55 |
56 | foreach (var conn in cmn.Connectors.OfType())
57 | {
58 | #if REVIT2016
59 | var gesseg = new ConnectorPointGeometrySegment(elm.Id, conn.Origin, conn.Id);
60 | Cache.connectorsCache.Add(gesseg, conn.Origin);
61 | #else
62 | throw new Exception("Only supported in Revit 2016 onwards");
63 | #endif
64 | }
65 |
66 |
67 | }
68 |
69 | if (doGeometryMatch) Cache.geoCacheWriter.AddElement(elm, true);
70 | }
71 |
72 | if (doGeometryMatch)
73 | {
74 | var li = DocUtils.GetLinkInstances(doc);
75 | dsCount = li.Count();
76 | //cache geometry in linked documents. The geometry is expected to remain static, or changed as a block, so we don't need to keep track of each element.
77 | foreach (var linkedInstance in li)
78 | {
79 | Transform docTransform = linkedInstance.GetTotalTransform();
80 | Transform docTransformInverse = docTransform.Inverse;
81 |
82 | //RevitLinkType linkType = (RevitLinkType)rDoc.GetElement(linkedInstance.GetTypeId()) as RevitLinkType;
83 | var ldoc = linkedInstance.GetLinkDocument();// HLRevitUtilities.GetLinkedDocumentFromType(_rdoc.Application, linkType);
84 | if (ldoc == null) continue;
85 |
86 | var lnGeoCol = new FilteredElementCollector(ldoc);
87 | var lnGeoFilter = new ElementMulticategoryFilter(new BuiltInCategory[] { BuiltInCategory.OST_Floors, BuiltInCategory.OST_Roofs });
88 |
89 | foreach (var lnelm in lnGeoCol.WherePasses(lnGeoFilter).WhereElementIsNotElementType().ToElements())
90 | {
91 | Cache.geoCacheWriter.AddElement(lnelm, true, docTransformInverse);
92 | }
93 | }
94 | }
95 |
96 |
97 | var elmcache = new HashSet();
98 | var parserCount = Parsers.Count;
99 |
100 | foreach (var parser in Parsers)
101 | {
102 | parser.InitializeGraph(this);
103 | var elms = scanElements.Where(el => parser.CanParse(el)).ToList();
104 | dsCount = elms.Count();
105 |
106 | foreach (var elm in elms)
107 | {
108 | parser.ParseFrom(elm, this);
109 | }
110 | parser.FinalizeGraph(this);
111 | }
112 |
113 | }
114 |
115 |
116 | }
117 | }
118 |
119 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Utils/GeoUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Autodesk.Revit.DB;
5 | using HLApps.Revit.Geometry;
6 |
7 | namespace HLApps.Revit.Utils
8 | {
9 | class GeoUtils
10 | {
11 | public static IEnumerable GetAllSolidsInGeometry(GeometryObject geo)
12 | {
13 | if (geo != null)
14 | {
15 | if (geo is GeometryElement)
16 | {
17 | var geoElm = geo as GeometryElement;
18 | foreach (var geoObj in geoElm.OfType())
19 | {
20 | foreach (var recursiveCat in GetAllSolidsInGeometry(geoObj))
21 | {
22 | yield return recursiveCat;
23 | }
24 | }
25 | }
26 |
27 | if (geo is GeometryInstance)
28 | {
29 | var geoInst = geo as GeometryInstance;
30 | GeometryElement geoElm = null;
31 | try
32 | {
33 | if (geoInst.Transform.IsConformal)
34 | {
35 | geoElm = geoInst.GetInstanceGeometry();
36 | }
37 | }
38 | catch
39 | {
40 | //sometimes Revit throws an error unexpectedly, (e.g. "Trf is not conformal")
41 | //so we'll swallow it for now
42 | }
43 |
44 | if (geoElm != null)
45 | {
46 | foreach (var recursiveCat in GetAllSolidsInGeometry(geoElm))
47 | {
48 | yield return recursiveCat;
49 | }
50 | }
51 | }
52 |
53 | if (geo is Solid)
54 | {
55 | yield return geo as Solid;
56 | }
57 | }
58 |
59 | }
60 |
61 |
62 | ///
63 | /// Returns an axis aligned box which for extents of only visible geometry
64 | /// Solid.GetBoundingBox method includes planes and non-visible geometry
65 | ///
66 | ///
67 | ///
68 | ///
69 | public static HLBoundingBoxXYZ GetGeoBoundingBox(Solid geoObj, Transform parentTransform)
70 | {
71 | HLBoundingBoxXYZ box = null;
72 |
73 | var sld = geoObj as Solid;
74 | foreach (var edge in sld.Edges.OfType())
75 | {
76 | foreach (var pt in edge.Tessellate())
77 | {
78 | var ptx = parentTransform.OfPoint(pt);
79 | if (box == null)
80 | {
81 | box = new HLBoundingBoxXYZ(ptx, new XYZ(0.01, 0.01, 0.01));
82 | }
83 | else
84 | {
85 | box.ExpandToContain(ptx);
86 | }
87 | }
88 | }
89 |
90 | return box;
91 | }
92 |
93 | public static bool DoBoxesIntersect(HLBoundingBoxXYZ r1, HLBoundingBoxXYZ r2, double tolerance)
94 | {
95 | return r1.Min.X <= r2.Max.X && r1.Max.X >= r2.Min.X && r1.Min.Y <= r2.Max.Y && r1.Max.Y >= r2.Min.Y && r1.Min.Z <= r2.Max.Z && r1.Max.Z >= r2.Min.Z;
96 | }
97 |
98 | //Rotate the point (x,y,z) around the vector (u,v,w)
99 | public static XYZ RotateAboutVector(XYZ point, XYZ Vector, double angle)
100 | {
101 |
102 | double u = Vector.X;
103 | double v = Vector.Y;
104 | double w = Vector.Z;
105 | double x = point.X;
106 | double y = point.Y;
107 | double z = point.Z;
108 |
109 | double ux = Vector.X * point.X;
110 | double uy = Vector.X * point.Y;
111 | double uz = Vector.X * point.Z;
112 | double vx = Vector.Y * point.X;
113 | double vy = Vector.Y * point.Y;
114 | double vz = Vector.Y * point.Z;
115 | double wx = Vector.Z * point.X;
116 | double wy = Vector.Z * point.Y;
117 | double wz = Vector.Z * point.Z;
118 | double sa = Math.Sin(angle);
119 | double ca = Math.Cos(angle);
120 | x = u * (ux + vy + wz) + (x * (v * v + w * w) - u * (vy + wz)) * ca + (-wy + vz) * sa;
121 | y = v * (ux + vy + wz) + (y * (u * u + w * w) - v * (ux + wz)) * ca + (wx - uz) * sa;
122 | z = w * (ux + vy + wz) + (z * (u * u + v * v) - w * (ux + vy)) * ca + (-vx + uy) * sa;
123 |
124 | return new XYZ(x, y, z);
125 | }
126 |
127 |
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Graph/MEPNodeEdge.cs:
--------------------------------------------------------------------------------
1 | //using Newtonsoft.Json.Serialization;
2 | using System.Collections.Generic;
3 | using HLApps.MEPGraph.Model;
4 |
5 | namespace HLApps.Revit.Graph
6 | {
7 |
8 | public class MEPRevitEdge
9 | {
10 |
11 | public MEPRevitEdge(int index, MEPRevitNode owner, MEPRevitNode next, MEPPathDirection direction) : this()
12 | {
13 | ThisConnectorIndex = index;
14 | NextNode = next;
15 | ThisNode = owner;
16 | Direction = direction;
17 | }
18 |
19 | public MEPRevitEdge(int index, int systemId, MEPRevitNode owner, MEPRevitNode next, MEPPathDirection direction) : this(index, owner, next, direction)
20 | {
21 | SystemId = SystemId;
22 | }
23 |
24 | public MEPRevitEdge()
25 | {
26 | Length = 0;
27 | }
28 |
29 | public int SystemId { get; set; }
30 | public int ThisConnectorIndex { get; set; }
31 | public int NextConnectorIndex { get; set; }
32 |
33 | string _Description;
34 | public string Description
35 | {
36 | get
37 | {
38 | return _Description;
39 | }
40 | set
41 | {
42 | _Description = value;
43 | SetWeight("Description", value);
44 | }
45 |
46 | }
47 |
48 | public MEPRevitNode NextNode { get; set; }
49 |
50 | public MEPRevitEdge Reverse { get; set; }
51 |
52 | public Autodesk.Revit.DB.XYZ ThisOrigin { get; set; }
53 | public Autodesk.Revit.DB.XYZ NextOrigin { get; set; }
54 |
55 | public MEPRevitNode ThisNode { get; set; }
56 |
57 | MEPPathConnectionType _ConnectionType = MEPPathConnectionType.Analytical;
58 | public MEPPathConnectionType ConnectionType
59 | {
60 | get
61 | {
62 | return _ConnectionType;
63 | }
64 | set
65 | {
66 | _ConnectionType = value;
67 | SetWeight("ConnectionType", value.ToString());
68 | }
69 |
70 | }
71 |
72 | MEPPathDirection _Direction;
73 | public MEPPathDirection Direction {
74 | get
75 | {
76 | return _Direction;
77 | }
78 | set
79 | {
80 | _Direction = value;
81 | SetWeight("Direction", value.ToString());
82 | }
83 | }
84 |
85 |
86 | Dictionary _weights = new Dictionary();
87 | public Dictionary Weights
88 | {
89 | get
90 | {
91 | return _weights;
92 | }
93 |
94 | }
95 |
96 |
97 | public object GetWeight(string name)
98 | {
99 | if (Weights.ContainsKey(name))
100 | {
101 | return Weights[name];
102 | }
103 | else
104 | {
105 | throw new System.Exception("Node does not contain weight: " + name);
106 | }
107 | }
108 |
109 | public void SetWeight(string name, object value)
110 | {
111 | if (Weights.ContainsKey(name))
112 | {
113 | Weights[name] = value;
114 | }
115 | else
116 | {
117 | Weights.Add(name, value);
118 | }
119 | }
120 |
121 | public double Flow
122 | {
123 | get
124 | {
125 | return Weights.ContainsKey("Flow") ? (double)GetWeight("Flow") : 0;
126 | }
127 | set
128 | {
129 | SetWeight("Flow", value);
130 | }
131 | }
132 |
133 | public double Length
134 | {
135 | get
136 | {
137 | return Weights.ContainsKey("Length") ? (double)GetWeight("Length") : 0;
138 | }
139 | set
140 | {
141 | SetWeight("Length", value);
142 | }
143 | }
144 |
145 |
146 | Edge _edge;
147 | public Edge AsNodeEdge
148 | {
149 | get
150 | {
151 | if (_edge ==null) _edge = new Edge();
152 |
153 | return _edge;
154 | }
155 | }
156 |
157 |
158 | }
159 |
160 | public class MEPConnectorNodeEdge : MEPRevitEdge
161 | {
162 |
163 | public MEPConnectorNodeEdge(int index, MEPRevitNode owner, MEPRevitNode next, MEPPathDirection direction) : base(index, owner, next, direction)
164 | {
165 | }
166 |
167 | public MEPConnectorNodeEdge(int index, int systemId, MEPRevitNode owner, MEPRevitNode next, MEPPathDirection direction) : base(index, systemId, owner, next, direction)
168 | {
169 | }
170 |
171 |
172 |
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Geometry/Octree/BoundsOctreeElementWriter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Autodesk.Revit.DB;
3 | using HLApps.Revit.Utils;
4 |
5 | namespace HLApps.Revit.Geometry.Octree
6 | {
7 |
8 | public class BoundsOctreeElementWriter
9 | {
10 |
11 | BoundsOctree _boundsStree;
12 | Dictionary _geoOptionsOverrides;
13 | Options defaultGeomOptions;
14 |
15 | public BoundsOctreeElementWriter(BoundsOctree boundsStree)
16 | {
17 | _geoOptionsOverrides = new Dictionary();
18 | _boundsStree = boundsStree;
19 | var fineGeoOp = new Options();
20 | fineGeoOp.DetailLevel = ViewDetailLevel.Fine;
21 |
22 | var courseGeomOptions = new Options();
23 | courseGeomOptions.DetailLevel = ViewDetailLevel.Coarse;
24 |
25 |
26 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_PipeCurves, fineGeoOp);
27 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_PipeSegments, fineGeoOp);
28 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_PipeFitting, fineGeoOp);
29 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_PipeAccessory, fineGeoOp);
30 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_FlexPipeCurves, fineGeoOp);
31 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_FlexDuctCurves, fineGeoOp);
32 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_Windows, fineGeoOp);
33 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_Doors, courseGeomOptions);
34 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_Roofs, fineGeoOp);
35 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_Floors, fineGeoOp);
36 | _geoOptionsOverrides.Add((int)BuiltInCategory.OST_Ceilings, fineGeoOp);
37 |
38 |
39 | defaultGeomOptions = new Options();
40 | defaultGeomOptions.DetailLevel = ViewDetailLevel.Medium;
41 |
42 | }
43 |
44 | Dictionary> SegmentCache = new Dictionary>();
45 |
46 | public void AddElement(ICollection elements, bool includeGeometry)
47 | {
48 | foreach (var elm in elements)
49 | {
50 | AddElement(elm, includeGeometry);
51 | }
52 | }
53 |
54 | public void AddElement(Element elm, bool includeGeometry, Transform tx = null)
55 | {
56 | if (_boundsStree == null || elm == null)
57 | {
58 | return;
59 | }
60 |
61 |
62 | var elmid = elm.Id.IntegerValue;
63 |
64 | HashSet segList;
65 |
66 | if (SegmentCache.ContainsKey(elmid))
67 | {
68 | segList = SegmentCache[elmid];
69 | }
70 | else
71 | {
72 | segList = new HashSet();
73 | }
74 |
75 | if (includeGeometry || elm is FamilyInstance)
76 | {
77 | var gop = defaultGeomOptions;
78 | if (elm.Category != null && _geoOptionsOverrides.ContainsKey(elm.Category.Id.IntegerValue))
79 | {
80 | gop = _geoOptionsOverrides[elm.Category.Id.IntegerValue];
81 | }
82 |
83 | var egeo = elm.get_Geometry(gop);
84 | if (egeo == null) return;
85 |
86 | if (tx != null) egeo = egeo.GetTransformed(tx);
87 |
88 | var allSolids = GeoUtils.GetAllSolidsInGeometry(egeo);
89 | foreach (var sld in allSolids)
90 | {
91 | if (!solidIsValid(sld))
92 | {
93 | continue;
94 | }
95 |
96 | var hlbbox = GeoUtils.GetGeoBoundingBox(sld, Transform.Identity);
97 | if (hlbbox == null) continue;
98 | var geoSegment = new SolidGeometrySegment(sld, elm, hlbbox);
99 | segList.Add(geoSegment);
100 | _boundsStree.Add(geoSegment, hlbbox);
101 | }
102 | }
103 |
104 | if (elm.Location is LocationCurve)
105 | {
106 | var curve = elm.Location as LocationCurve;
107 | if (curve == null) return;
108 | var acCurve = curve.Curve;
109 |
110 | if (tx != null) acCurve = acCurve.CreateTransformed(tx);
111 |
112 | var cseg = new CurveGeometrySegment(acCurve, elm);
113 | segList.Add(cseg);
114 | _boundsStree.Add(cseg, cseg.Bounds);
115 | }
116 |
117 |
118 | if (!SegmentCache.ContainsKey(elmid))
119 | {
120 | SegmentCache.Add(elmid, segList);
121 |
122 | }
123 |
124 |
125 |
126 | }
127 |
128 |
129 | public BoundsOctree OcTree
130 | {
131 | get
132 | {
133 | return _boundsStree;
134 | }
135 | }
136 |
137 |
138 |
139 | double _minVolume = 0.1;
140 | private bool solidIsValid(Solid sld)
141 | {
142 | return sld != null && sld.Volume > _minVolume;
143 | }
144 |
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Parameters/HLRevitElementProperty.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Autodesk.Revit.DB;
4 |
5 | namespace HLApps.Revit.Parameters
6 | {
7 | public class HLRevitElementProperty : HLRevitElementData
8 | {
9 | string _name;
10 | object _value;
11 | Type _ExpectedType;
12 | StorageType _storageType;
13 | object _baseObj = null;
14 | bool _isReadOnly = true;
15 | int _elementdId = -1;
16 |
17 | public HLRevitElementProperty(int elmId, string name, object value, StorageType storageTyp)
18 | {
19 | _name = name;
20 | _value = value;
21 | _ExpectedType = value.GetType();
22 | _storageType = storageTyp;
23 | _isValid = true;
24 | _elementdId = elmId;
25 | }
26 |
27 | public HLRevitElementProperty(int elmId, string name, object value, StorageType storageTyp, object baseObj)
28 | {
29 | _name = name;
30 | _value = value;
31 | _ExpectedType = value.GetType();
32 | _storageType = storageTyp;
33 | _baseObj = baseObj;
34 | _isValid = true;
35 | _elementdId = elmId;
36 | }
37 |
38 | public HLRevitElementProperty(string name, object baseObj)
39 | {
40 | _name = name;
41 | _baseObj = baseObj;
42 |
43 | var prop = _baseObj.GetType().GetProperties().FirstOrDefault(pr => pr.Name == _name);
44 |
45 | var bt = _baseObj.GetType().BaseType;
46 | var propbt = bt.GetProperties().FirstOrDefault(pr => pr.Name == _name);
47 |
48 | var allProps = baseObj.GetType().GetProperties().Select(p => p.Name).ToList();
49 | if (prop != null)
50 | {
51 | _ExpectedType = prop.PropertyType;
52 | _storageType = Autodesk.Revit.DB.StorageType.None;
53 | if (prop.GetGetMethod() != null)
54 | {
55 | _value = prop.GetValue(baseObj, null);
56 | _isValid = true;
57 | }
58 | else
59 | {
60 | // _value = baseObj.GetPropertyValue(name);
61 | }
62 |
63 | _isReadOnly = !prop.CanWrite;
64 | }
65 | }
66 |
67 | public override string Name
68 | {
69 | get
70 | {
71 | return _name;
72 | }
73 | }
74 |
75 | public override object Value
76 | {
77 | get
78 | {
79 | return _value;
80 | }
81 | set
82 | {
83 | if (_baseObj != null)
84 | {
85 | var prop = _baseObj.GetType().GetProperties().FirstOrDefault(pr => pr.Name == _name);
86 |
87 | if (prop != null)
88 | {
89 | prop.SetValue(_baseObj, value, null);
90 | }
91 | }
92 | }
93 | }
94 |
95 | public override Type ExpectedType
96 | {
97 | get
98 | {
99 | return _ExpectedType;
100 | }
101 | }
102 |
103 | public override string StringValue
104 | {
105 | get
106 | {
107 | if (_value is Category)
108 | {
109 | return (_value as Category).Name;
110 | }
111 | else if (_value is Element)
112 | {
113 | return (_value as Element).Name;
114 | }
115 |
116 | return _value.ToString();
117 | }
118 | set
119 | {
120 |
121 | Value = value;
122 | }
123 |
124 | }
125 |
126 | public override StorageType StorageType
127 | {
128 | get
129 | {
130 | return _storageType;
131 | }
132 | }
133 |
134 | public override bool IsReadOnly
135 | {
136 | get
137 | {
138 | return _isReadOnly;
139 | }
140 | }
141 |
142 | bool _isValid = false;
143 | public bool IsValid
144 | {
145 | get { return _isValid; }
146 | }
147 |
148 | public override int IntElementId
149 | {
150 | get
151 | {
152 | return _elementdId;
153 | }
154 | }
155 |
156 | protected override void OnDisposing()
157 | {
158 |
159 | }
160 | }
161 |
162 | /*
163 | *Name property on element has no Get?? this soultion didn't work
164 | public static class ObjectExtensions
165 | {
166 | public static Object GetPropertyValue(this Object obj, String propertyName)
167 | {
168 | if (obj == null) throw new ArgumentNullException("obj", "`obj` cannot be null");
169 |
170 | var fields = from f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
171 | where f.Name.Contains(String.Format("<{0}>", propertyName))
172 | select f;
173 |
174 | if (fields.Any())
175 | {
176 | return fields.First().GetValue(obj);
177 | }
178 |
179 | return null;
180 | }
181 | } */
182 |
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph/Parameters/HLRevitReadonlyTextData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.DB;
3 |
4 | namespace HLApps.Revit.Parameters
5 | {
6 | public class HLRevitReadonlyTextData : HLRevitElementData
7 | {
8 | int _elmId;
9 | string _value;
10 | string _Name;
11 |
12 | public HLRevitReadonlyTextData(ElementId elementId, string value, string name)
13 | {
14 | _elmId = elementId.IntegerValue;
15 | _value = value;
16 | _Name = name;
17 | }
18 |
19 | public override Type ExpectedType
20 | {
21 | get
22 | {
23 | return typeof(string);
24 | }
25 | }
26 |
27 | public override int IntElementId
28 | {
29 | get
30 | {
31 | return _elmId;
32 | }
33 | }
34 |
35 | public override bool IsReadOnly
36 | {
37 | get
38 | {
39 | return true;
40 | }
41 | }
42 |
43 | public override string Name
44 | {
45 | get
46 | {
47 | return _Name;
48 | }
49 | }
50 |
51 | public override StorageType StorageType
52 | {
53 | get
54 | {
55 | return StorageType.String;
56 | }
57 | }
58 |
59 | public override string StringValue
60 | {
61 | get
62 | {
63 | return _value;
64 | }
65 |
66 | set
67 | {
68 | _value = value;
69 | }
70 | }
71 |
72 | public override object Value
73 | {
74 | get
75 | {
76 | return StringValue;
77 | }
78 | set
79 | {
80 | StringValue = value != null ? value.ToString() : string.Empty;
81 | }
82 | }
83 |
84 | protected override void OnDisposing()
85 | {
86 |
87 | }
88 | }
89 |
90 |
91 | public class HLRevitReadonlyData : HLRevitElementData
92 | {
93 | int _elmId;
94 | object _value;
95 | string _Name;
96 |
97 | public HLRevitReadonlyData(ElementId elementId, object value, string name)
98 | {
99 | _elmId = elementId.IntegerValue;
100 | _value = value;
101 | _Name = name;
102 |
103 | _storageType = StorageType.None;
104 | if (value is int)
105 | {
106 | _storageType = StorageType.Integer;
107 | }
108 | else if (value is double)
109 | {
110 | _storageType = StorageType.Double;
111 | }
112 | else if (value is string)
113 | {
114 | _storageType = StorageType.String;
115 | }
116 | else if (value is ElementId)
117 | {
118 | _storageType = StorageType.ElementId;
119 | }
120 | }
121 |
122 |
123 | public override Type ExpectedType
124 | {
125 | get
126 | {
127 | return typeof(string);
128 | }
129 | }
130 |
131 | public override int IntElementId
132 | {
133 | get
134 | {
135 | return _elmId;
136 | }
137 | }
138 |
139 | public override bool IsReadOnly
140 | {
141 | get
142 | {
143 | return true;
144 | }
145 | }
146 |
147 | public override string Name
148 | {
149 | get
150 | {
151 | return _Name;
152 | }
153 | }
154 |
155 | StorageType _storageType;
156 | public override StorageType StorageType
157 | {
158 | get
159 | {
160 | return _storageType;
161 | }
162 | }
163 |
164 | public override string StringValue
165 | {
166 | get
167 | {
168 | return _value != null ? _value.ToString() : string.Empty;
169 | }
170 | set
171 | {
172 | throw new Exception("Value is read only");
173 | }
174 | }
175 |
176 | public override object Value
177 | {
178 | get
179 | {
180 | return _value;
181 | }
182 | set
183 | {
184 | _value = value;
185 | }
186 | }
187 |
188 | protected override void OnDisposing()
189 | {
190 |
191 | }
192 | }
193 | /*
194 | *Name property on element has no Get?? this soultion didn't work
195 | public static class ObjectExtensions
196 | {
197 | public static Object GetPropertyValue(this Object obj, String propertyName)
198 | {
199 | if (obj == null) throw new ArgumentNullException("obj", "`obj` cannot be null");
200 |
201 | var fields = from f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
202 | where f.Name.Contains(String.Format("<{0}>", propertyName))
203 | select f;
204 |
205 | if (fields.Any())
206 | {
207 | return fields.First().GetValue(obj);
208 | }
209 |
210 | return null;
211 | }
212 | } */
213 |
214 |
215 | }
216 |
--------------------------------------------------------------------------------
/HLApps.MEPGraph/Neo4j/Neo4jClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using Neo4j.Driver.V1;
6 |
7 | namespace HLApps.MEPGraph
8 | {
9 | public class Neo4jClient : IDisposable, IGraphDBClient
10 | {
11 |
12 | IDriver _driver;
13 | public Neo4jClient(Uri host, string userName, string password)
14 | {
15 | _driver = GraphDatabase.Driver(host, AuthTokens.Basic(userName, password));
16 | }
17 |
18 | ///
19 | /// MATCH(a),(b)
20 | /// WHERE ID(a) = $fromNodeId AND ID(b) = $toNodeId
21 | /// CREATE (a)-[r: $relType $variables ]->(b)
22 | ///
23 | ///
24 | ///
25 | ///
26 | ///
27 | public void Relate(long fromNodeId, long toNodeId, Model.MEPEdgeTypes relType, Dictionary variables)
28 | {
29 | Dictionary props = new Dictionary();
30 | props.Add("auid", fromNodeId);
31 | props.Add("buid", toNodeId);
32 |
33 | string query = string.Empty;
34 | if (variables != null && variables.Count > 0)
35 | {
36 | props.Add("cvar", variables);
37 | query =
38 | "MATCH(a),(b)" +
39 | "WHERE ID(a) = $auid AND ID(b) = $buid " +
40 | string.Format("CREATE (a)-[r: {0} $cvar]->(b) ", relType);
41 | }
42 | else
43 | {
44 | query =
45 | "MATCH(a),(b)" +
46 | "WHERE ID(a) = $auid AND ID(b) = $buid " +
47 | string.Format("CREATE (a)-[r: {0}]->(b) ", relType);
48 | }
49 |
50 |
51 | using (var session = _driver.Session())
52 | {
53 | var greeting = session.WriteTransaction(tx =>
54 | {
55 | var result = props.Count > 0 ? tx.Run(query, props) : tx.Run(query);
56 | return result;
57 | });
58 |
59 | Console.WriteLine(greeting);
60 | }
61 |
62 |
63 | }
64 |
65 |
66 | public void Relate(Model.Node fromNode, Model.Node toNode, string relType, Dictionary variables)
67 | {
68 | Dictionary props = new Dictionary();
69 | props.Add("auid", fromNode.UniqueId);
70 | props.Add("buid", toNode.UniqueId);
71 |
72 | string query = string.Empty;
73 | if (variables != null && variables.Count > 0)
74 | {
75 | props.Add("cvar", variables);
76 | query =
77 | string.Format("MATCH(a:{0}),(b:{1})", fromNode.Label, toNode.Label) +
78 | "WHERE a.UniqueId = $auid AND b.UniqueId = $buid " +
79 | string.Format("CREATE (a)-[r: {0} $cvar]->(b) ", relType);
80 | }
81 | else
82 | {
83 | query =
84 | string.Format("MATCH(a:{0}),(b:{1})", fromNode.Label, toNode.Label) +
85 | "WHERE a.UniqueId = $auid AND b.UniqueId = $buid " +
86 | string.Format("CREATE (a)-[r: {0}]->(b) ", relType);
87 | }
88 |
89 |
90 | using (var session = _driver.Session())
91 | {
92 | var greeting = session.WriteTransaction(tx =>
93 | {
94 | var result = props.Count > 0 ? tx.Run(query, props) : tx.Run(query);
95 | return result;
96 | });
97 |
98 | Console.WriteLine(greeting);
99 | }
100 |
101 | }
102 |
103 | public long Push(Model.Node node, Dictionary variables)
104 | {
105 | Dictionary props = new Dictionary();
106 | props.Add("props", variables);
107 |
108 |
109 | var nodeLabel = node.Label;
110 | var query = string.Format("CREATE (n:{0} $props) RETURN ID(n)", nodeLabel);
111 |
112 | IStatementResult retId;
113 |
114 | using (var session = _driver.Session())
115 | {
116 | retId = session.WriteTransaction(tx =>
117 | {
118 | var result = props.Count > 0 ? tx.Run(query, props) : tx.Run(query);
119 | return result;
120 | });
121 |
122 | }
123 |
124 | if (retId != null)
125 | {
126 | var lr = retId.ToList();
127 | if (lr.Count() == 1)
128 | {
129 | var rs = lr.First();
130 | if (rs.Values.Count() == 1)
131 | {
132 | var rtval = rs.Values.First().Value;
133 | return (long)rtval;
134 | }
135 | }
136 |
137 | }
138 | return -1;
139 |
140 | }
141 |
142 | #region IDisposable Support
143 | private bool disposedValue = false; // To detect redundant calls
144 |
145 | protected virtual void Dispose(bool disposing)
146 | {
147 | if (!disposedValue)
148 | {
149 | if (disposing)
150 | {
151 | if (_driver != null) _driver.Dispose();
152 | }
153 | disposedValue = true;
154 | }
155 | }
156 |
157 | // This code added to correctly implement the disposable pattern.
158 | public void Dispose()
159 | {
160 | // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
161 | Dispose(true);
162 | }
163 | #endregion
164 |
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/UI/GraphAppWindow.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
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 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | Traverses all pipes, ducts and cable trays, adds them to the graph and connects them up. Lengths, flow rates, all parameters, and relationships to spaces and levels are included.
89 |
90 | Traverses all circuits, adds them to the graph and connects them up. All parameters, wires, and relationships to spaces and levels are included.
91 |
92 | Interrogates the geometry by ray trace to find simplified bounding surfaces between spaces. Surfaces on the same element (wall/door/window) which face the same direction count as a single surface node. Warning: For large models this might take a long time.
93 |
94 |
95 |
96 |
97 |
98 |
99 |
102 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/HLApps.Revit.Graph.UIAddin/UI/ViewModel/Command.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace HLApps.Revit.Graph.UIAddin.ViewModel
5 | {
6 |
7 | ///
8 | /// The ViewModelCommand class - an ICommand that can fire a function.
9 | ///
10 | public class Command : ICommand
11 | {
12 | ///
13 | /// Initializes a new instance of the class.
14 | ///
15 | /// The action.
16 | /// if set to true [can execute].
17 | public Command(Action action, bool canExecute = true)
18 | {
19 | // Set the action.
20 | this.action = action;
21 | this.canExecute = canExecute;
22 | }
23 |
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | /// The parameterized action.
28 | /// if set to true [can execute].
29 | public Command(Action