示例#1
0
        public static void UpdateParameterSets(this IArchitecturalObject architecturalObject, Autodesk.Revit.DB.Element element)
        {
            Core.SAMObject sAMObject = architecturalObject 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));
        }
示例#2
0
        public static Core.SAMObject Transform(this Transform transform, Core.SAMObject sAMObject)
        {
            if (transform == null || sAMObject == null)
            {
                return(null);
            }

            if (transform.IsIdentity)
            {
                return(Core.Query.Clone(sAMObject));
            }

            if (sAMObject is Panel || sAMObject is Aperture || sAMObject is Space)
            {
                return(Transform(transform, sAMObject as dynamic));
            }

            return(Core.Query.Clone(sAMObject));
        }
示例#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)
        {
            int index;

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run))
            {
                run = false;
            }

            if (!run)
            {
                return;
            }

            index = Params.IndexOfInputParam("_pathTasTSD");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string path_TSD = null;

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

            index = Params.IndexOfInputParam("_pathTasTBD");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string path_TBD = null;

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

            index = Params.IndexOfInputParam("_analyticalObject");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Core.SAMObject sAMObject = null;
            if (!dataAccess.GetData(index, ref sAMObject) || sAMObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            bool unmetHours = false;

            index = Params.IndexOfInputParam("_runUnmetHours_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref unmetHours))
                {
                    unmetHours = true;
                }
            }

            double unmetHoursMargin = 0.5;

            index = Params.IndexOfInputParam("_unmetHoursMargin_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref unmetHoursMargin))
                {
                    unmetHoursMargin = 0.5;
                }
            }

            AdjacencyCluster adjacencyCluster = null;

            if (sAMObject is AdjacencyCluster)
            {
                adjacencyCluster = new AdjacencyCluster((AdjacencyCluster)sAMObject);
            }
            else if (sAMObject is AnalyticalModel)
            {
                adjacencyCluster = ((AnalyticalModel)sAMObject).AdjacencyCluster;
            }

            List <Core.Result> results = null;

            if (adjacencyCluster != null)
            {
                results = Analytical.Tas.Modify.AddResults(path_TSD, adjacencyCluster);

                if (unmetHours)
                {
                    List <Core.Result> results_UnmetHours = Analytical.Tas.Query.UnmetHours(path_TSD, path_TBD, unmetHoursMargin);
                    if (results_UnmetHours != null && results_UnmetHours.Count > 0)
                    {
                        foreach (Core.Result result in results_UnmetHours)
                        {
                            if (result is AdjacencyClusterSimulationResult)
                            {
                                adjacencyCluster.AddObject(result);
                                results.Add(result);
                            }
                            else if (result is SpaceSimulationResult)
                            {
                                SpaceSimulationResult spaceSimulationResult = (SpaceSimulationResult)result;

                                List <SpaceSimulationResult> spaceSimulationResults = Analytical.Tas.Query.Results(results, spaceSimulationResult);
                                if (spaceSimulationResults == null)
                                {
                                    results.Add(spaceSimulationResult);
                                }
                                else
                                {
                                    spaceSimulationResults.ForEach(x => Core.Modify.Copy(spaceSimulationResult, x, SpaceSimulationResultParameter.UnmetHourFirstIndex, SpaceSimulationResultParameter.UnmetHours, SpaceSimulationResultParameter.OccupiedUnmetHours));
                                }
                            }
                        }
                    }
                }

                adjacencyCluster = Analytical.Tas.Modify.UpdateDesignLoads(path_TBD, adjacencyCluster);

                if (sAMObject is AdjacencyCluster)
                {
                    sAMObject = adjacencyCluster;
                }
                else if (sAMObject is AnalyticalModel)
                {
                    sAMObject = new AnalyticalModel((AnalyticalModel)sAMObject, adjacencyCluster);
                }
            }

            index = Params.IndexOfOutputParam("analyticalObject");
            if (index != -1)
            {
                dataAccess.SetData(index, sAMObject);
            }

            index = Params.IndexOfOutputParam("zoneSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is ZoneSimulationResult && ((ZoneSimulationResult)x).LoadType() == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("spaceSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is SpaceSimulationResult && ((SpaceSimulationResult)x).LoadType() == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("zoneSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is ZoneSimulationResult && ((ZoneSimulationResult)x).LoadType() == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("spaceSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is SpaceSimulationResult && ((SpaceSimulationResult)x).LoadType() == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("panelSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is PanelSimulationResult && Analytical.Query.LoadType(((PanelSimulationResult)x)) == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("panelSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is PanelSimulationResult && Analytical.Query.LoadType(((PanelSimulationResult)x)) == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("_adjacencyClusterSimulationResultCooling");
            if (index != -1)
            {
                dataAccess.SetData(index, results?.Find(x => x is AdjacencyClusterSimulationResult && Analytical.Query.LoadType(((AdjacencyClusterSimulationResult)x)) == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("adjacencyClusterSimulationResultHeating");
            if (index != -1)
            {
                dataAccess.SetData(index, results?.Find(x => x is AdjacencyClusterSimulationResult && Analytical.Query.LoadType(((AdjacencyClusterSimulationResult)x)) == LoadType.Heating));
            }
        }
示例#4
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            if (document == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

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

            List <Panel> panels = null;

            if (sAMObject is Panel)
            {
                panels = new List <Panel>()
                {
                    (Panel)sAMObject
                };
            }
            else if (sAMObject is AdjacencyCluster)
            {
                panels = ((AdjacencyCluster)sAMObject).GetPanels();
            }
            else if (sAMObject is AnalyticalModel)
            {
                panels = ((AnalyticalModel)sAMObject).GetPanels();
            }

            if (panels == null || panels.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            StartTransaction(document);

            List <ElementType> elementTypes = new List <ElementType>();

            for (int i = 0; i < panels.Count; i++)
            {
                Panel panel = panels[i];
                if (panel == null)
                {
                    continue;
                }

                Geometry.Spatial.Vector3D normal = panel.Normal;
                PanelType panelType = panel.PanelType;

                if (panelType == PanelType.Air || panelType == PanelType.Undefined)
                {
                    panels[i] = Create.Panel(panel);
                    ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                    if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                    {
                        elementTypes.Add(elementType);
                    }

                    continue;
                }

                PanelType panelType_Normal = Analytical.Revit.Query.PanelType(normal);
                if (panelType_Normal == PanelType.Undefined || panelType.PanelGroup() == panelType_Normal.PanelGroup())
                {
                    panels[i] = Create.Panel(panel);
                    ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                    if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                    {
                        elementTypes.Add(elementType);
                    }

                    continue;
                }

                if (panelType.PanelGroup() == PanelGroup.Floor || panelType.PanelGroup() == PanelGroup.Roof)
                {
                    double value = normal.Unit.DotProduct(Geometry.Spatial.Vector3D.WorldY);
                    if (Math.Abs(value) <= Core.Revit.Tolerance.Tilt)
                    {
                        panels[i] = Create.Panel(panel);
                        ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                        if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                        {
                            elementTypes.Add(elementType);
                        }

                        continue;
                    }
                }

                HostObjAttributes hostObjAttributes = Analytical.Revit.Modify.DuplicateByType(document, panelType_Normal, panel.Construction) as HostObjAttributes;
                if (hostObjAttributes == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Skipped - Could not duplicate construction for {0} panel (Guid: {1}).", panel.Name, panel.Guid));
                    continue;
                }

                panels[i] = Create.Panel(panel, panelType_Normal);

                if (elementTypes.Find(x => x.Id == hostObjAttributes.Id) == null)
                {
                    elementTypes.Add(hostObjAttributes);
                }
            }


            int index_Analytical = Params.IndexOfOutputParam("analytical");

            if (index_Analytical != -1)
            {
                if (sAMObject is Panel)
                {
                    dataAccess.SetData(index_Analytical, panels?.FirstOrDefault());
                }
                else if (sAMObject is AnalyticalModel)
                {
                    AnalyticalModel analyticalModel = new AnalyticalModel((AnalyticalModel)sAMObject);
                    panels.ForEach(x => analyticalModel.AddPanel(x));
                    dataAccess.SetData(index_Analytical, analyticalModel);
                }
                else if (sAMObject is AdjacencyCluster)
                {
                    AdjacencyCluster adjacencyCluster = new AdjacencyCluster((AdjacencyCluster)sAMObject);
                    panels.ForEach(x => adjacencyCluster.AddObject(x));
                    dataAccess.SetData(index_Analytical, adjacencyCluster);
                }
            }

            int index_ElementType = Params.IndexOfOutputParam("elementType");

            if (index_ElementType != -1)
            {
                dataAccess.SetDataList(index_ElementType, elementTypes);
            }
        }
示例#5
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);
            }
        }
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;


            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            if (document == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string name = null;

            index = Params.IndexOfInputParam("_name");
            if (index == -1 || !dataAccess.GetData(index, ref name) || string.IsNullOrWhiteSpace(name))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            bool inverted = false;

            index = Params.IndexOfInputParam("inverted_");
            if (index == -1 || !dataAccess.GetData(index, ref inverted))
            {
                inverted = false;
            }

            List <string> parameterNames = new List <string>();

            index = Params.IndexOfInputParam("_parameterNames_");
            if (index == -1 || !dataAccess.GetDataList(index, parameterNames) || parameterNames.Count == 0)
            {
                parameterNames = null;
            }

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

            StartTransaction(document);

            ElementType elementType = null;

            if (sAMObject is Panel)
            {
                Panel panel = (Panel)sAMObject;

                if (inverted)
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, name, panel.PanelType, panel.Construction, parameterNames);
                }
                else
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, panel.Construction, panel.PanelType, name, parameterNames);
                }
            }
            else if (sAMObject is ApertureConstruction)
            {
                ApertureConstruction apertureConstruction = (ApertureConstruction)sAMObject;

                if (inverted)
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, name, apertureConstruction, parameterNames);
                }
                else
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, apertureConstruction, name, parameterNames);
                }
            }
            else if (sAMObject is Construction)
            {
                Construction construction = (Construction)sAMObject;

                if (construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string panelTypeString))
                {
                    PanelType panelType = Analytical.Query.PanelType(panelTypeString);
                    if (panelType != PanelType.Undefined)
                    {
                        if (inverted)
                        {
                            elementType = Analytical.Revit.Modify.DuplicateByName(document, name, panelType, construction, parameterNames);
                        }
                        else
                        {
                            elementType = Analytical.Revit.Modify.DuplicateByName(document, construction, panelType, name, parameterNames);
                        }
                    }
                }
            }
            else if (sAMObject is Aperture)
            {
                ApertureConstruction apertureConstruction = ((Aperture)sAMObject).ApertureConstruction;

                if (inverted)
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, name, apertureConstruction, parameterNames);
                }
                else
                {
                    elementType = Analytical.Revit.Modify.DuplicateByName(document, apertureConstruction, name, parameterNames);
                }
            }

            index = Params.IndexOfOutputParam("elemenType");
            if (index != -1)
            {
                dataAccess.SetData(index, elementType);
            }
        }