创建三维视图之剖面框

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;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值