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

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

我正在尝试使用Revit API设置视图标题以显示在Revit项目上,但是我不知道如何访问它。

我能够在工作表上放置一个视口,并将视图标题族加载到项目中,但是我无法将加载的视图标题分配给该视口。有人有运气吗?

这里有一些我想做的照片:

1)视图放置在图纸上。没问题View is placed on the sheet. not a problem

2)编辑视图类型并使用“ View Title w sheet”更改视图标题enter image description here

3)将表演扩展线更改为“是”enter image description here

4)使它看起来像这样。enter image description here

以下是我一直在查看的一些资料:https://thebuildingcoder.typepad.com/blog/2013/01/changing-viewport-type.html

https://forums.autodesk.com/t5/revit-api-forum/move-title-of-a-viewport/td-p/5598602

**************更新**********************]

我以为我可以完美地工作了,我没有。

第一次单击按钮时,除未设置“标题”(Title)参数外,其他所有功能均有效。它仍然显示<none>

第二次单击该按钮会在创建视口时向我发送InternalDefinition Error。

如果我手动将Title设置为加载的视图标题族,则应用更改,将其重置回<none>,应用更改,然后点击按钮。有用。这几乎就像在我应用更改之前,该家庭不被视为合法的视图标题选项。

这是我的代码:

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


            // Get available viewPlans block from document
            FilteredElementCollector collectorViewPlans = new FilteredElementCollector(doc);
            collectorViewPlans.OfClass(typeof(ViewPlan));
            List<ViewPlan> viewPlansList = collectorViewPlans.Cast<ViewPlan>().ToList();

            // grab first as example
            ViewPlan duplicatedPlan = viewPlansList[0];


            // grab viewport labels
            FilteredElementCollector colViewTitles = new FilteredElementCollector(doc);
            colViewTitles.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_ViewportLabel);

            String colViewTitleFamilyName = null;
            Element colViewTitleFamilyName2 = null;
            ElementId viewTitleIdCommand = null;

using (Transaction t = new Transaction(doc))
            {

                //try
                //{

                t.Start("Create a new ViewSheet");

                // check if any title blocks are loaded. if not, load familly
                if (colTitleBlocks != null)
                {
                    LoadTitleBlocks loadFamily = new LoadTitleBlocks();
                    loadFamily.loadFamily(commandData);
                }
                FamilySymbol firstSheet = colTitleBlocks.FirstElement() as FamilySymbol;


                // Create a sheet view Block
                ViewSheet viewSheet = ViewSheet.Create(doc, firstSheet.Id);
                if (viewSheet == null)
                {
                    throw new Exception("Failed to create new ViewSheet.");
                }
                // End of Create a sheet view Block


                // begin duplication
                ElementId duplicatedPlan2Copy = duplicatedPlan.Duplicate(ViewDuplicateOption.Duplicate);

                // 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);


                try
                {
                    // Create Viewport
                    newViewPort = Viewport.Create(doc, viewSheet.Id, duplicatedPlan2Copy, new XYZ(location.U, location.V, 0));
                }
                catch (Exception)
                {

                    throw;
                }

                newViewPort.LookupParameter("View Scale").Set(24);
                bool newViewportTypeParameterShowLabel = doc.GetElement(newViewPort.GetTypeId()).get_Parameter(BuiltInParameter.VIEWPORT_ATTR_SHOW_LABEL).Set(1);


if (colViewTitles.Count() > 0)
                {
                    viewTitleIdCommand = colViewTitles.FirstElementId();
                    colViewTitleFamilyName = colViewTitles.FirstElement().ToString();
                    Debug.Print("Count greater than 0. colViewTitleFamilyName: " + colViewTitleFamilyName + " Id: " + viewTitleIdCommand);

                }
                else if (colViewTitles.Count() == 0)
                {
                    LoadViewTitle loadViewTitle = new LoadViewTitle();
                    loadViewTitle.loadFamily(commandData);
                    viewTitleIdCommand = loadViewTitle.viewTitleId;
                    colViewTitleFamilyName = doc.GetElement(loadViewTitle.viewTitleId).Name;
                    colViewTitleFamilyName2 = doc.GetElement(loadViewTitle.viewTitleId) as Family;
                    //Family colViewTitleFamilyName3 = colViewTitleFamilyName2.
                    Debug.Print("Count is 0. colViewTitleFamilyName: " + colViewTitleFamilyName + " Id: " + viewTitleIdCommand);
                }
                doc.GetElement(newViewPort.GetTypeId()).get_Parameter(BuiltInParameter.VIEWPORT_ATTR_LABEL_TAG).Set(viewTitleIdCommand);


c# revit-api revit pyrevit bim
2个回答
1
投票

这里是有关Title Block Data Access的最新解释,应该会有所帮助。


1
投票

通过使用这两行代码,我可以得到想要的东西:

但是,我必须两次运行按钮。我仍在寻找如何只运行一次的方法。

bool newViewportTypeParameterShowLabel = doc.GetElement(newViewPortTypeId).get_Parameter(BuiltInParameter.VIEWPORT_ATTR_SHOW_LABEL).Set(1);


bool elementType = doc.GetElement(newViewPortTypeId).get_Parameter(BuiltInParameter.VIEWPORT_ATTR_LABEL_TAG).Set(viewTitleIdCommand);

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