Example #1
0
 private void InitSunSettings(SunAndShadowSettings settings)
 {
     InternalSunAndShadowSettings = settings;
     InternalElementId            = settings.Id;
     InternalUniqueId             = settings.UniqueId;
     IsRevitOwned = true;
 }
Example #2
0
 private SunSettings(SunAndShadowSettings settings)
 {
     InternalSunAndShadowSettings = settings;
     InternalElementId = settings.Id;
     InternalUniqueId = settings.UniqueId;
     IsRevitOwned = true;
 }
        // Shared by Mohsen Assaqqaf in a comment on The Building Coder:
        // https://thebuildingcoder.typepad.com/blog/2013/06/sun-direction-shadow-calculation-and-wizard-update.html#comment-4614771756
        // I found that this method for getting the vector
        // of the sun does not take into account the True
        // North angle of the project, so I updated it
        // myself using the following code:
        /// <summary>
        /// Get sun direction adjusted for project true north
        /// </summary>
        static XYZ GetSunDirection(View view)
        {
            Document doc = view.Document;

            // Get sun and shadow settings from the 3D View
            SunAndShadowSettings sunSettings
                = view.SunAndShadowSettings;

            // Set the initial direction of the sun at ground level (like sunrise level)
            XYZ initialDirection = XYZ.BasisY;

            // Get the altitude of the sun from the sun settings
            double altitude = sunSettings.GetFrameAltitude(
                sunSettings.ActiveFrame);

            // Create a transform along the X axis based on the altitude of the sun
            Transform altitudeRotation = Transform
                                         .CreateRotation(XYZ.BasisX, altitude);

            // Create a rotation vector for the direction of the altitude of the sun
            XYZ altitudeDirection = altitudeRotation
                                    .OfVector(initialDirection);

            // Get the azimuth from the sun settings of the scene
            double azimuth = sunSettings.GetFrameAzimuth(
                sunSettings.ActiveFrame);

            // Correct the value of the actual azimuth with true north

            // Get the true north angle of the project
            Element projectInfoElement
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ProjectBasePoint)
                  .FirstElement();

            BuiltInParameter bipAtn
                = BuiltInParameter.BASEPOINT_ANGLETON_PARAM;

            Parameter patn = projectInfoElement.get_Parameter(
                bipAtn);

            double trueNorthAngle = patn.AsDouble();

            // Add the true north angle to the azimuth
            double actualAzimuth = 2 * Math.PI - azimuth + trueNorthAngle;

            // Create a rotation vector around the Z axis
            Transform azimuthRotation = Transform
                                        .CreateRotation(XYZ.BasisZ, actualAzimuth);

            // Finally, calculate the direction of the sun
            XYZ sunDirection = azimuthRotation.OfVector(
                altitudeDirection);

            return(sunDirection);
        }
Example #4
0
        public static Dictionary <string, object> Lighting(View view)
        {
            var v        = (Autodesk.Revit.DB.View)view.InternalElement;
            var settings = new SunAndShadowSettings(v.SunAndShadowSettings);


            return(new Dictionary <string, object>
            {
                { "SunAndShadowSettings", settings },
                { "SunlightIntensity", v.SunlightIntensity },
                { "ShadowIntensity", v.ShadowIntensity }
            });
        }
Example #5
0
 public static void viewOptions(Document doc, View view)
 {
     try
     {
         using (Transaction tx = new Transaction(doc))
         {
             SunAndShadowSettings sunSettings = view.SunAndShadowSettings;
             tx.Start("shade");
             view.DisplayStyle = DisplayStyle.FlatColors;
             tx.Commit();
         }
     }
     catch (Exception) { }
 }
Example #6
0
        void registerButt_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var activeView = DocumentManager.Instance.CurrentDBDocument.ActiveView;

            PickedSunAndShadowSettings = activeView.SunAndShadowSettings;

            if (PickedSunAndShadowSettings != null)
            {
                _sunVector = GetSunDirection(PickedSunAndShadowSettings);
                _tb.Text   = PickedSunAndShadowSettings.Name;
            }
            else
            {
                _tb.Text = "Nothing Selected";
            }
        }
