有个客户用新的Revit打开一个旧的文件,那么文件会被升级,升级之后,他认为Document.IsModified应该返回True,但实际上,返回值却是False.
If we useApplication.OpenDocumentFile to open a previous Revit version RFA family (i.ewe open a Revit 2013 family from Revit 2015),the family is correctly convertedto Revit 2015 format but Document.IsModified is falseIthink that in this case Document.IsModified should be true as the family hasbeen obviously modified (upgrade to a new Revit format)
对此我们开发部的同事Arnošt做出的解释是:
升级之后,该文件是一个和旧文件信息相同的新的文件,从Revit的角度看,并没有任何从用户那边来的修改,所以返回False应该是期望的行为。
Document.IsModified was correct to be returning False, since when you open a 2013 document on a newer version of Revit, from the Revit perspective, the document has not been modified by the end user. It has become a new Document with the information of the Old one. If you open a document that upgrades,it would prompt the user to save in the new format before closing even if nothing else (beside the upgrade) was modified.This being the reason on why the IsModified property will return False. The API just mimics the behavior of the modification.
或许我们有其他的办法。
我们知道Application.VersionName是用来拿当前Revit的版本信息的。
而另外一个类BasicFileInfo可以通过SavedInVersion属性获取当时保存该文档的Revit的版本信息。
我们通过比较这两个值是不是一样就可以判断这个文档是否被升级了。示例代码如下:
var verionName = RevitApp.VersionName; //<==Autodesk Revit 2015
if(File.Exists(RevitDoc.PathName))
{
var info = BasicFileInfo.Extract(RevitDoc.PathName);
var docVer = info.GetDocumentVersion();
var savedInVersion = info.SavedInVersion; //<==Autodesk Revit 2014
if (verionName != savedInVersion)
{
// should be an upgraded document!
}
}