【问题标题】:Revit API - C# - Sun and shadow setting - calculating sun direction for every hour in a year periodRevit API - C# - 太阳和阴影设置 - 计算一年中每小时的太阳方向
【发布时间】:2019-12-01 06:05:52
【问题描述】:

我正在使用 Jeremy Tammik 的示例代码通过 Revit API 计算一年的太阳方向。 https://thebuildingcoder.typepad.com/blog/2013/06/sun-direction-shadow-calculation-and-wizard-update...

所以我基本上循环它以获得全年8760小时的太阳方向。

但是,当我将数据导出到 Excel 时,数据似乎不正确。太阳方向的矢量在许多小时内保持不变,这是不对的。 PS Activeframe时间是正确的。

以下是我的代码(附有 Visual Studio 版本),所附图像是我的数据的一部分,它显示了问题。谢谢!


            Autodesk.Revit.DB.View view = doc.ActiveView;

            SunAndShadowSettings sunsetting = view.SunAndShadowSettings;

            Transaction transun = new Transaction(doc);

            transun.Start("sun1");

            IList<DateTime> datetime = new List<DateTime>();

            IList<DateTime> activeframe = new List<DateTime>();

            //create list of 0 to 23
            IList<double> timesss = test3.EnumerableUtilities.RangePython(0, 24, 1).ToList();

            IList<XYZ> revitsun = new List<XYZ>();

            DateTime StartDate = new DateTime (2018,1,1);
            DateTime EndDate = new DateTime(2018,12,31);

            foreach (DateTime days in EachDay(StartDate, EndDate))
            {

                datetime.Add(days);
            }

            foreach (var dat in datetime )
            {
                DateTime datee = dat;
                int year = dat.Year;
                int month = dat.Month;
                int date = dat.Day;

                foreach (var da in timesss)
                {
                    double ti = da;
                    DateTime sunstart = DateTime.SpecifyKind(new DateTime(year,month,date), DateTimeKind.Utc);

                    sunsetting.SunAndShadowType = SunAndShadowType.StillImage;


                    sunsetting.StartDateAndTime = sunstart.AddHours(ti);

                    if (sunsetting.IsTimeIntervalValid(SunStudyTimeInterval.Hour)) // check that this interval is valid for this SunAndShadowType

                        sunsetting.TimeInterval = SunStudyTimeInterval.Hour;

                    // check for validity of start and end times
                    if (!(sunsetting.IsAfterStartDateAndTime(sunsetting.EndDateAndTime)
                        && sunsetting.IsBeforeEndDateAndTime(sunsetting.StartDateAndTime)))
                        TaskDialog.Show("Error", "Start and End dates are invalid");


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

                    DateTime time = sunsetting.GetFrameTime(sunsetting.ActiveFrame);

                    activeframe.Add(time);
                    //string frametime = time.ToString();



                    // Get the altitude of the sun from the sun settings
                    double altitude = sunsetting.GetFrameAltitude(
                      sunsetting.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 = sunsetting.GetFrameAzimuth(
                      sunsetting.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);

                    revitsun.Add(sunDirection);

                    string countsundirection = sunDirection.ToString();
                }
            }```


[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/ldFTc.png

【问题讨论】:

    标签: c# shadow revit-api revit


    【解决方案1】:

    正如我在 Revit API 论坛主题中向您建议的那样 在同一问题上,Revit API - C# - Sun and shadow setting - calculating sun direction, 请通过用户界面手动执行相同的分析。

    你在那里看到了什么结果?

    同时,你已经确认成功,说:

    感谢您的回复!我通过将datetimespecify.Utc 更改为datetimespecify.local 解决了这个问题。

    恭喜并感谢您告知我们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      相关资源
      最近更新 更多