0

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

我可以在图纸上放置一个视口并将视图标题系列加载到项目中,但我无法将加载的视图标题分配给视口。有没有人有这方面的运气?

这是我正在尝试做的一些照片:

1) 视图放置在图纸上。不是问题 视图放置在图纸上。 不是问题

2)编辑视图类型和更改视图标题使用“View Title w sheet” 在此处输入图像描述

3)将显示延长线更改为“是” 在此处输入图像描述

4)让它看起来像这样。 在此处输入图像描述

以下是我一直在查看的一些资源: https ://thebuildingcoder.typepad.com/blog/2013/01/changeing-viewport-type.html <-- 显示如何将视口类型更改为已创建的视口类型。

https://forums.autodesk.com/t5/revit-api-forum/move-title-of-a-viewport/td-p/5598602 <--显示如何移动视图标题

**************更新**********************

我以为我让它完美地工作,我没有。

第一次单击该按钮时,除了未设置“标题”参数外,一切正常。它仍然显示<none>

创建视口时,再次单击该按钮会向我发送内部定义错误。

如果我将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);


4

2 回答 2

1

这是最近对标题块数据访问的解释,应该会有所帮助。

于 2020-05-07T09:48:49.463 回答
1

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

但是,我必须运行该按钮两次。我仍在弄清楚如何只需要运行一次。

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

****Solved*****
I needed to use a filtered element collector to find the elementId of my TitleView family instead of using the elementId from my `loadFamily` class. A peculiar error. 


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

于 2020-05-09T04:37:50.270 回答