/// <summary>
        /// Draws an analysis zone in Dynamo.  Use this to identify which zone is which in the CreateFromMass/CreateFromMassAndLevels 'ZoneIds' output list.
        /// </summary>
        /// <param name="ZoneId">The ElementId of the zone to draw.  Get this from the AnalysisZones > CreateFrom* > ZoneIds output list</param>
        /// <returns>A list of Dynamo meshes for each zone.</returns>
        public static List <Autodesk.DesignScript.Geometry.Mesh> DrawAnalysisZone(ElementId ZoneId)
        {
            //local varaibles
            Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassZone zone   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            // get zone data from the document using the id
            try
            {
                zone = (MassZone)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(ZoneId.InternalId));

                if (zone == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a zone object with Id #: " + ZoneId.ToString());
            }


            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = zone.MassEnergyAnalyticalModelId;
                // myEnergyModelId = MassEnergyAnalyticalModel.GetMassEnergyAnalyticalModelIdForMassInstance(RvtDoc, MassFamilyInstance.InternalElement.Id);
                if (myEnergyModelId == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                //throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + MassFamilyInstance.InternalElement.Id.ToString());
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + zone.MassEnergyAnalyticalModelId.ToString());
            }

            //return a list of all fo the mesh faces for each zone
            List <Autodesk.DesignScript.Geometry.Mesh> outMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>();
            //get references to all of the faces
            IList <Reference> faceRefs = zone.GetReferencesToEnergyAnalysisFaces();

            foreach (var faceRef in faceRefs)
            {
                //get the actual face and add the converted version to our list
                Autodesk.Revit.DB.Face face = (Autodesk.Revit.DB.Face)zone.GetGeometryObjectFromReference(faceRef);
                outMeshes.Add(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(face.Triangulate()));
            }
            return(outMeshes);
        }
        public static Dictionary <string, object> DecomposeZone(ElementId ZoneId)
        {
            // local variables
            Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassZone zone   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;
            gbXMLConditionType          conditionType   = gbXMLConditionType.NoConditionType;
            gbXMLSpaceType spaceType = gbXMLSpaceType.NoSpaceType;

            // get zone data from the document using the id
            try
            {
                zone = (MassZone)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(ZoneId.InternalId));

                if (zone == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a zone object with Id #: " + ZoneId.ToString());
            }

            //get external faces belonging to this zone
            List <EnergyAnalysisForDynamo.ElementId> outWallSurfaceIds = Helper.GetSurfaceIdsFromZoneBasedOnType(zone, "Mass Exterior Wall");
            List <EnergyAnalysisForDynamo.ElementId> outRoofSurfaceIds = Helper.GetSurfaceIdsFromZoneBasedOnType(zone, "Mass Roof");

            // assign condition type
            conditionType = zone.ConditionType;

            // assign space type
            spaceType = zone.SpaceType;

            // return outputs
            return(new Dictionary <string, object>
            {
                { "WallSurfaceIds", outWallSurfaceIds },
                { "RoofSurfaceIds", outRoofSurfaceIds },
                { "SpaceType", spaceType },
                { "conditionType", conditionType }
            });
        }
        // get surface ids from zone based on type
        public static List <EnergyAnalysisForDynamo.ElementId> GetSurfaceIdsFromZoneBasedOnType(MassZone MassZone, string SurfaceTypeName = "Mass Exterior Wall")
        {
            //some faces supposedly share massSurfaceData definitions (although i think they are all unique in practice) - here we're pulling out unique data definitions.
            Dictionary <int, Autodesk.Revit.DB.Element> mySurfaceData = new Dictionary <int, Autodesk.Revit.DB.Element>();
            List <Autodesk.Revit.DB.ElementId>          SurfaceIds    = new List <Autodesk.Revit.DB.ElementId>();

            //get references to all of the faces
            IList <Reference> faceRefs = MassZone.GetReferencesToEnergyAnalysisFaces();

            foreach (var faceRef in faceRefs)
            {
                var    srfType = faceRef.GetType();
                string refType = faceRef.ElementReferenceType.ToString();

                //get the element ID of the MassSurfaceData object associated with this face
                Autodesk.Revit.DB.ElementId id = MassZone.GetMassDataElementIdForZoneFaceReference(faceRef);

                //add it to our dict if it isn't already there
                if (!mySurfaceData.ContainsKey(id.IntegerValue))
                {
                    Autodesk.Revit.DB.Element mySurface = MassZone.Document.GetElement(id);
                    //add id and surface to dictionary to keep track of data
                    mySurfaceData.Add(id.IntegerValue, mySurface);

                    if (mySurface.Category.Name == SurfaceTypeName)
                    {
                        // collect the id
                        SurfaceIds.Add(id);
                    }
                }
            }

            //loop over the output lists, and wrap them in our ElementId wrapper class
            List <ElementId> outSurfaceIds = SurfaceIds.Select(e => new ElementId(e.IntegerValue)).ToList();

            return(outSurfaceIds);
        }