Example #7
0
        /// <summary>
        /// Description of ShadowCalculatorUtils.
        /// NOTE: this is derived from Scott Connover's great class "Geometry API in Revit" from DevCamp 2012, source files accesed 6-8-12 from here 
        /// https://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Homehttps://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Home
        /// </summary>
        public static XYZ GetSunDirection(SunAndShadowSettings sunSettings)
        {
            //SunAndShadowSettings sunSettings = view.SunAndShadowSettings;

            XYZ initialDirection = XYZ.BasisY;

            //double altitude = sunSettings.Altitude;
            double altitude = sunSettings.GetFrameAltitude(sunSettings.ActiveFrame);
            Autodesk.Revit.DB.Transform altitudeRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisX, altitude);
            XYZ altitudeDirection = altitudeRotation.OfVector(initialDirection);

            //double azimuth = sunSettings.Azimuth;
            double azimuth = sunSettings.GetFrameAzimuth(sunSettings.ActiveFrame);
            double actualAzimuth = 2 * Math.PI - azimuth;
            Autodesk.Revit.DB.Transform azimuthRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisZ, actualAzimuth);
            XYZ sunDirection = azimuthRotation.OfVector(altitudeDirection);
            XYZ scaledSunVector = sunDirection.Multiply(100);

            return scaledSunVector;
        }
Example #8
0
 protected override void LoadNode(XmlNode nodeElement)
 {
     foreach (XmlNode subNode in nodeElement.ChildNodes)
     {
         if (subNode.Name.Equals("instance"))
         {
             try
             {
                 PickedSunAndShadowSettings = DocumentManager.Instance.CurrentDBDocument.GetElement(
                     new ElementId(Convert.ToInt32(subNode.Attributes[0].Value))
                     ) as SunAndShadowSettings;
                 if (PickedSunAndShadowSettings != null)
                 {
                     _tb.Text             = PickedSunAndShadowSettings.Name;
                     _sunPathButt.Content = "Use SunPath from Current View";
                 }
             }
             catch { }
         }
     }
 }
Example #9
0
        /// <summary>
        /// Description of ShadowCalculatorUtils.
        /// NOTE: this is derived from Scott Connover's great class "Geometry API in Revit" from DevCamp 2012, source files accesed 6-8-12 from here
        /// https://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Homehttps://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Home
        /// </summary>

        public static XYZ GetSunDirection(SunAndShadowSettings sunSettings)
        {
            //SunAndShadowSettings sunSettings = view.SunAndShadowSettings;

            XYZ initialDirection = XYZ.BasisY;

            //double altitude = sunSettings.Altitude;
            double altitude = sunSettings.GetFrameAltitude(sunSettings.ActiveFrame);

            Autodesk.Revit.DB.Transform altitudeRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisX, altitude);
            XYZ altitudeDirection = altitudeRotation.OfVector(initialDirection);

            //double azimuth = sunSettings.Azimuth;
            double azimuth       = sunSettings.GetFrameAzimuth(sunSettings.ActiveFrame);
            double actualAzimuth = 2 * Math.PI - azimuth;

            Autodesk.Revit.DB.Transform azimuthRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisZ, actualAzimuth);
            XYZ sunDirection    = azimuthRotation.OfVector(altitudeDirection);
            XYZ scaledSunVector = sunDirection.Multiply(100);

            return(scaledSunVector);
        }
