using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace View3Dset
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uIDoc = commandData.Application.ActiveUIDocument;
Document doc = uIDoc.Document;
View activeView = uIDoc.ActiveView;
//先设定一个剖切框范围
//由用户框选范围
PickedBox pickedBox = null;
pickedBox = uIDoc.Selection.PickBox(PickBoxStyle.Directional, "框选范围");
//由于用户框选方向无法确定,需要求出矩形框的左下和右上点
XYZ pick1 = pickedBox.Min;
XYZ pick2 = pickedBox.Max;
double xmax = Math.Max(pick1.X, pick2.X);
double xmin = Math.Min(pick1.X, pick2.X);
double ymax = Math.Max(pick1.Y, pick2.Y);
double ymin = Math.Min(pick1.Y, pick2.Y);
//本案例高度设为当前楼层开始,至3000高处
double zmin = activeView.GenLevel.Elevation;
double zmax = zmin + 3000 / 304.8;
XYZ min = new XYZ(xmin, ymin, zmin);
XYZ max = new XYZ(xmax, ymax, zmax);
//构件一个boundingbox作为范围框
BoundingBoxXYZ boudingbox = new BoundingBoxXYZ();
boudingbox.Min = min;
boudingbox.Max = max;
//获得默认三维视图类型
ElementId tg = doc.GetDefaultElementTypeId(ElementTypeGroup.ViewType3D);
//新建并启动事务
Transaction transaction = new Transaction(doc, "创建三维视图");
transaction.Start();
//创建轴测图
View3D view3D = View3D.CreateIsometric(doc, tg);
//设置剖面框范围
view3D.SetSectionBox(boudingbox);
transaction.Commit();
//将当前视图跳转到该平面
uIDoc.ActiveView = view3D;
return Result.Succeeded;
}
}
}