Beispiel #1
0
        public static IAnalyticalObject Transform(this Transform transform, IAnalyticalObject analyticalObject)
        {
            if (transform == null || analyticalObject == null)
            {
                return(null);
            }

            IAnalyticalObject result = Core.Query.Clone(analyticalObject);

            if (transform.IsIdentity)
            {
                return(result);
            }

            if (result is AirPartition)
            {
                AirPartition airPartition = (AirPartition)result;
                return(new AirPartition(airPartition.Guid, Geometry.Revit.Query.Transform(transform, airPartition.Face3D)));
            }

            if (result is IHostPartition)
            {
                return(Transform(transform, (IHostPartition)result));
            }

            if (result is Space)
            {
                Space space = (Space)result;

                space = new Space(space, space.Name, Geometry.Revit.Query.Transform(transform, space.Location));
                return(space);
            }

            return(result);
        }
Beispiel #2
0
        public static void UpdateParameterSets(this IAnalyticalObject analyticalObject, Autodesk.Revit.DB.Element element)
        {
            Core.SAMObject sAMObject = analyticalObject as Core.SAMObject;
            if (sAMObject == null)
            {
                return;
            }

            Core.Revit.Modify.UpdateParameterSets(sAMObject, element, Core.Revit.ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
        }
Beispiel #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            dataAccess.SetData(4, false);

            bool run = false;

            if (!dataAccess.GetData(2, ref run))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }
            if (!run)
            {
                return;
            }

            string path_TBD = null;

            if (!dataAccess.GetData(0, ref path_TBD) || string.IsNullOrWhiteSpace(path_TBD))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            IAnalyticalObject analyticalObject = null;

            if (!dataAccess.GetData(1, ref analyticalObject) || analyticalObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            List <SpaceSimulationResult> spaceSimulationResults_Cooling = null;
            List <SpaceSimulationResult> spaceSimulationResults_Heating = null;
            List <Space> spaces = null;
            bool         result = false;

            if (analyticalObject is AnalyticalModel)
            {
                analyticalObject = Analytical.Tas.Modify.UpdateDesignLoads(path_TBD, (AnalyticalModel)analyticalObject);
                AdjacencyCluster adjacencyCluster = ((AnalyticalModel)analyticalObject).AdjacencyCluster;
                if (adjacencyCluster != null)
                {
                    spaces = adjacencyCluster.GetSpaces();
                    if (spaces != null)
                    {
                        spaceSimulationResults_Cooling = new List <SpaceSimulationResult>();
                        spaceSimulationResults_Heating = new List <SpaceSimulationResult>();

                        foreach (Space space in spaces)
                        {
                            List <SpaceSimulationResult> spaceSimulationResults = adjacencyCluster.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source());
                            if (spaceSimulationResults == null)
                            {
                                continue;
                            }

                            spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling));
                            spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating));
                        }
                        result = true;
                    }
                }
            }
            else if (analyticalObject is BuildingModel)
            {
                BuildingModel buildingModel = new BuildingModel((BuildingModel)analyticalObject);
                spaces = Analytical.Tas.Modify.UpdateDesignLoads(buildingModel, path_TBD);
                if (spaces != null)
                {
                    spaceSimulationResults_Cooling = new List <SpaceSimulationResult>();
                    spaceSimulationResults_Heating = new List <SpaceSimulationResult>();

                    foreach (Space space in spaces)
                    {
                        List <SpaceSimulationResult> spaceSimulationResults = buildingModel.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source());
                        if (spaceSimulationResults == null)
                        {
                            continue;
                        }

                        spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling));
                        spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating));
                    }

                    result = true;
                }

                analyticalObject = buildingModel;
            }

            dataAccess.SetData(0, new GooAnalyticalObject(analyticalObject));
            dataAccess.SetDataList(1, spaces?.ConvertAll(x => new GooSpace(x)));
            dataAccess.SetDataList(2, spaceSimulationResults_Cooling?.ConvertAll(x => new GooResult(x)));
            dataAccess.SetDataList(3, spaceSimulationResults_Heating?.ConvertAll(x => new GooResult(x)));
            dataAccess.SetData(4, result);
        }
