Copy a Model from a Revit Server

Yesterday evening we had dinner together with developer partners at
Heaven 23 again,
the same place we visited

last year
,
with its unique reflection-accessible cloud.

Today we are holding a DevLab here in the Autodesk office in Gothenburg in Sweden, providing an opportunity for developers to come visit us with their day-to-day work in progress and current issues.

Meanwhile, here is a question related to the

Revit Server and its API
:

Question: How can I copy a Revit file out of Revit server 2012 to a network location?
I need something similar to the

RevitServerViewer sample
,
but instead of just relaying the information of the file I would like to get the actual file definition, assign it to an object in .NET, and use standard I/O operations to copy it to multiple other servers.

Answer: Look at the Application.CopyModel method.


public void CopyModel(
ModelPath sourceModelPath,
string destFilePath,
bool overwrite )

It copies an existing model to a new file, which can then be copied elsewhere as needed.

It takes the path of the file and does not require opening the file.
It accepts the path of the server (or file) based source file and the destination path, besides a Boolean specifying whether you wish to overwrite the destination file or not.

If you have to copy multiple files, you can call this method multiple times specifying different source and destination information for each file.

This method is a Revit API method, so it does require Revit to be up and running and must be called in a valid Revit API context.
As you can see in the “Revit Server REST API Reference.pdf” in the Revit Server SDK, the REST API supports copying or moving a specified folder or model to another folder within the Revit Server without starting up Revit, but not copying a model to a network location outside of the server.

Addendum

Please note that downloading from Revit Server requires an RSN.INI entry.


Comments

4 responses to “Copy a Model from a Revit Server”

  1. Is it possible to do the reverse? For example, could I copy a file from a file-share and upload it to Revit Server? Sort of like uploading it, but in a programmatic way?
    Feel free to email me if you need to!

  2. Dan Tartaglia Avatar
    Dan Tartaglia

    Hi John,
    I asked ADN is very question about a month ago. Here’s the answer:
    Unfortunately, Revit Server REST API cannot move files between the server and the local machine – no download, no upload.
    You can use the Revit API to download files, but not to upload.
    There is also an utility that enables you to create local copies: “\Program\RevitServerToolCommand\RevitServerTool.exe”
    However, programmatically uploading is not yet possible way at the moment.

  3. Hey Dan,
    Thanks for the update. I’m currently just working on some research for a client to see if this is possible. Sad that it’s not, but not the end of the world right now (for me).
    Hopefully we’ll see this functionality in the future; would be useful for sure (HINT HINT Autodesk…).
    Thanks!

  4. Hey Dan,
    Do you have the link to your post on ADN? Would be super helpful to add for my documentation purposes in my wirte-up. Thanks! :-]

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading