【问题标题】:What changes need to be made to my code to create a new 3D perspective view in Revit?需要对我的代码进行哪些更改才能在 Revit 中创建新的 3D 透视图?
【发布时间】:2020-11-09 21:01:39
【问题描述】:

我从The Building Coder 复制了一些代码,以在已打开的 Revit 文件中创建 3D 透视图。但是,当我运行 Execute 方法时,绝对没有任何反应。输出日志中没有抛出异常或错误,所以我认为这只是我的代码副本的问题。

我需要怎样做才能让这段代码创建一个 3D 透视图和/或在 Revit 中打开它?

using (Transaction t = new Transaction(doc, "CameraTransaction"))
            {
                t.Start();
                IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                                              let type = elem as ViewFamilyType
                                                              where type.ViewFamily == ViewFamily.ThreeDimensional
                                                              select type;
                
                View3D issue3DCameraView = View3D.CreatePerspective(doc, viewFamilyTypes.First().Id);
                issue3DCameraView.Name = "Issue_" + issue.Name;

                PerspectiveCamera cam = issue.Viewpoints[i].PerspectiveCamera;
                XYZ position = new XYZ(cam.CameraViewPoint.X, cam.CameraViewPoint.Y, cam.CameraViewPoint.Z);
                XYZ up = new XYZ(cam.CameraUpVector.X, cam.CameraUpVector.Y, cam.CameraUpVector.Z);
                XYZ sightDir = new XYZ(cam.CameraDirection.X, cam.CameraDirection.Y, cam.CameraDirection.Z);

                var orientation = new ViewOrientation3D(position, up, sightDir);
                issue3DCameraView.SetOrientation(orientation);

                Parameter farClip = issue3DCameraView.LookupParameter("Far Clip Active");
                farClip.Set(0);

                Parameter cropRegionVisible = issue3DCameraView.LookupParameter("Crop Region Visible");
                cropRegionVisible.Set(1);

                Parameter cropView = issue3DCameraView.LookupParameter("Crop View");
                cropView.Set(1);
/* Removed                
//Added in an attempt to make the code work
                RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Default3DView);
                if (app.CanPostCommand(commandId))
                {
                    app.PostCommand(commandId);
                }*/

                t.Commit();
            }

编辑:对这个问题的进一步研究表明,事务只是在“issue3DCameraView.SetOrientation(orientation);”处停止。行。

【问题讨论】:

    标签: c# revit-api


    【解决方案1】:

    我无法通过查看您的代码来判断可能有什么问题......当然,除了您添加的 PostCommand 调用。相反,那肯定无济于事。

    我建议您先学习Creating and Setting Up a 3D View 上的 The Building coder 主题组中列出的其他一些文章,而不是尝试为您修复代码。

    【讨论】:

      【解决方案2】:

      此代码的问题在于 issue.Viewpoints[i].PerspectiveCamera 的源代码。代码本身运行良好。

      我把这个答案留在这里是为了那些追随我的人的利益。

      【讨论】:

        猜你喜欢
        • 2019-07-12
        • 1970-01-01
        • 2021-12-12
        • 2022-01-03
        • 2016-06-04
        • 2022-01-26
        • 1970-01-01
        • 2021-03-10
        • 2015-03-25
        相关资源
        最近更新 更多