Revit secondary development Seventeen-depth analysis Revit Interface

In revit, there UIApplication \ Application \ UIControlApplication, the links between them in the end and what is the difference, I am more confused been the problem in-depth understanding of the organizational structure of Revit, revit thinking logically follows, according to my understanding, the following only personal thoughts, do not represent the real situation.

 

 

 

 First, the application program Application

 In revit, the application is only one, but in Revit, defines a number of Application, they in the end what's the difference?

1, an object data bearer ApplicationServices.Application

In fact, only one application that Application, he is located Autodesk.Revit.ApplicationServices.Application. He is the core of the application object is the core revit currently open, has opened a new file and the current application ability of all settings, which carries all of the document object is the current revit data center, and a beginning of revit application program, only one Application.

2, the carrier interface UIApplication

Is Application of a screen interface that he represents all interface information of the current application, can operate all interfaces that are currently open, the current application center of the current capacity of the UI on behalf of all current Appliction only valid for the current open this application, Appliction only read current with previously read, an interface generated only valid within the current application cycle

3, the carrier contains only application interface data control application ControlApplication

Look at the code, you know, in fact ControlApplication just a package of Application due Application boot there is a certain life cycle, when the application has just started, to access the Application is not a safe thing, because they can not be avoided will have access to the document object, so when the plug-in is loaded, you need only a simplified version for processing interface Application, it defines the ControlApplication, for access to the IExternalApplication time, empathy. So ControlApplication class is not accessible to document object.

 

4, the carrier comprises only the initial application interface application UIControlApplication

 Similarly we know, which is defined

 

 

 

 5, Creator.Application class, mainly used to create a wrapper class Application class elements.

 

 Second, the document Document

1, an object data bearer: Autodesk.Revit.DB.Document

In any three-dimensional software, have to say an important thing, is the data, all we have to render three-dimensional data-based, whether it is presented as a plane, elevation, three-dimensional or other, must have a unique data, all of us All views, just a manifestation of the current data, in which there is a critical target for carrying data and define all of the data, the core element is the next Autodesk.Revit.DB namespace for all object carrying the object data is the core of all: "Document", which is the object Autodesk.Revit.DB.Document, the object carries all data objects, we look at these main targets several methods:

 

As can be seen, this object is data integrity, import and export as the core object of our data, we can also get the elements, family and other objects through this document.

document obtained manner, in commandData.Application.ActiveUIDocument.Document

2, create data objects: Autodesk.Revit.Creation.Document

 由于Autodesk.Revit.DB.Document承载着所有的数据,是所有构件显示的源头,直接通过API操作DB.Document肯定不合适,数据任意添加,不利于数据的稳定性,在此基础上,定义了一个Creation.Document的封装类,用于对DB.Document进行创建操作,这个对象Autodesk.Revit.DB.Document.Create属性获取。我们可以看看其常规的属性定义:

 

 3、Autodesk.Revit.UI.UIDocument

前面两个对象,无非操作都是数据,但是模型如何呈现,特别基于文档级别的模型定位、隔离、视图管理等,基本上无法做到,这里就不得不提UIDocument对象,这个对象是用于对document数据所有呈现的视图的一个综合管理,所以对于MVC来说,U就是V层、DB.Document是M层,Creation.Document是C层,共同构建了Revit文档的一个综合管理,UIDocument是对显示的一个管理单元,其控制着所有的视图对象,我们可以在UIDocument里面找到属性定义如下:

 

 

 如图所示,其包含了document数据对象,包含界面上的选择对象,也包含了所有的视图对象,其核心方法GetOpenUIViews能获取界面上所有的UVView视图对象。

三、视图对象

1、数据视图对象Autodesk.Revit.DB.View

他和DB.Document对象基本一致,是View中数据的一个载体,这个View的数据和DB.Document息息相关和有一些关系,主要看View自身利用的多少,所以View有很多不同的类型,每种类型都有很多自身的特性,对视图的操作,基本都是在这个View之中。但这些操作只是局限在对视图中的元素数据进行操作,对视图的本身的改变就交给另外一个类UIView来实现

2、视图呈现类Autodesk.Revit.UI.UIView  

这个对象是对View的可视化对象,用于在Revit中显示View中的数据,所有UIView可以缩放、定位等功能,是对于界面层级的操作。

小结,通过以上的分析,我们知道了Revit采用MVC的管理模式,将数据和视图进行分离,所以View作为一个Element对象,存储在Document中,所以通过对应的过滤器,能获取当前文档的所有视图:

 

FilteredElementCollector collector = new FilteredElementCollector(doc);
IList<Element> views = collector.OfClass(typeof(View)).ToElements();

 

UIView视图,是显示View的时候才创建,并不是一致都存在,所有的基本原理可以定义如下:

 

Guess you like

Origin www.cnblogs.com/minhost/p/12108322.html