revit api 创建 sheet - 文档 - 包含已弃用的“view3d

revit api create sheet - docs - contain deprecated "view3d

我正在根据文档尝试使用 C#

中的 Revit API 创建一个带有视图的 sheet

here is the docs URL link。您可以在第一个 C# 块的底部找到代码。

我在 view3D.Id:

下方看到一条红色波浪线

Viewport.Create(doc, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));

我找不到它已被弃用,也不知道如何解决它。我对它为什么要尝试获取自己的 elementID 感到有点困惑。另外,刚刚进入 revit-API。 Revit 中的 "views" 似乎在 API 中被称为 "viewports"。我需要阅读更多相关内容。

这里是整个代码块:

private void CreateSheetView(Autodesk.Revit.DB.Document document, View3D view3D)
{

    // Get an available title block from document
    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.OfClass(typeof(FamilySymbol));
    collector.OfCategory(BuiltInCategory.OST_TitleBlocks);

    FamilySymbol fs = collector.FirstElement() as FamilySymbol;
    if (fs != null)
    {
        using (Transaction t = new Transaction(document, "Create a new ViewSheet"))
        {
            t.Start();
            try
            {
                // Create a sheet view
                ViewSheet viewSheet = ViewSheet.Create(document, fs.Id);
                if (null == viewSheet)
                {
                    throw new Exception("Failed to create new ViewSheet.");
                }

                // Add passed in view onto the center of the sheet
                UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2,
                                     (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                //viewSheet.AddView(view3D, location);
                Viewport.Create(document, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));
                ^ERROR HAPPENS IN LINE ABOVE AT view3D.Id


                // Print the sheet out
                if (viewSheet.CanBePrinted)
                {
                    TaskDialog taskDialog = new TaskDialog("Revit");
                    taskDialog.MainContent = "Print the sheet?";
                    TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No;
                    taskDialog.CommonButtons = buttons;
                    TaskDialogResult result = taskDialog.Show();

                    if (result == TaskDialogResult.Yes)
                    {
                        viewSheet.Print();
                    }
                }

                t.Commit();
            }
            catch
            {
                t.RollBack();
            }
        }
    }
}

The Building Coder discussion of exact viewport positioning 包括一些对 ViewSheet.CreateViewport.Create.

的唤醒示例调用