Message 1 of 1
RevitLinkType & Cloud model
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
1) How to check if a RevitLinkType comes from the cloud (BIM 360)?
Here is the method I use to determine if the model is from the cloud. Is this valid?
public static bool IsLinkedModel(RevitLinkType revitLinkType)
{
IDictionary<ExternalResourceType, ExternalResourceReference> r = revitLinkType.GetExternalResourceReferences();
ExternalResourceReference reference = r[ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink];
var dictinfo = reference.GetReferenceInformation();
if (dictinfo.ContainsKey("LinkedModelProjectId") && dictinfo.ContainsKey("LinkedModelModelId"))
return true;
return false;
}
2) Is it necessary to use the Load () function to determine the path of the file ?, Because currently I use this function but sometimes the InSessionPath variable is empty.
public static string GetPath(RevitLinkType revitLinkType)
{
IDictionary<ExternalResourceType, ExternalResourceReference> r = revitLinkType.GetExternalResourceReferences();
ExternalResourceReference reference = r[ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink];
string sessionPath = reference.InSessionPath;
return sessionPath;
}
Discussion link: https://thebuildingcoder.typepad.com/blog/2019/06/accessing-bim360-cloud-links-thumbnail-and-dynamo....
// Obtain all external resource references
// (saying BIM360 Cloud references and local
// file references this time)
ISet<ElementId> xrefs = ExternalResourceUtils
.GetAllExternalResourceReferences( doc );
string caption = "BIM360 Links";
try
{
int n = 0;
var msg = string.Empty;
foreach( ElementId eid in xrefs )
{
var elem = doc.GetElement( eid );
if( elem == null ) continue;
// Get RVT document links only this time
var link = elem as RevitLinkType;
if( link == null ) continue;
var map = link.GetExternalResourceReferences();
var keys = map.Keys;
foreach( var key in keys )
{
var reference = map[key];
// Contains Forge BIM360 ProjectId
// (i.e., LinkedModelModelId) and
// ModelId (i.e., LinkedModelModelId)
// if it's from BIM360 Docs.
// They can be used in calls to
// ModelPathUtils.ConvertCloudGUIDsToCloudPath.
var dictinfo = reference.GetReferenceInformation();
// Link Name shown on the Manage Links dialog
var displayName = reference.GetResourceShortDisplayName();
var path = reference.InSessionPath;
}
try
{
// Load model temporarily to get the model
// path of the cloud link
var result = link.Load();
// Link ModelPath for Revit internal use
var mdPath = result.GetModelName();
link.Unload( null );
// Convert model path to user visible path,
// i.e., saved Path shown on the Manage Links
// dialog
var path = ModelPathUtils
.ConvertModelPathToUserVisiblePath( mdPath );
// Reference Type shown on the Manage Links dialog
var refType = link.AttachmentType;
msg += string.Format( "{0} {1}\r\n",
link.AttachmentType, path );
++n;
}
catch( Exception ex ) // never catch all exceptions!
{
TaskDialog.Show( caption, ex.Message );
}
}
caption = string.Format( "{0} BIM360 Link{1}",
n, Util.PluralSuffix( n ) );
TaskDialog.Show( caption, msg );
}
catch( Exception ex )
{
TaskDialog.Show( caption, ex.Message );
}
This returns the path well:
var path = ModelPathUtils
.ConvertModelPathToUserVisiblePath( mdPath );
But this one is empty:
var path = reference.InSessionPath;