Example #10
0
        // Shared by Mohsen Assaqqaf in a comment on The Building Coder:
        // https://thebuildingcoder.typepad.com/blog/2013/06/sun-direction-shadow-calculation-and-wizard-update.html#comment-4614771756
        // I found that this method for getting the vector
        // of the sun does not take into account the True
        // North angle of the project, so I updated it
        // myself using the following code:
        /// <summary>
        /// Get sun direction adjusted for project true north
        /// </summary>
        static XYZ GetSunDirection(View view)
        {
            Document doc = view.Document;

            // Get sun and shadow settings from the 3D View

            SunAndShadowSettings sunSettings
                = view.SunAndShadowSettings;

            // Set the initial direction of the sun
            // at ground level (like sunrise level)

            XYZ initialDirection = XYZ.BasisY;

            // Get the altitude of the sun from the sun settings

            double altitude = sunSettings.GetFrameAltitude(
                sunSettings.ActiveFrame);

            // Create a transform along the X axis
            // based on the altitude of the sun

            Transform altitudeRotation = Transform
                                         .CreateRotation(XYZ.BasisX, altitude);

            // Create a rotation vector for the direction
            // of the altitude of the sun

            XYZ altitudeDirection = altitudeRotation
                                    .OfVector(initialDirection);

            // Get the azimuth from the sun settings of the scene

            double azimuth = sunSettings.GetFrameAzimuth(
                sunSettings.ActiveFrame);

            // Correct the value of the actual azimuth with true north

            // Get the true north angle of the project

            Element projectInfoElement
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ProjectBasePoint)
                  .FirstElement();

            BuiltInParameter bipAtn
                = BuiltInParameter.BASEPOINT_ANGLETON_PARAM;

            Parameter patn = projectInfoElement.get_Parameter(
                bipAtn);

            double trueNorthAngle = patn.AsDouble();

            // Add the true north angle to the azimuth

            double actualAzimuth = 2 * Math.PI - azimuth + trueNorthAngle;

            // Create a rotation vector around the Z axis

            Transform azimuthRotation = Transform
                                        .CreateRotation(XYZ.BasisZ, actualAzimuth);

            // Finally, calculate the direction of the sun

            XYZ sunDirection = azimuthRotation.OfVector(
                altitudeDirection);

            // https://github.com/jeremytammik/the_building_coder_samples/issues/14
            // The resulting sun vector is pointing from the
            // ground towards the sun and not from the sun
            // towards the ground. I recommend reversing the
            // vector at the end before it is returned so it
            // points in the same direction as the sun rays.

            return(-sunDirection);
        }
Example #11
0
 void Controller_RevitDocumentChanged(object sender, EventArgs e)
 {
     PickedSunAndShadowSettings = null;
 }
Example #12
0
 private SunSettings(SunAndShadowSettings settings)
 {
     SafeInit(() => InitSunSettings(settings));
 }
Example #13
0
 void Controller_RevitDocumentChanged(object sender, EventArgs e)
 {
     PickedSunAndShadowSettings = null;
 }
Example #14
0
 protected override void LoadNode(XmlNode nodeElement)
 {
     foreach (XmlNode subNode in nodeElement.ChildNodes)
     {
         if (subNode.Name.Equals("instance"))
         {
             try
             {
                 PickedSunAndShadowSettings = DocumentManager.Instance.CurrentDBDocument.GetElement(
                    new ElementId(Convert.ToInt32(subNode.Attributes[0].Value))
                 ) as SunAndShadowSettings;
                 if (PickedSunAndShadowSettings != null)
                 {
                     _tb.Text = PickedSunAndShadowSettings.Name;
                     _sunPathButt.Content = "Use SunPath from Current View";
                 }
             }
             catch { }
         }
     }
 }
Example #15
0
        void registerButt_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var activeView = DocumentManager.Instance.CurrentDBDocument.ActiveView;
            PickedSunAndShadowSettings = activeView.SunAndShadowSettings;

            if (PickedSunAndShadowSettings != null)
            {
                _sunVector = GetSunDirection(PickedSunAndShadowSettings);
                _tb.Text = PickedSunAndShadowSettings.Name;
            }
            else
            {
                _tb.Text = "Nothing Selected";
            }
        }
