specklesystems / xUnitRevit

xUnit runner for Revit
https://speckle.systems/blog/xunitrevit/
MIT License
120 stars 44 forks source link

Enhancement: Function to open RevitServer and CloudModels with xUnitRevit #36

Open agnBIM opened 10 months ago

agnBIM commented 10 months ago

We needed to be able to open models from our Revit server with xUnitRevit and couldn't find a solution in the existing repo.

This is now the only way to open a model:

/// <summary>
/// Opens and activates a document if not open already
/// </summary>
/// <param name="filePath">Path to the file to open</param>
public static Document OpenDoc(string filePath)
{
  Assert.NotNull(Uiapp);
  Document doc = null;
  //OpenAndActivateDocument only works if run from the current context
  UiContext.Send(x => doc = Uiapp.OpenAndActivateDocument(filePath).Document, null);
  Assert.NotNull(doc);
  return doc;
}

So we added the OpenDoc() function with the correct parameters for cloud/server models from the Revit API to the xru class in the xUnitRevitUtils:

/// <summary>
/// Opens and activates a document from server or cloud
/// </summary>
/// <param name="filePath">Path to the file to open</param>
/// <param name="openOpts">Opening Options for Cloud Models</param>
/// <param name="detach">Boolean to determine if file should be detached from central</param>
public static Document OpenDoc(string filePath, OpenOptions openOpts, Boolean detach)
{
  Assert.NotNull(Uiapp);
  Document doc = null;
  //OpenAndActivateDocument only works if run from the current context
  UiContext.Send(x => doc = Uiapp.OpenAndActivateDocument(ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath), openOpts, detach).Document, null);
  Assert.NotNull(doc);
  return doc;
}

Do more people feel the need for this feature? If so, we would prepare a PR for it.

phat-hongTran commented 2 months ago

I created one on my own. It must be helpful if it already supports the call to cloud model.