Beispiel #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index            = -1;
            int index_Successful = -1;

            index_Successful = Params.IndexOfOutputParam("successful");
            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, false);
            }

            bool run = false;

            if (!dataAccess.GetData(1, ref run) || !run)
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            IAnalyticalObject analyticalObject = null;

            index = Params.IndexOfInputParam("_analytical");
            if (index == -1 || !dataAccess.GetData(index, ref analyticalObject) || analyticalObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit_UpdateNumbers = new List <Autodesk.Revit.DB.Mechanical.Space>();

            Core.SAMObject sAMObject = analyticalObject as Core.SAMObject;
            if (sAMObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            List <Tuple <ElementId, Core.SAMObject> > tuples = new List <Tuple <ElementId, Core.SAMObject> >();

            if (sAMObject is Space)
            {
                Space space = (Space)sAMObject;

                ElementId elementId = space.ElementId();
                if (elementId == null || elementId == ElementId.InvalidElementId)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();
                    if (spaces_Revit != null)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = spaces_Revit.Find(x => x.Name != null && x.Name.Equals(space.Name));
                        if (space_Revit == null)
                        {
                            foreach (Autodesk.Revit.DB.Mechanical.Space space_Revit_Temp in spaces_Revit)
                            {
                                Parameter parameter = space_Revit_Temp?.get_Parameter(BuiltInParameter.ROOM_NAME);
                                if (parameter == null || !parameter.HasValue)
                                {
                                    continue;
                                }

                                string name = parameter.AsString();
                                if (string.IsNullOrEmpty(name))
                                {
                                    continue;
                                }

                                if (name.Equals(space.Name))
                                {
                                    space_Revit = space_Revit_Temp;
                                    break;
                                }
                            }
                        }

                        if (space_Revit != null)
                        {
                            elementId = space_Revit.Id;
                        }
                    }
                }

                tuples.Add(new Tuple <ElementId, Core.SAMObject> (elementId, space));
                if (elementId != null && elementId != ElementId.InvalidElementId)
                {
                    tuples.Add(new Tuple <ElementId, Core.SAMObject>(elementId, space.InternalCondition));
                }
            }
            else if (sAMObject is AnalyticalModel)
            {
                AnalyticalModel analyticalModel = (AnalyticalModel)sAMObject;
                List <Space>    spaces          = analyticalModel.GetSpaces();
                if (spaces != null)
                {
                    foreach (Space space in spaces)
                    {
                        ElementId elementId = space.ElementId();
                        if (elementId == null || elementId == ElementId.InvalidElementId)
                        {
                            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();
                            if (spaces_Revit != null)
                            {
                                Autodesk.Revit.DB.Mechanical.Space space_Revit = spaces_Revit.Find(x => x.Name != null && x.Name.Equals(space.Name));
                                if (space_Revit == null)
                                {
                                    foreach (Autodesk.Revit.DB.Mechanical.Space space_Revit_Temp in spaces_Revit)
                                    {
                                        Parameter parameter = space_Revit_Temp?.get_Parameter(BuiltInParameter.ROOM_NAME);
                                        if (parameter == null || !parameter.HasValue)
                                        {
                                            continue;
                                        }

                                        string name = parameter.AsString();
                                        if (string.IsNullOrEmpty(name))
                                        {
                                            continue;
                                        }

                                        if (name.Equals(space.Name))
                                        {
                                            space_Revit = space_Revit_Temp;
                                            break;
                                        }
                                    }
                                }

                                if (space_Revit != null)
                                {
                                    elementId = space_Revit.Id;
                                    spaces_Revit_UpdateNumbers.Add(space_Revit);
                                }
                            }
                        }

                        tuples.Add(new Tuple <ElementId, Core.SAMObject>(elementId, space));
                        if (elementId != null && elementId != ElementId.InvalidElementId)
                        {
                            tuples.Add(new Tuple <ElementId, Core.SAMObject>(elementId, space.InternalCondition));
                        }
                    }
                }
            }
            else
            {
                ElementId elementId = ((Core.SAMObject)analyticalObject).ElementId();
                if (elementId != null && elementId != ElementId.InvalidElementId)
                {
                    tuples.Add(new Tuple <ElementId, Core.SAMObject>(elementId, sAMObject));
                }
            }

            if (tuples == null || tuples.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cound not find matching Revit Element");
                return;
            }

            StartTransaction(document);

            List <Element> elements = new List <Element>();

            foreach (Tuple <ElementId, Core.SAMObject> tuple in tuples)
            {
                if (tuple.Item2 == null)
                {
                    continue;
                }

                if (tuple.Item1 == null || tuple.Item1 == ElementId.InvalidElementId)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Cound not find matching Revit Element for SAM Object [Guid: {0}]", tuple.Item2.Guid));
                }

                Element element = document.GetElement(tuple.Item1);
                if (element == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Cound not find matching Revit Element for SAM Object [Guid: {0}]", tuple.Item2.Guid));
                }

                Core.Revit.Modify.SetValues(element, tuple.Item2);
                Core.Revit.Modify.SetValues(element, tuple.Item2, ActiveSetting.Setting);
                Core.Revit.Modify.SetValues(element, tuple.Item2, Analytical.Revit.ActiveSetting.Setting);
                elements.Add(element);
            }

            if (spaces_Revit_UpdateNumbers != null && spaces_Revit_UpdateNumbers.Count != 0)
            {
                Analytical.Revit.Modify.UpdateNumbers(spaces_Revit_UpdateNumbers);
            }

            index = Params.IndexOfOutputParam("elements");
            if (index != -1)
            {
                dataAccess.SetDataList(0, elements);
            }

            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, true);
            }
        }