Example #16
0
        public static void CreateTestFaces(IList <Reference> faceSelection, IList <Reference> massSelection, double analysysGridSize, UIDocument uidoc, View view)
        {
            if (faceSelection == null)
            {
                return;
            }

            var testFaces = CreateEmptyTestFaces(faceSelection, uidoc.Document);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // not required when using ReferenceIntersector
            var solids = SolidsFromReferences(massSelection, uidoc.Document);

            // create a ReferenceIntersection
            var ids = massSelection.Select(s => s.ElementId).ToList();
            var referenceIntersector = new ReferenceIntersector(ids, FindReferenceTarget.All, view as View3D);

            Transaction t = new Transaction(uidoc.Document);

            t.Start("testSolarVectorLines");

            ////create colour scheme
            SolarAnalysisColourSchemes.CreateAnalysisScheme(SolarAnalysisColourSchemes.DefaultColours, uidoc.Document, "Direct Sunlight Hours", true);
            var schemeId = SolarAnalysisColourSchemes.CreateAnalysisScheme(SolarAnalysisColourSchemes.DefaultColours, uidoc.Document, "Direct Sunlight Hours - No Legend", false);

            foreach (DirectSunTestFace testFace in testFaces)
            {
                var    boundingBox       = testFace.Face.GetBoundingBox();
                double boundingBoxUTotal = boundingBox.Max.U - boundingBox.Min.U;
                double boundingBoxVTotal = boundingBox.Max.V - boundingBox.Min.V;
                double gridDivisionsU    = boundingBoxUTotal > 2 * analysysGridSize ? (boundingBoxUTotal / analysysGridSize) : 2;
                double gridDivisionsV    = boundingBoxVTotal > 2 * analysysGridSize ? (boundingBoxVTotal / analysysGridSize) : 2;
                double gridSizeU         = boundingBoxUTotal / gridDivisionsU;
                double gridSizeV         = boundingBoxVTotal / gridDivisionsV;

                for (double u = boundingBox.Min.U + (gridSizeU / 2); u <= boundingBox.Max.U; u += gridSizeU)
                {
                    for (double v = boundingBox.Min.V + (gridSizeV / 2); v <= boundingBox.Max.V; v += gridSizeV)
                    {
                        UV uv = new UV(u, v);

                        if (testFace.Face.IsInside(uv))
                        {
                            SunAndShadowSettings setting = view.SunAndShadowSettings;
                            double interval = 1;
                            switch (setting.TimeInterval)
                            {
                            case SunStudyTimeInterval.Hour:
                                interval = 1;
                                break;

                            case SunStudyTimeInterval.Minutes30:
                                interval = 0.5;
                                break;

                            case SunStudyTimeInterval.Minutes15:
                                interval = 0.25;
                                break;

                            case SunStudyTimeInterval.Minutes45:
                                interval = 0.75;
                                break;
                            }

                            var hoursOfSun = (setting.NumberOfFrames - 1) * interval;
                            //// Autodesk makes active frame starts from 1..
                            for (int activeFrame = 1; activeFrame <= setting.NumberOfFrames; activeFrame++)
                            {
                                setting.ActiveFrame = activeFrame;
                                var start = testFace.Face.Evaluate(uv);
                                start = start.Add(testFace.Face.ComputeNormal(uv).Normalize() / 16);
                                var sunDirection = GetSunDirectionalVector(uidoc.ActiveView, GetProjectPosition(uidoc.Document), out var _);
                                var end          = start.Subtract(sunDirection.Multiply(1000));

                                //// use this only for testing.
                                //// BuildingCoder.Creator.CreateModelLine(uidoc.Document, start, end);

                                var line = Line.CreateBound(start, end);

                                // Brute Force
                                // remove if ReferenceIntersector is faster...
                                foreach (var solid in solids)
                                {
                                    try
                                    {
                                        var solidInt = solid.IntersectWithCurve(line, new SolidCurveIntersectionOptions());
                                        if (solidInt.SegmentCount > 0)
                                        {
                                            hoursOfSun = hoursOfSun - interval;
                                            break;
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        Console.WriteLine(exception.Message);
                                    }
                                }
                            }
                            testFace.AddValueAtPoint(uv, hoursOfSun);
                        }
                    }
                }
            }

            var sfm = DirectSunTestFace.GetSpatialFieldManager(uidoc.Document);

            sfm.Clear();

            foreach (var testFace in testFaces)
            {
                testFace.CreateAnalysisSurface(uidoc, sfm);
            }

            view.AnalysisDisplayStyleId = schemeId;

            t.Commit();
            stopwatch.Stop();
            SCaddinsApp.WindowManager.ShowMessageBox("Time Elapsed", "Time elepsed " + stopwatch.Elapsed.ToString() + @"(hh:mm:ss:uu)");
        }