Exemplo n.º 1
0
        void scanFromDocument(MEPRevitGraph graph, Document doc, Transform tr, Document spaceSourceDoc)
        {
            var doorCol = new FilteredElementCollector(doc);
            var doors   = doorCol.OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements().OfType <FamilyInstance>();

            foreach (var door in doors)
            {
                if (door.Location == null)
                {
                    continue;
                }

                var ho = door.FacingFlipped ? door.FacingOrientation.Negate() : door.FacingOrientation;
                //var bbox = door.get_BoundingBox(null);
                var midPoint = (door.Location as LocationPoint).Point + new XYZ(0, 0, 1);
                //if (bbox != null)
                //{
                //    midPoint = (bbox.Min + bbox.Max) / 2;
                //}

                //get point in front
                var hfOrt        = ho.Normalize();
                var frontPos     = midPoint + hfOrt.Multiply(1.64042);           //stub is 1.64042 feet (0.5 meters)
                var lpFrontPoint = tr.OfPoint(frontPos);
                var spFront      = spaceSourceDoc.GetSpaceAtPoint(lpFrontPoint); //, phase);


                //get point behind
                var hbOrt         = ho.Negate().Normalize();
                var behindPos     = midPoint + hbOrt.Multiply(1.64042);            //stub is 1.64042 feet (0.5 meters)
                var lpBehindPoint = tr.OfPoint(behindPos);
                var spBehind      = spaceSourceDoc.GetSpaceAtPoint(lpBehindPoint); //, phase);



                if (spFront != null)
                {
                    var edges = graph.AddConnection(spFront, door, midPoint, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO);
                    edges.ThisNode.OrginTransform = tr;
                }

                if (spBehind != null)
                {
                    var edges = graph.AddConnection(door, spBehind, midPoint, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO);
                    edges.ThisNode.OrginTransform = tr;
                }
            }
        }
Exemplo n.º 2
0
        public void ScanFromDocument(Document doc, MEPRevitGraph graph, int maxDepth)
        {
            Dictionary <int, HashSet <FamilyInstance> > spaceToDoors = new Dictionary <int, HashSet <FamilyInstance> >();

            scanFromDocument(graph, doc, Transform.Identity, doc);

            //get linked documents
            foreach (RevitLinkInstance linkedInstance in DocUtils.GetLinkInstances(doc))
            {
                //RevitLinkType linkType = (RevitLinkType)doc.GetElement(linkedInstance.GetTypeId()) as RevitLinkType;

                //ExternalFileReference exfRef = linkType.GetExternalFileReference();

                //if (exfRef.GetLinkedFileStatus() != LinkedFileStatus.Loaded) continue;


                var ldoc = linkedInstance.GetLinkDocument();
                if (ldoc == null)
                {
                    continue;
                }
                scanFromDocument(graph, ldoc, linkedInstance.GetTotalTransform().Inverse, doc);
            }
        }
