The Revit Server REST API

Download Report

Transcript The Revit Server REST API

Automating Autodesk® Revit® Server
Rod Howarth
Software Development Manager – Bornhorst + Ward
© 2011 Autodesk
Class Summary
This class will explore the API’s that are exposed by Autodesk Revit Server and
how we can make use of them in some interesting applications.
© 2011 Autodesk
Learning Objectives
At the end of this class, you will be able to:
 Explain how Revit server automation can be integrated into existing software
processes
 Describe the REST interface to Revit Server
 Combine the Revit Server command line and the Revit API to perform a task in a
Revit model on a schedule
 Use the supplied command line utility to create local files from Revit Server
© 2011 Autodesk
Agenda

Revit Server Background
 REST API Overview

Intro
 What is REST?
 How to access it
 Rest API overview
What can I use it for?

HTML Server Admin
 Interface with existing system

Revit Server Command Line Tools


Creating local files
Opportunities
© 2011 Autodesk
Revit Server Background
© 2011 Autodesk
Revit Server Background

Young product

Replaces file system storage of central files

Optimizes network traffic

Allows replication

Hosted in IIS

Web based administration tool
© 2011 Autodesk
Admin Tool
© 2011 Autodesk
REST API Overview
© 2011 Autodesk
Revit Server API – What is it?

Allows administration of folders and models

Exposes the functionality from the online admin tool

User guide available in the Revit SDK

Web based API

Uses REST
© 2011 Autodesk
What is REST?

Representational State Transfer (REST)

Web based API that uses URLs to interact


Based on HTTP specification

Browsers access websites in the same way
Uses HTTP Verbs

GET - Read only retrieval of a resource

POST – Modify/update a resource

PUT – Create/Overwrite a resource

DELETE - Delete a resource
© 2011 Autodesk
What is a resource?

A resource is identified by a URL (Uniform Resource Locator)


Verbs and query string define what to do to this resource


Browsers request a ‘resource’ from a web server (usually GET requests)
Querystring is the ?parameter=value&parameter2=value
Server responds with response code and data

404 is a HTTP response code for resource not found

200 is the code for success
© 2011 Autodesk
Anatomy of a HTTP request
Verb
Host Name
Resource
GET http://usa.autodesk.com/company/ HTTP/1.1
Header: value
Protocol
Header2: value2
HTTP Version
Header list
© 2011 Autodesk
Anatomy of a HTTP Response
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Response Code
Content Type
Header: Value
Header2: Value2
<html><head><title>About Autodesk</title>
Header list
Raw Data
</head><body>We are a software
company that make Revit</body>
</html>
Data can be HTML, JSON,
XML, Binary or other formats
© 2011 Autodesk
REST APIs



URL and the Verb combine to act as a sort of method call
URL identifies what you what resource you are using
Verb specifies what action to take

Same URL with different verbs can be totally different
 GET http://servername/resource returns the resource
 DELETE http://servername/resource deletes it
 Big difference!

Querystring can be used to supply extra parameters

DELETE http://servername/resource?newObjectName=newName could rename to
newName
 Leave out Querystring to delete
© 2011 Autodesk
How to access REST services

Standard HTTP request

Use anything capable of HTTP requests

C# and VB have System.Net.HttpWebRequest

Jquery(Javascript) has $.ajax()
© 2011 Autodesk
Why REST?

Many advantages

Hosted on a web server

Use them with any programming language capable of a web request

Consistent and self describing interface

Very popular on the web

Flickr is well known for having a good REST API
© 2011 Autodesk
More on REST
Further Resources
 Nettuts+ - http://goo.gl/EHxmH
 O’Reilly RESTful Web Services Book - http://goo.gl/NiuAh

Probably more for people making RESTful API’s
View HTTP requests
 Firebug in Firefox
 F12 in Chrome and IE then click ‘Network’
 Fiddler2 (http://fiddler2.com) lets you view ALL request on your system

Very useful for testing your Revit Server API access
© 2011 Autodesk
JSON
{
"Path": string,
"Items":

JavaScript Object Notation

Alternative to XML/HTML for displaying data

Easy to use with Jquery

Requires parsing in .NET
[
{
"Comment": string,
"Date": DateTime,
"User": string,
"VersionNumber": int,
"ModelSize": int
}
]
}
© 2011 Autodesk
The Revit Server REST API

Specification in SDK

Base URL:
http://servername/RevitServerAdminRESTService/AdminRESTService.svc


Required headers to identify yourself when making requests
Information Querying APIs


Get server properties, folder contents, directory info, model save history
Data Managing APIs

Lock models/folders, delete locks
 Create, delete, move, rename and copy folders/models
© 2011 Autodesk
Quick Examples


GET /{folderPath}/contents

Returns a JSON object listing the models and folders

For example GET http://BASEURL/AUJob/contents

To get the contents of the parent dir use a space GET http://baseurl/ /contents
PUT /{objectPath}/lock

Locks the specified folder or model (object can be either)

For example PUT /AUJob|Subfolder|Model_01.rvt/lock

Notice that | is used instead of the familiar / in the path

This is because the / would form part of the URL
© 2011 Autodesk
What can I use it for?
© 2011 Autodesk
HTML Server Admin

Existing interface is Silverlight based

This is ok, but requires installation and won’t work on mobile

Revit Server API gives us same functionality

We can use this API to build a HTML replica

With a little help from JQuery
© 2011 Autodesk
Demo
© 2011 Autodesk
Interface with existing system

A more likely scenario is linking with an
existing system

For example, a project records system

User enters project details, and it is stored in a database

Want to make a Revit Server folder automatically for new projects
© 2011 Autodesk
Demo
© 2011 Autodesk
Revit Server Command Line Utilities
© 2011 Autodesk
Revit Server Command Line Utilities

2 similarly named utilities

RevitServerCommand


Allows you to lock/unlock models/folders

Already seen 2 other ways of doing this

Ships in Revit Server folder
RevitServerToolCommand

Ships in the Revit Directory on all users PC’s

Lets you create local files from a Revit Server
© 2011 Autodesk
RevitServerToolCommand



Create local files
Located under Revit Dir
Program\RevitServerToolCommand
© 2011 Autodesk
Opportunities
© 2011 Autodesk
Opportunities

Already seen some potential use cases, but more to ponder…

Revit Server has all of your files stored on your servers

This data is replicated automatically to all locations

Quick access to Revit files on any Revit Server

Ability to lock and unlock files
© 2011 Autodesk
Revit Remote Boot

Last example of what you could do with these API’s

This tool lets you run some code on a model at scheduled times

Very fragile, prototype only


(Revit isn’t meant for this kind of thing)
May give you ideas for your own tools
© 2011 Autodesk
Demo
© 2011 Autodesk
Conclusion

Revit Server is still a young product

But already has a great API

REST lets you access from anywhere

Command line tools provide even more access

Plenty of things you could make

Contact me via [email protected] or twitter.com/rodh257
© 2011 Autodesk
Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and
services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2011 Autodesk, Inc. All rights reserved.
© 2011 Autodesk