Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BIM 360 REST API to get Model Size?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mehdi.blanchard
1963 Views, 4 Replies

BIM 360 REST API to get Model Size?

I am using a macro to retrieve the model size.

For Revit Server files, I was able to use the REST API as follows:

ModelPath modelPath = doc.GetWorksharingCentralModelPath();
string server = modelPath.CentralServerPath; string fullPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(modelPath);
string[] splitPath = fullPath.Split(new string[] {"/"}, StringSplitOptions.RemoveEmptyEntries); string restPath = string.Join("|", splitPath.Skip(2))); //removing protocol and server name WebRequest request = WebRequest.Create("http://" + server + "/RevitServerAdminRESTService" + version + "/AdminRESTService.svc/"+ restPath + "|/modelInfo" ); request.Method = "GET";

If I try to use a similar code on a BIM 360 file I get the error message below:

"The remote server returned an error: (400) Bad Request."

 

Note: the server (CentralServerPath) returns something like:

"https://modelxyz.skyscraper.autodesk.com:443/ModelService2015/ModelService.svc/basichttpbuffer"

 

So I am wondering:

  1. Is the REST API available on a BIM 360 model?
  2. If it is available how different is it to access it?
  3. If it is not available, is there another way to get the file size?

Note: I saw a Dynamo Script that gets the document GUID (doc.WorksharingCentralGUID), and search for the GUID.rvt in the local cache folder 

 

 

4 REPLIES 4
Message 2 of 5

The "https://modelxyz.skyscraper.autodesk.com:443/ModelService2015/ModelService.svc/basichttpbuffer" is for Autodesk internal use only as I know, 3rd party users/customers cannot access it directly, you should use Forge APIs instead.

 

Here are some reference for getting started on the Forge:

https://fieldofviewblog.wordpress.com/forge/

 

Before getting the file size, you have to find the right item in the response of the Forge API GET projects/:project_id/folders/:folder_id/contents. You can iterate all file versions of items in the API response, then find matched projectGUID and ModelGUID in the "extension.data" attribute, like this:

 

{  
   "type":"versions",
   "id":"urn:adsk.wipprod:fs.file:vf.abcd1234?version=1",
   "attributes":{  
      "name":"fileName.rvt",
      "displayName":"fileName.rvt",
      ...
      "mimeType":"application/vnd.autodesk.r360",
      "storageSize":123456,                                         //!<<< physical size of the RVT file
      "fileType":"rvt",
      "extension":{  
         "type":"versions:autodesk.bim360:C4RModel",
         ....
         "data":{  
            ...
            "projectGuid":"48da72af-3aa6-4b76-866b-c11bb3d53883",  //!<<< Here
            ....
            "modelGuid":"e666fa30-9808-42f4-a05b-8cb8da576fe9",    //!<<< and here
            ....
         }
      }
   },
   ....
}

 

Then you can get the physical size of the RVT file in bytes, see remark "//!<<< physical size of the RVT file" above. For more details, please see  https://forge.autodesk.com/blog/accessing-bim-360-design-models-revit

 

Note. To obtain both projectGUID and ModelGUID of the model you wanted to check the size, please call ModelPath#GetProjectGUID and ModelPath#GetModelGUID, see API docs here: http://www.revitapidocs.com/2018.1/f214cb44-8350-054e-821a-53571769f236.htm

 

Another way is checking the file stored in BIM360 OSS bucket. For using this approach, please refer my answer on a StackOverflow thread: https://stackoverflow.com/a/50520985/7745569

 

Hope it helps!

 

Cheers,

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

Message 3 of 5

Thanks Eason,

I am not using Forge yet so I have just adapted the dynamo script to a C# script for now by locating the file in the cache folder.

 

string fullPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(modelPath);
if (fullPath.StartsWith("BIM 360")) {
  string folder = "C:\\Users\\" + Environment.UserName + "\\AppData\\Local\\Autodesk\\Revit\\Autodesk Revit " + app.VersionNumber + "\\CollaborationCache";
  string revitFile = doc.WorksharingCentralGUID.ToString() + ".rvt";
  string[] files = Directory.GetFiles(folder, revitFile, SearchOption.AllDirectories).Where(c => !c.Contains("CentralCache")).ToArray();
  if (files.Length > 0) {
    double length = (double)(new System.IO.FileInfo(files[0]).Length);
    int modelSize = Convert.ToInt32(Math.Round(length / BYTES_TO_MB));	// conversion from Bytes to MegaBytes
  } 
}

 

 

 

Message 4 of 5

Hi Mehdi,

It's nice to hear that you found your own solution without playing with the Forge.

 

Cheers,


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

Message 5 of 5
snhaMOSES
in reply to: mehdi.blanchard

Hello.

 

I am new to C#

What classes and namespaces are necessary to make this code work?

When i put the line below into Macro editor i get an error concerning 'modelPath'

string fullPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(modelPath);

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community