using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
namespace WorkingDymo
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class 创建默认类型的平面视图 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
View activeView = uiDoc.ActiveView;
//获得默认建筑平面类型
ElementTypeGroup typeGroup = ElementTypeGroup.ViewTypeFloorPlan;
ElementId vid = doc.GetDefaultElementTypeId(typeGroup);
//新建并启动事务
Transaction transaction = new Transaction(doc, "创建平面视图");
transaction.Start();
//创建平面视图
ViewPlan viewPlan = ViewPlan.Create(doc, vid, activeView.GenLevel.Id);
//设置视图名称,之一需要规避同名视图,本案例忽略
viewPlan.Name = activeView.GenLevel.Name + "平面";
//分别设置视图的详细程度、比例、显式模式、规程
viewPlan.DetailLevel = ViewDetailLevel.Medium;
viewPlan.Scale = 150;
viewPlan.DisplayStyle = DisplayStyle.HLR;// HLR为隐藏线
viewPlan.Discipline = ViewDiscipline.Architectural;
//设置视图范围,以设置剖切高度1500为例
PlanViewRange planViewRange = viewPlan.GetViewRange();
planViewRange.SetOffset(PlanViewPlane.CutPlane, 1500 / 304.8);
viewPlan.SetViewRange(planViewRange);
//提交事务
transaction.Commit();
//将当前视图跳转到新建视图
uiDoc.ActiveView = viewPlan;
return Result.Succeeded;
}
}
}
创建默认视图的平面视图
最新推荐文章于 2022-11-01 11:23:02 发布