Access Central File TransmissionData on Revit Server

We already discussed using the TransmissionData class to list linked files and make changes using the WriteTransmissionData method.

Here is another question on this topic answered by my colleague Joe Ye:

Question: I want to access the TransmissionData object in a central file stored in the Revit Server. How can I achieve that via the Revit API, please?

I tried the suggestions listed in the developer guide and none of them worked for me.

I also tried using IsValidUserVisibleFullServerPath on various permutations of the server name, path and model name as reported in my journal file, but it returned false on all my attempts.

Answer: To read the TransmissionData object, you need to call the static method TransmissionData.ReadTransmissionData. It requires a ModelPath object. We will show you how to construct the ModelPath object that refers to the central file.

There are two ways to construct a ModelPath object.

Way #1

Let's look at accessing the following central file on a Revit Server:

Revit Server central file

Here is the code showing the implementation of way #1:

[TransactionAttribute( TransactionMode.Manual )]
public class RevitCommand : IExternalCommand
{
  public Result Execute( 
    ExternalCommandData commandData,
    ref string messages, 
    ElementSet elements )
  {
    UIApplication app = commandData.Application;
    Document doc = app.ActiveUIDocument.Document;
 
    Transaction trans = new Transaction( doc );
    trans.Start( "ExComm" );
 
    string visiblePath = ModelPathUtils
      .GetRevitServerPrefix() + "/testmodel.rvt";
 
    ModelPath serverPath = ModelPathUtils
      .ConvertUserVisiblePathToModelPath( 
        visiblePath );
 
    TransmissionData transData = TransmissionData
      .ReadTransmissionData( serverPath );
 
    if( transData != null )
    {
      // Access the data in the transData here.
    }
    else
    {
      TaskDialog.Show( "Transmission Data",
        "The document does not have any transmission data" );
    }
 
    trans.Commit();
 
    return Result.Succeeded;
  }
}

Way #2

Use this if your program knows the local server name. This is mostly not recommended, since the server name may be changed manually from the user interface by the Revit user.

Here is the code showing the implementation of way#2.

[TransactionAttribute( TransactionMode.Manual )]
public class RevitCommand : IExternalCommand
{
  public Result Execute(
    ExternalCommandData commandData,
    ref string messages,
    ElementSet elements )
  {
    UIApplication app = commandData.Application;
    Document doc = app.ActiveUIDocument.Document;
 
    Transaction trans = new Transaction( doc );
    trans.Start( "ExComm" );
 
    ServerPath serverPath = new ServerPath(
      "SHACNG035WQRP", "testmodel.rvt" );
 
    TransmissionData transData = TransmissionData
      .ReadTransmissionData( serverPath );
 
    if( transData != null )
    {
      // Access the data in the transData here.
    }
    else
    {
      TaskDialog.Show( "Transmission Data",
        "The document does not have any transmission data" );
    }
    trans.Commit();
 
    return Result.Succeeded;
  }
}