We talked about Revit Application and Document events previously. In this article, let us have a look at the Revit Application and ControlledApplication classes.
Both Application and ControlledApplication classes are in the Revit API Autodesk.Revit.ApplicationServices namespace. They are both derived from the System.Object class and do not have any inheritance relationship between each other though they share most of methods, properties, and events.
Let’s look at the special kind of methods, constructors, first. The Application type even provides a constructor and we can create a Revit Application object at our will like this:
Dim app As New Autodesk.Revit.ApplicationServices.Application()
MessageBox.Show("Document count: " + app.Documents.Size.ToString())
And it behaves just well and reports the document count correctly. So the constructor of the Application type behaves like retrieving the Revit application single instance from caches somewhere rather than really creating a new instance of the Revit application. This can be verified from the fact that the Dispose() method of the Application does not take any effect at all supposing the following code is appended to the code above.
app.Dispose()
People would expect the whole Revit session be ended by the Dispose method, not right?
It is not a big deal anyway. In fact, it is good that another way is provided to retrieve the application instance besides caching it from the ExternalCommandData when external commands are being executed. In terms of the Dispose() method, we can just forget about it from now on since we have found out it does nothing.
Except for the Dispose method, other extra methods in the Application type make very sense as they are document related:
ExtractPartAtomFromFamilyFile
NewFamilyDocument
NewProjectDocument
NewProjectTemplateDocument
OpenDocumentFile
Both Application and ControlledApplication classes have the following methods and they have no reasons to behave different, even a bit:
Equals
GetFailureDefinitionRegistry
GetHashCode
GetType
OpenSharedParameterFile
RegisterFailuresProcessor
ToString
WriteJournalComment
In terms of properties, the Application type has a few additional ones and again they all seem to be document related:
Assets
Documents
FamilyTemplatePath
ObjectFactory
Both Application and ControlledApplication classes have the following properties and they have no reasons to carry anything different, even a bit:
Cities
Create
IsQuiescent
Language
LibraryPaths
Product
RecordingJournalFilename
SharedParametersFilename
VersionBuild
VersionName
VersionNumber
Now events: both Application and ControlledApplication classes have the following events and they have no reasons to carry anything different or behave different, even a bit:
DocumentClosing
DocumentPrinted
DocumentPrinting
DocumentSaved
DocumentSavedAs
DocumentSaving
DocumentSavingAs
ViewPrinted
ViewPrinting
DocumentChanged
DocumentClosed
DocumentCreated
DocumentCreating
DocumentOpened
DocumentOpening
DocumentSynchronizedWithCentral
DocumentSynchronizingWithCentral
FailuresProcessing
FileExported
FileExporting
FileImported
FileImporting
It is understandable that two types of the same application single instance are provided to address different entry points, external application startup and external command execution, but it would make more sense that one is derived from another since they share most of stuffs and they behave just exactly the same. What about LightApplication and FullApplication and the latter inherits everything from the former and adds its own methods, properties and events?
It does not really matter as far as naming is concerned though.
RevitAddinWizard cannot do much about the inheritance but it can help create a lot using what’s provided automatically in no time, such as Application/ControlledApplication even handlers, UIApplication event handlers, Document event handlers, and so on.
Recent Comments