学习Revit可以从两个方面着手:学习Revit产品的使用和学习使用Revit API进行开发,二者相辅相成。基于Revit的开发离不开对产品的了解,对Revit技术架构的理解又能促进你对产品有更深刻地认识。所以说,二者缺一不可。当然要想成为建筑设计软件的行家里手,必要的相关行业背景知识也是必不可少的。
(The Autodesk Revit API is designed to reflect the same user interaction paradigms as the program’s Graphical User Interface. Therefore, the first step to understanding the API is to learn how to use the program. If you are an Autodesk Revit novice, we suggest you first start by going through the Tutorials which you can access through the program’s Help menu. You may also find it helpful to take a Training class from your local Autodesk reseller. This will help you quickly get up to speed with the program)
相关资料和背景知识
文档“Autodesk Revit 20XX(不同版本) API – Getting Started”会给你一个很不错的开始。更多资源可以求助于相关网站。
Autodesk Resources:
- http://www.autodesk.com/revitbuilding/
- http://www.autodesk.com/revitstructure/
- http://www.autodesk.com/revitsystems/
- http://www.autodesk.com/bim/
- http://discussion.autodesk.com/
External Resources:
All Autodesk Revit-based products are Parametric Building Information Modeling (BIM) tools.
(我喜欢BIM,所以我喜欢这句断言。J)
The Autodesk Revit API supports in-process DLLs only.
The Autodesk Revit API supports single threaded access only.
使用Microsoft Visual Studio开发的基本程
-
- 使用VS创建一个DLL工程(库工程)
- 在工程中引用RevitAPI.dll
- 新建类并实现特定接口
- IExternalCommand接口
- 添加外部命令,可以通过点击Add-Ins菜单来执行
- IExternalApplication接口
- 添加外部应用,在启动或关闭Revit程序时自动调用执行
- IExternalCommand接口
- 编译生成Assembly
- 手动修改Revit.ini文件(或启动Revit后使用Add-In Manager 加载用户开发的程序)
(为了防止翻译造成曲解,以下保持英文)
Autodesk.Revit.UI.IExternalCommand
External Command Object Lifetime
When no other command or edit modes are active within Autodesk Revit, the registered external command will become enabled. When picked, the command object will be created and the Execute method called. Once this method returns back to Autodesk Revit the command object will be destroyed. Due to this destruction, data cannot persist within the object between command executions. If you wish the data to persist you may use an external file or database to do so. If you wish the data to persist within the Autodesk Revit project you may use the shared parameters mechanism to store this data.
Autodesk.Revit.UI.IExternalApplication
External Application Object Lifetime
When Autodesk Revit starts, the external application object will be created and the OnStartup method called. Once this method returns back successfully to Autodesk Revit the external application object will be held during the entire Autodesk Revit session. The OnShutdown method will be called when Autodesk Revit shuts down.
关键类介绍
- 在Revit API中,顶层类对象是Application和Document
n Autodesk.Revit.Application revitApp = commandData.Application;
n commandData.Application.ActiveDocument;
- Revit API中的数据模型是一个多文档的类似于Microsoft Office的模式
n DocumentSet openedDocs = revitApp.Documents;
- Application对象代表着当前与之交互的Revit程序,可以通过它来操作当前打开的所有文档以及Revit中的一些设置
- Document对象代表一个打开的Revit文档(.rvt, .rfa, …),可以通过它操作当前文档中的各种元素
- 获得Revit中打开的所有文档
commandData.Application.Documents
- 获得当前活动的文档对象
commandData.Application.ActiveDocument
- 获得用来操作族文档的对象
commandData.Application.ActiveDocument.FamilyManager
- 获得当前活动文档中的所有元素
commandData.Application.ActiveDocument.Elements
(Application-Document-View-Element 关系图)
(Element分类)
API中的族操作
- Document.IsFamilyDocument
判断当前文档是不是一个族文档
- Document.FamilyManager(返回FamilyManager对象)
用来管理族中的类型和参数数据
- Document.FamilyCreate
在族文档中创建新的Revit元素
- FamilyManager.Types
得到族中的所有类型
- FamilyManager.CurrentType
得到族的当前类型
- FamilyManager.Parameters
得到族中的所有参数
过滤获取Revit中的元素
通过过滤提高获得特定类型元素的速度 (类别 、族名字 、所属类的类型 、组合过滤 …)
组合过滤: 更精确的得到特定的Revit元素
参数概览
- Revit模型是参数驱动的
- Revit中的Element有一系列的参数与之关联
API--通过Element类操作与之关联的所有参数,Element.Parameters
- 难点是理解和应用Revit中的自定义参数——共享参数和项目参数
(后文将对此作专门讨论)