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

罗伊·林

我正在使用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
杰里米·塔米克(Jeremy Tammik)

正如我在有关同一问题的Revit API讨论论坛主题中向您建议的那样,Revit API-C#-太阳和阴影设置-计算太阳方向,请通过用户界面手动执行相同的分析。

您在那看到什么结果?

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

谢谢回复!我通过将更datetimespecify.Utc改为解决了datetimespecify.local

恭喜,谢谢您让我们知道。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

C# revit api 在 Revit 中创建面板

Revit API C# 插入和旋转族

使用 c# api 读取和导出计划多个 revit 文件

C# Revit API,如何使用 ExternalCommand 创建一个简单的墙?

提示用户使用C#中的Revit API回答布尔选择

Revit API WPF C#:列表框中复选框的“全部选中”按钮

在 Revit 2017 API 中获取房间的邻居

Revit API中的元素的高级过滤

Revit API / Dynamo脚本中的MullionType错误

Revit API-C#-如何在视口上设置视图标题

一年中的天数的 API

如何在 Revit API 中的所有元素上设置“房间边界”属性

IronPython和Revit API-如何在列表框中显示项目属性(属性名称)?

c-一年中的星期,起始日期和锚定日期不定

Java API获取一年中特定时区的夏令时的开始和结束详细信息

Revit API:“隐藏”方法?

控制事件-Revit API

在C#中获取一年中的日期以及两个日期之间的所有小时

用一年中的年和周计算的Python日期不正确

在Forge API中以JSON形式返回Revit元素数据

在Python中创建商品ID Revit API的集合

使用python获取Revit API中的过滤规则信息

在 SQL 中,如何根据开始日期和经过的天数计算一年中的天数

如何使用C#获取Revit中选定元素的宽度、高度和深度

如何在 Revit 的设计自动化 api 中激活 3d 视图并保存 Revit 模型

如何在 Forge Viewer 中应用 Revit 显示设置?

使用特定设置从 Forge 中的 revit 文件导出 ifc 文件

Revit API-从Revit项目中完全删除系列

为什么ZonedDateTime和日历上不同意每小时在2050年一年?