Revit native project identifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have been studying how to get an unique (Guid) identifier for the project. I know there has been few posts already here and in the Building Coder blog about the subject.
But the bottom line is that I REALLY would like to have a Revit native method, mainly to avoid challenges in the work sharing environment. Below some highlights from my study:
- I have managed to confirm that using a project information element unique id is NOT an option, as several different projects can have identical id (perhaps it comes from the template...?).
- Utilizing the ExportUtils.GetExportId() with project information seems to result exactly the same. So probably this method uses the unique id too. Not usable.
- ExportUtils.GetGBXMLDocumentId() works somewhat better, and seems pretty good
- ExporterIFCUtils.CreateProjectLevelGUID() seems to be best though. Difference to previous is that this method results different id for project that has been detached from the central and saved with Save as (which sound reasonable).
So...I was pretty much already made my decision to use CreateProjectLevelGUID()...until I saw compilation warning from R2022 build. It has been deprecated :-(. "Ok, no problem" I though, as there has always been new alternative mentioned in the warning text. In this case it says:
"This function is deprecated in Revit 2022. Please see the IFC open source function CreateProjectLevelGUID for examples of how to do this starting in Revit 2022."
So eventually I decided to download the source codes from the "https://github.com/Autodesk/revit-ifc", as that's what it means right!?
More over I did found the method called CreateProjectLevelGUID() at took a look of the implementation (I'll paste the code at the bottom as it is public anyway). To me there's no native Revit mechanism I could utilize:
- Seems that the project information element dos NOT have following parameters by default (even in the R2022 level project): "IfcProjectGuid", BuiltInParameter.IFC_PROJECT_GUID
- The implementation in the comments (refering also to R2022) seems incorrect to me, as a) it is utilizing the IFCProjectLevelGUIDType enumeration which is also deprecated. b) moreover creating a ElementId from the enumeration value seems quite odd as according to IL reflection tool, enumeration values are using default enum values (0,1,2...)
So my questions basically is:
Is there a native method/technique replacing the deprecated CreateProjectLevelGUID(), or what's the best alternative (not necessarily specific to IFC)
/// <summary>
/// Creates a Project, Site, or Building GUID. If a shared parameter is set with a valid IFC GUID value,
/// that value will override the default one.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="guidType">The GUID being created.</param>
/// <returns>The IFC GUID value.</returns>
/// <remarks>For Sites, the user should only use this routine if there is no Site element in the file. Otherwise, they
/// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
{
string parameterName = "Ifc" + guidType.ToString() + " GUID";
ProjectInfo projectInfo = document.ProjectInformation;
BuiltInParameter parameterId = BuiltInParameter.INVALID;
switch (guidType)
{
case IFCProjectLevelGUIDType.Building:
parameterId = BuiltInParameter.IFC_BUILDING_GUID;
break;
case IFCProjectLevelGUIDType.Project:
parameterId = BuiltInParameter.IFC_PROJECT_GUID;
break;
case IFCProjectLevelGUIDType.Site:
parameterId = BuiltInParameter.IFC_SITE_GUID;
break;
default:
// This should eventually log an error.
return null;
}
if (projectInfo != null)
{
string paramValue = null;
ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
if (!IsValidIFCGUID(paramValue) && parameterId != BuiltInParameter.INVALID)
ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue);
if (IsValidIFCGUID(paramValue))
return paramValue;
}
// Only for 2022
//ElementId projectLevelElementId = new ElementId((int)guidType);
//System.Guid guid = ExportUtils.GetExportId(document, projectLevelElementId);
//string ifcGUID = ConvertToIFCGuid(guid);
string ifcGUID = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);
if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
{
if (parameterId != BuiltInParameter.INVALID)
ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair<ElementId, BuiltInParameter>(projectInfo.Id, parameterId)] = ifcGUID;
}
return ifcGUID;
}