Revit API-C#-太阳和阴影设置-计算一年中每小时的太阳方向

问题描述 投票:0回答:1

我正在使用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个回答
0
投票

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

您在那看到什么结果?

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

感谢您的回复!通过将datetimespecify.Utc更改为datetimespecify.local可以解决此问题。

恭喜,谢谢您通知我们。

© www.soinside.com 2019 - 2024. All rights reserved.