Exemplo n.º 3
0
        protected void ScanSpacesFromElement(Element elm, MEPRevitGraph graph, HashSet <int> scannedElements)
        {
            var doc = elm.Document;

            if (elm is FamilyInstance) //elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal || elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MechanicalEquipment)
            {
                var fi  = elm as FamilyInstance;
                var org = (elm.Location as LocationPoint).Point;
                var pos = (elm.Location as LocationPoint).Point;

                var   phase = doc.GetElement(elm.CreatedPhaseId) as Phase;
                var   sp    = elm.Document.GetSpaceAtPoint(pos, phase);
                Level lvl   = null;

                if (sp == null)
                {
                    var lvPAram = elm.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM);
                    if (lvPAram != null)
                    {
                        lvl = doc.GetElement(lvPAram.AsElementId()) as Level;
                        if (lvl != null)
                        {
                            var lvPs = new XYZ(pos.X, pos.Y, lvl.ProjectElevation + 1);
                            sp = elm.Document.GetSpaceAtPoint(lvPs, phase);
                        }
                    }
                }


                if (sp == null)
                {
                    var lvPAram = elm.get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM);
                    if (lvPAram != null)
                    {
                        lvl = doc.GetElement(lvPAram.AsElementId()) as Level;
                        if (lvl != null)
                        {
                            var lvPs = new XYZ(pos.X, pos.Y, lvl.ProjectElevation + 1);
                            sp = elm.Document.GetSpaceAtPoint(lvPs, phase);
                        }
                    }
                }

                if (sp == null)
                {
                    var hxOrt = fi.HandOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(1.64042); //stub is 1.64042 feet (0.5 meters)
                    sp  = elm.Document.GetSpaceAtPoint(pos, phase);
                }

                if (sp == null)
                {
                    var hxOrt = fi.HandOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(-1.64042); //stub is 1.64042 feet (0.5 meters)
                    sp  = elm.Document.GetSpaceAtPoint(pos, phase);
                }


                if (sp == null)
                {
                    pos = org + new XYZ(0, 0, -4);
                    sp  = elm.Document.GetSpaceAtPoint(pos, phase);
                }

                if (sp != null)
                {
                    scannedElements.Add(sp.Id.IntegerValue);

                    graph.AddConnection(elm, sp, pos, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.IS_IN_SPACE);

                    if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal)
                    {
                        //try to find out if this terminal is supply or extract
                        ConnectorManager currentCm = MEPUtils.GetConnectionManager(elm);

                        var inConn = currentCm != null?currentCm.Connectors.OfType <Connector>().Where(cn =>
                                                                                                       cn.Domain == Autodesk.Revit.DB.Domain.DomainHvac &&
                                                                                                       (cn.ConnectorType == ConnectorType.End || cn.ConnectorType == ConnectorType.Curve) &&
                                                                                                       cn.Direction == FlowDirectionType.In).FirstOrDefault() : null;

                        if (inConn != null)
                        {
                            graph.AddConnection(elm, sp, pos, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                        else
                        {
                            graph.AddConnection(sp, elm, pos, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                    }
                }

                if (lvl != null)
                {
                    graph.AddConnection(elm, lvl, MEPPathConnectionType.Proximity, MEPGraph.Model.MEPEdgeTypes.IS_ON);
                }
            }
        }
Exemplo n.º 4
0
        protected void ScanSpacesFromElement(Connector conn, MEPRevitGraph graph, HashSet <int> scannedElements, bool connectFlow)
        {
            var elm = conn.Owner;
            var doc = elm.Document;

            var phase = doc.GetElement(elm.CreatedPhaseId) as Phase;
            var org   = conn.Origin;
            var pos   = conn.Origin;

            var   sp  = elm.Document.GetSpaceAtPoint(pos, phase);
            Level lvl = null;

            if (sp == null)
            {
                var lvPAram = elm.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM);
                if (lvPAram != null)
                {
                    lvl = doc.GetElement(lvPAram.AsElementId()) as Level;
                    if (lvl != null)
                    {
                        var lvPs = new XYZ(pos.X, pos.Y, lvl.ProjectElevation + 1);
                        sp = elm.Document.GetSpaceAtPoint(lvPs, phase);
                    }
                }
            }


            if (sp == null)
            {
                var lvPAram = elm.get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM);
                if (lvPAram != null)
                {
                    lvl = doc.GetElement(lvPAram.AsElementId()) as Level;
                    if (lvl != null)
                    {
                        var lvPs = new XYZ(pos.X, pos.Y, lvl.ProjectElevation + 1);
                        sp = elm.Document.GetSpaceAtPoint(lvPs, phase);
                    }
                }
            }

            //this check is needed!
            if (sp == null)
            {
                var p1   = XYZ.BasisZ;
                var p2   = conn.CoordinateSystem.OfVector(p1).Normalize();
                var tp2  = p2 * 0.2;
                var pos2 = pos + tp2;


                sp = elm.Document.GetSpaceAtPoint(pos2, phase);

                if (sp == null && lvl != null)
                {
                    pos2 = new XYZ(pos2.X, pos2.Y, lvl.ProjectElevation + 1);
                    sp   = elm.Document.GetSpaceAtPoint(pos2, phase);
                }
            }

            if (connectFlow && (elm is Autodesk.Revit.DB.Mechanical.Duct) || (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctFitting))
            {
                if (sp != null)
                {
                    scannedElements.Add(sp.Id.IntegerValue);

                    if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal)
                    {
                        if (conn.Domain == Autodesk.Revit.DB.Domain.DomainHvac && conn.Direction == FlowDirectionType.In)
                        {
                            graph.AddConnection(elm, sp, org, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                        else
                        {
                            graph.AddConnection(sp, elm, org, MEPPathConnectionType.Analytical, MEPGraph.Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                    }
                }

                if (lvl != null)
                {
                    graph.AddConnection(elm, lvl, MEPPathConnectionType.Proximity, MEPGraph.Model.MEPEdgeTypes.IS_ON);
                }
            }

            if (elm is MEPCurve && sp != null && !graph.GetEdges(elm).Any(ed => ed.AsNodeEdge.EdgeType == MEPGraph.Model.MEPEdgeTypes.IS_IN_SPACE && ed.NextNode.OriginId == sp.Id.IntegerValue))
            {
                graph.AddConnection(elm, sp, pos, MEPPathConnectionType.Phyiscal, MEPGraph.Model.MEPEdgeTypes.IS_IN_SPACE);
            }

            //TODO: also find extents of duct which intersects space
        }
Exemplo n.º 5
0
 private void ScanElementsFromSpaces(SpatialElement space, MEPRevitGraph graph, HashSet <int> scannedElements, BoundsOctree <GeometrySegment> geoTree)
 {
 }
Exemplo n.º 6
0
 public void ScanFromElement(Element elm, MEPRevitGraph graph, int maxDepth)
 {
     //TODO: actually scan from the supplied element
     ScanFromDocument(elm.Document, graph, maxDepth);
 }
        protected void ScanSpacesFromElement(Element elm, MEPRevitGraph graph, HashSet <int> scannedElements, Transform hostTx, Document SpacesModel)
        {
            var elmDoc = elm.Document;

            var gpNode = graph.AddElement(elm, true);

            if (elm is FamilyInstance) //elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal || elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MechanicalEquipment)
            {
                var fi  = elm as FamilyInstance;
                var org = (elm.Location as LocationPoint).Point;
                var pos = (elm.Location as LocationPoint).Point;

                if (fi.HasSpatialElementCalculationPoint)
                {
                    pos = fi.GetSpatialElementCalculationPoint();
                }

                pos = hostTx.OfPoint(pos);

                Level lvl = null;
                //need to do phase mapping if elmDoc is not the same as the SpacesModel
                var phase = SpacesModel.GetElement(elm.CreatedPhaseId) as Phase;

                var sp = fi.Space;

                if (sp == null)
                {
                    sp = SpacesModel.GetSpaceAtPoint(pos, phase);
                }

                if (lvl == null)
                {
                    var lvPAram = elm.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM);
                    if (lvPAram != null)
                    {
                        lvl = elmDoc.GetElement(lvPAram.AsElementId()) as Level;
                    }
                }


                if (lvl == null)
                {
                    var lvPAram = elm.get_Parameter(BuiltInParameter.SCHEDULE_LEVEL_PARAM);
                    if (lvPAram != null)
                    {
                        lvl = elmDoc.GetElement(lvPAram.AsElementId()) as Level;
                    }
                }

                if (lvl == null && sp != null)
                {
                    lvl = sp.Level;
                }

                if (lvl == null)
                {
                    lvl = elmDoc.GetElement(fi.LevelId) as Level;
                }

                //check around element for a space
                double chDistance = 3.28084; //3.28084 = 1m

                if (sp == null)
                {
                    var hxOrt = fi.HandOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(-chDistance);
                    pos = hostTx.OfPoint(pos);
                    sp  = SpacesModel.GetSpaceAtPoint(pos, phase);
                }


                if (sp == null)
                {
                    var hxOrt = fi.HandOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(chDistance);
                    pos = hostTx.OfPoint(pos);
                    sp  = SpacesModel.GetSpaceAtPoint(pos, phase);
                }

                if (sp == null)
                {
                    var hxOrt = fi.FacingOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(-chDistance);
                    pos = hostTx.OfPoint(pos);
                    sp  = SpacesModel.GetSpaceAtPoint(pos, phase);
                }

                if (sp == null)
                {
                    var hxOrt = fi.FacingOrientation.Normalize().Negate();
                    pos = org + hxOrt.Multiply(chDistance);
                    pos = hostTx.OfPoint(pos);
                    sp  = SpacesModel.GetSpaceAtPoint(pos, phase);
                }

                if (sp == null)
                {
                    pos = org + new XYZ(0, 0, -chDistance);
                    pos = hostTx.OfPoint(pos);
                    sp  = SpacesModel.GetSpaceAtPoint(pos, phase);
                }

                if (sp != null && sp.Level != null)
                {
                    lvl = sp.Level;
                }

                if (sp == null && lvl != null)
                {
                    var lvPs = new XYZ(pos.X, pos.Y, lvl.ProjectElevation + 2);
                    lvPs = hostTx.OfPoint(lvPs);
                    sp   = elm.Document.GetSpaceAtPoint(lvPs, phase);
                }

                if (sp != null)
                {
                    scannedElements.Add(sp.Id.IntegerValue);

                    graph.AddConnection(elm, sp, pos, MEPPathConnectionType.Phyiscal, Model.MEPEdgeTypes.IS_IN_SPACE);

                    if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal)
                    {
                        //try to find out if this terminal is supply or extract
                        ConnectorManager currentCm = MEPUtils.GetConnectionManager(elm);

                        var inConn = currentCm != null?currentCm.Connectors.OfType <Connector>().Where(cn =>
                                                                                                       cn.Domain == Autodesk.Revit.DB.Domain.DomainHvac &&
                                                                                                       (cn.ConnectorType == ConnectorType.End || cn.ConnectorType == ConnectorType.Curve) &&
                                                                                                       cn.Direction == FlowDirectionType.In).FirstOrDefault() : null;

                        if (inConn != null)
                        {
                            graph.AddConnection(elm, sp, pos, MEPPathConnectionType.Analytical, Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                        else
                        {
                            graph.AddConnection(sp, elm, pos, MEPPathConnectionType.Analytical, Model.MEPEdgeTypes.FLOWS_TO_SPACE);
                        }
                    }
                }

                if (lvl != null)
                {
                    gpNode.LevelId = lvl.Id.IntegerValue;
                }
            }
        }
 protected void ScanSpacesFromElement(Element elm, MEPRevitGraph graph, HashSet <int> scannedElements)
 {
     ScanSpacesFromElement(elm, graph, scannedElements, Transform.Identity, elm.Document);
 }