使用API创建标高之后,Revit不会自动创建对应的视图,可以使用ViewPlan.Create函数创建对应的视图:
public static ViewPlan Create(Document document, ElementId viewFamilyTypeId, ElementId levelId)
测试代码如下:
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
FilteredElementCollector colletorLevel = new FilteredElementCollector(doc);
Element elemLevel = colletorLevel.OfClass(typeof(Level)).FirstElement();
Level level = null;
//新建标高level
using (Transaction trans = new Transaction(doc))
{
trans.Start("Create Level");
level = Level.Create(doc, UnitUtils.ConvertToInternalUnits(3.6 , DisplayUnitType.DUT_METERS));
level.Name = "标高 2";
trans.Commit();
}
FilteredElementCollector collectorViewFamilyType = new FilteredElementCollector(doc);
IList<Element> viewFamilyTypes = collectorViewFamilyType.OfClass(typeof(ViewFamilyType)).ToElements();
foreach (Element elem in viewFamilyTypes)
{
ViewFamilyType viewFamilyType = elem as ViewFamilyType;
if (viewFamilyType.ViewFamily == ViewFamily.CeilingPlan || viewFamilyType.ViewFamily == ViewFamily.FloorPlan)
{
using (Transaction trans = new Transaction(doc))
{
trans.Start("Create ViewPlan");
ViewPlan viewPlan = ViewPlan.Create(doc, viewFamilyType.Id, level.Id);//为新建的标高创建对应的视图
trans.Commit();
}
}
}