LoadResource Method


Implement this method to load the requested resource.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2015

Syntax

C#
void LoadResource(
	Guid loadRequestId,
	ExternalResourceType resourceType,
	ExternalResourceReference desiredResource,
	ExternalResourceLoadContext loadContext,
	ExternalResourceLoadContent loadResults
)
Visual Basic
Sub LoadResource ( _
	loadRequestId As Guid, _
	resourceType As ExternalResourceType, _
	desiredResource As ExternalResourceReference, _
	loadContext As ExternalResourceLoadContext, _
	loadResults As ExternalResourceLoadContent _
)
Visual C++
void LoadResource(
	Guid loadRequestId, 
	ExternalResourceType^ resourceType, 
	ExternalResourceReference^ desiredResource, 
	ExternalResourceLoadContext^ loadContext, 
	ExternalResourceLoadContent^ loadResults
)

Parameters

loadRequestId
Type: System Guid
The id uniquely identifying the load request.
resourceType
Type: Autodesk.Revit.DB ExternalResourceType
The type of resource requested.
desiredResource
Type: Autodesk.Revit.DB ExternalResourceReference
The specific resource that should be loaded.
loadContext
Type: Autodesk.Revit.DB ExternalResourceLoadContext
A class containing info about the context of the load request.
loadResults
Type: Autodesk.Revit.DB ExternalResourceLoadContent
The data returned by the server as a result of this load operation. Revit will ensure that this argument is the appropriate subclass of ExternalResourceLoadContent for the type of data.

Remarks

This method will be invoked when Revit needs to load a resource supplied by this server.

Revit provides four key pieces of information to the server:

  • A GUID identifying the load request.
  • The type of external resource that Revit is requesting, such as keynote data, linked Revit/CAD files, etc.
  • An ExternalResourceReference object, which contains information, such as a filename, the version, or other data, that identifies the specific resource that Revit needs from the server.
  • An ExternalResourceLoadContext object, which contains information about the context of the load request. For example, the ExternalResourceLoadContext contains information describing whether the load came about as a result of a user action or an automatic action.

The server returns the results of the load request back to Revit via the loadResults argument, which will be a sub-class of ExternalResourceLoadContent. This object will contain appropriate data structures to hold the actual resource data (content) required by Revit for the specified ExternalResourceType.

Server authors may also wish to display UI related to the resource load operation, particularly when errors occur while loading or creating the content. The UI should not be created by the IExternalResourceServer. Instead, the server author should implement an IExternalResourcesUIServer which will handle all UI-related tasks. The external services framework supports data sharing between, and coordinates the actions of, the two types of servers as follows:

  1. Each ExternalResourceLoadContent sub-class is designed to hold data related to errors that may have occurred while loading or creating the content the specified ExternalResourceType. The IExternalResourceServer should set this data as needed in the LoadResource(Guid, ExternalResourceType, ExternalResourceReference, ExternalResourceLoadContext, ExternalResourceLoadContent) method.
  2. The error data, along with ExternalResourceReference and other information associated with the attempt to load the external resource, is stored internally by Revit until a time when it is appropriate to display UI.
  3. When appropriate, the framework will invoke the HandleLoadResourceResults method of any IExternalResourceUIServer that is associated with the IExternalResourceServer, and will pass the error data and other information to the UIServer for possible display in the Revit UI.

Note that instead of using the ExternalResourceLoadContent object, the IExternalResourceServer can store its own error information. Subsequently, when the external services framework invokes the IExternalResourceUIServer's HandleLoadResourceResults method, the IExternalResourceUIServer can communicate directly with its associated IExternalResourceServer - using whatever interface the server developer has implemented - to retrieve the required messages and error data for display in the UI. Revit provides a GUID to LoadResource(Guid, ExternalResourceType, ExternalResourceReference, ExternalResourceLoadContext, ExternalResourceLoadContent) , to facilitate identification of individual load requests.

See Also