revit二次开发——view

本文详细介绍了Revit二次开发中关于View的各个方面,包括视图类型(如ViewPlan、View3D等)、规程DisCipline、View的继承结构以及如何获取视图的具体信息,如名称、裁剪区域、坐标方向和缩放比例等。通过实例展示了如何利用API操作和获取视图数据。

1.viewType 视图类型(枚举)

API

ViewType Enumeration

Member nameDescription
UndefinedUndefined/unspecified type of view.   未定义未指定的视图类型。
FloorPlanFloor plan type of view.    平面图平面图类型的视图。  
CeilingPlanReflected ceiling plan type of view.      反映天花板平面类型的视图。
ElevationElevation type of view.       仰角类型的视图
ThreeD3-D type of view.      三维类型的视图
ScheduleSchedule type of view.         Schedule调度视图类型
DrawingSheetDrawing sheet type of view.  绘图表视图类型
ProjectBrowserThe project browser view.        ProjectBrowser项目浏览器视图
ReportReport type of view.   Report报表视图类型
DraftingViewDrafting type of view.        DraftingView视图的绘图类型
LegendLegend type of view.      传说类型的视图。  
SystemBrowserThe MEP system browser view. MEP系统浏览器视图
EngineeringPlanStructural plan or Engineering plan type of view. 计划或工程计划类型的视图
AreaPlanArea plan type of view.     区域规划视图类型。
SectionCross section type of view.   横截面视图类型
DetailDetail type of view.           视图的详细类型
CostReportCost Report view.    成本报表视图
LoadsReportLoads Report view.      负载报表视图
PresureLossReportPressure Loss Report view.        压力损失报表视图
ColumnScheduleColumn Schedule type of view.          列调度视图类型
PanelSchedulePanel Schedule Report view.     面板进度报表视图
WalkthroughWalk-Through type of 3D view.    渲染类型的3D视图
RenderingRendering type of view.           视图的渲染类型
InternalRevit's internal type of view          Revit的内部类型的视图 

 例子

 2.规程DisCipline

3.View 继承结构

所有的视图都是继承自 Autodesk.Revit.DB.View,分别对应各种视图类型

 

4.View 的实例

以官方给的文件为例:

楼层平面:ViewPlan
三维视图:View3D
立面、剖面、详细视图:ViewSection
渲染:ImageView
图例:View
明细表:ViewSchedule
图纸:ViewSheet

5.获取 View 的信息

视图的基本信息,包括:

视图名称,view.Name
视图裁剪区域,view.CropBox
视图起始点,view.Origin
视图平面投影区域,view.Outline
视图往右、往上、指向观察者的方向,view.RightDirection,view.UpDirection,view.ViewDirection
视图缩放比例,view.Scale

方法示例:

        private void Getinfo_View(Autodesk.Revit.DB.View view)
        {
            string message = "View: ";

            // 得到视图的名称
            message += "\nView name: " + view.Name;

            // 视图裁剪区域包围盒
            BoundingBoxXYZ cropBox = view.CropBox;
            XYZ max = cropBox.Max; // 最大值,包围盒右上角
            XYZ min = cropBox.Min; // 最小值,包围盒左下角
            message += "\nCrop Box: ";
            message += "\nMaximum coordinates: (" + max.X + ", " + max.Y + ", " + max.Z + ")";
            message += "\nMinimum coordinates: (" + min.X + ", " + min.Y + ", " + min.Z + ")";


            // 视图的起始点(想象一下透视视图)
            XYZ origin = view.Origin;
            message += "\nOrigin: (" + origin.X + ", " + origin.Y + ", " + origin.Z + ")";


            //视图投影到平面的范围框
            BoundingBoxUV outline = view.Outline;
            UV maxUv = outline.Max; // 最大值,包围盒右上角
            UV minUv = outline.Min; // 最小值,包围盒左下角
            message += "\nOutline: ";
            message += "\nMaximum coordinates: (" + maxUv.U + ", " + maxUv.V + ")";
            message += "\nMinimum coordinates: (" + minUv.U + ", " + minUv.V + ")";

            // 视图往右的方向
            XYZ rightDirection = view.RightDirection;
            message += "\nRight direction: (" + rightDirection.X + ", " +
                           rightDirection.Y + ", " + rightDirection.Z + ")";

            // 视图往上的方向
            XYZ upDirection = view.UpDirection;
            message += "\nUp direction: (" + upDirection.X + ", " +
                           upDirection.Y + ", " + upDirection.Z + ")";

            // 视图指向观察者(即我)的方向
            XYZ viewDirection = view.ViewDirection;
            message += "\nView direction: (" + viewDirection.X + ", " +
                           viewDirection.Y + ", " + viewDirection.Z + ")";

            // 视图的缩放比例
            message += "\nScale: " + view.Scale;
            // Scale is meaningless for Schedules
            if (view.ViewType != ViewType.Schedule)
            {
                int testScale = 5;
                //设置视图比例,需要 Transaction
                view.Scale = testScale;
                message += "\nScale after set: " + view.Scale;
            }

            TaskDialog.Show("Revit", message);
        }

主程序调用:

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace PersonalTools
{
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

            using(Transaction transaction = new Transaction(doc, "View"))
            {
                transaction.Start();
                View view = doc.ActiveView;
                Getinfo_View(view);
                transaction.Commit();
            }
            return Result.Succeeded;
        }

前视图数据:可知 Revit 中的坐标系,往右是 X 方向,往上是 Z 方向。因此前视图是从 Y 方向从屏幕外指向屏幕里面。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值