我正在尝试使用 Revit API 设置视图标题以显示在 Revit 项目中,但我不知道如何访问它。
我可以在图纸上放置一个视口并将视图标题系列加载到项目中,但我无法将加载的视图标题分配给视口。有没有人有这方面的运气?
这是我正在尝试做的一些照片:
2)编辑视图类型和更改视图标题使用“View Title w sheet”
以下是我一直在查看的一些资源: 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);