Exemple #4
0
        // get surface ids from zone based on type
        public static List <EnergyAnalysisForDynamo.ElementId> GetSurfaceIdsFromZoneBasedOnType(MassZone MassZone, string SurfaceTypeName = "Mass Exterior Wall")
        {
            //some faces supposedly share massSurfaceData definitions (although i think they are all unique in practice) - here we're pulling out unique data definitions.
            Dictionary <int, MassSurfaceData> mySurfaceData = new Dictionary <int, MassSurfaceData>();

            //get references to all of the faces
            IList <Reference> faceRefs = MassZone.GetReferencesToEnergyAnalysisFaces();

            foreach (var faceRef in faceRefs)
            {
                var    srfType = faceRef.GetType();
                string refType = faceRef.ElementReferenceType.ToString();

                //get the element ID of the MassSurfaceData object associated with this face
                Autodesk.Revit.DB.ElementId id = MassZone.GetMassDataElementIdForZoneFaceReference(faceRef);

                //add it to our dict if it isn't already there
                if (!mySurfaceData.ContainsKey(id.IntegerValue))
                {
                    var mySurface = MassZone.Document.GetElement(id);
                    // Extra check to make sure the surface is not a mass floor which is
                    // a MassLevelData in REVIT. In Vasari it doesn't make any issues.
                    if (mySurface.Category.Name != "Mass Floor")
                    {
                        MassSurfaceData d = (MassSurfaceData)MassZone.Document.GetElement(id);
                        mySurfaceData.Add(id.IntegerValue, d);
                    }
                }
            }

            //filter by category = mass exterior wall
            var allSurfsList = mySurfaceData.Values.ToList();
            var extSurfList  = from n in allSurfsList
                               where n.Category.Name == SurfaceTypeName
                               select n;

            //list of element Ids to wrap and output
            List <Autodesk.Revit.DB.ElementId> surfaceIds = extSurfList.Select(e => e.Id).ToList();

            //loop over the output lists, and wrap them in our ElementId wrapper class
            List <ElementId> outSurfaceIds = surfaceIds.Select(e => new ElementId(e.IntegerValue)).ToList();

            return(outSurfaceIds);
        }
        /// <summary>
        /// Sets an analysis zone's energy parameters
        /// </summary>
        /// <param name="ZoneId">The ElementId of the zone to modify.  Get this from the AnalysisZones > CreateFrom* > ZoneIds output list</param>
        /// <param name="SpaceType">Sets the zone's space type.  Use the Space Types Dropdown node from our EnergySetting tab to specify a value.</param>
        /// <param name="ConditionType">Sets the zone's condition type.  Use the Condition Types Dropdown node from our EnergySetting tab to specify a value.</param>
        /// <returns></returns>
        public static ElementId SetZoneParameters(ElementId ZoneId, string SpaceType = "", string ConditionType = "")
        {
            //local varaibles
            Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassZone zone   = null;


            //try to get MassZone using the ID
            try
            {
                zone = (MassZone)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(ZoneId.InternalId));

                if (zone == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a zone object with Id #: " + ZoneId.ToString());
            }


            //defense
            if (!string.IsNullOrEmpty(ConditionType) && !(gbXMLConditionType.IsDefined(typeof(gbXMLConditionType), ConditionType)))
            {
                throw new Exception(ConditionType.ToString() + " is not a valid condition type. Use conditionTypes dropdown to input a valid condition type.");
            }

            if (!string.IsNullOrEmpty(SpaceType) && !(gbXMLSpaceType.IsDefined(typeof(gbXMLSpaceType), SpaceType)))
            {
                throw new Exception(SpaceType.ToString() + " is not a valid space type. Use spaceTypes dropdown to input a valid space type.");
            }

            try
            {
                //start a transaction task
                TransactionManager.Instance.EnsureInTransaction(RvtDoc);

                //set condiotn type
                if (!string.IsNullOrEmpty(ConditionType))
                {
                    zone.ConditionType = (gbXMLConditionType)Enum.Parse(typeof(gbXMLConditionType), ConditionType);
                }

                //set space type
                if (!string.IsNullOrEmpty(SpaceType))
                {
                    zone.SpaceType = (gbXMLSpaceType)Enum.Parse(typeof(gbXMLSpaceType), SpaceType);
                }

                //done with transaction task
                TransactionManager.Instance.TransactionTaskDone();
            }
            catch (Exception)
            {
                throw new Exception("Something went wrong when trying to set the parameters on zone # " + ZoneId.ToString());
            }

            //return the zone ID so the zone can be used downstream
            return(ZoneId);
        }