DraftSight API

We are going to get a little serious in todays blog, no more t-shirt making or vinyl cutting for the moment.  Today we are going to deal with the DraftSight API SDK.

Some of you may be wondering “What is the DraftSight API SDK?” and the simple answer to that is the DraftSight API SDK contains a rich set of facilities that can help you add new functionality to the DraftSight software.

Automating tasks within DraftSight can speed up production of drawings, basically it will allow you to leverage more margin from your business. Your business can use DraftSight API to do the following:

  • Automate the workflows.
  • Integrate DraftSight into your own workflows involving other systems (ERP, PDM, databases etc)
  • Create add-ins in DraftSight that simulate the behavior of other CAD application addins.

So, if that is of interest to you and your users, then read on. One point of note though, the DraftSight API is only available in the DraftSight Enterprise and Professional versions.

I’ll start with a brief Overview of the DraftSight API SDK.  This will be a bit text heavy, but I’ll do my best to make it an easy read.

The DraftSight API SDK contains a rich set of facilities that can help you add new functionality to the DraftSight software. The SDK includes a set of methods and interfaces available for users to customize DraftSight. It allows customers to develop powerful add-ins which seamlessly work with DraftSight and make use of the same core elements with which DraftSight was built.

It provides templates through which developers can write add-ins fairly quickly, a set of examples which teach how the API can be used to automate some common work flows and documentation which contains plenty of code snippets that can be used directly in the application.

Examples of Add-ins that have been built using the DraftSight API are:

  • Flowcharts and diagrams
  • PDF Import for DraftSight
  • Online Maps for DraftSight

The DraftSight API provide access to a significant portion of the functionality of DraftSight. This includes, but is not limited to, the ability to create and modify data such as geometry in the drawings, customize the Ribbon User Interface etc.

DraftSight API is available for developers to write applications in the following languages.

  • C++
  • C++ COM
  • C#
  • VB.NET
  • JavaScript
  • LISP

The API interfaces are consistent across all the languages we support and are forward compatible. Developers can use the API to:

  • Develop external applications which automate a repetitive task (e.g., A VB.net application which batch prints a bunch of documents at a scheduled time every day)
  • Develop add-ins where they integrate an external application into their work flow (e.g., integrate EPDM or SAP).

In the second case, the DraftSight UI is fully accessible and users can add menus, toolbars, dockable windows etc.  The end result is that the add-in would look like a native DraftSight feature. All the entities in the drawings are available through the API and as a result the developers can query, update and do a whole lot of modification to those entities.

The C++ and .net Add-ins can be developed using Visual Studio 2008 and above. To assist developers to get started, DraftSight provides templates for Visual Studio through which a lot of boiler plate code (code which connects the add-in to DraftSight) is pre-generated.

Users can then focus on writing code which is relevant to their work flow rather than spend time in writing this connection code. LISP modules work without much effort (some LISP functions are not supported) but existing add-ins from other CAD applications need to be re-written in DS API.

Another quick way to develop add-ins is through the Macro feature, available in V1R5 and later. Users record their operations in any of the supported languages and either build add-ins which replay those sequences or use it as a starting to automate more sophisticated work flows.

In addition to standard programming languages like C++, C# and VB.NET, developers can write add-ins using JavaScript and HTML. The same API which is available for the other languages is now available in JavaScript so developers can build compelling web pages which connect to the data available in drawings. For example, users can build a web page using JavaScript to query the rooms on a floor plan and generate reports out of it.

In terms of the hierarchy, the Application object lies at the top with all the other objects below it in a tree structure. The following graphic demonstrates the top hierarchy:

The following graphic displays some of the interfaces and event enumerations available with the API. The entire list is available in the API Documentation:

As said previously, a developer can choose to develop their application either using scripting, for which they could use the following:

  • VBA
  • JavaScript

Or compiled languages for which they could use any of these:

  • VB/C#
  • .NET
  • C++ COM
  • C++

If you are a VAR, you could obviously build and deploy these add-ins for your enterprise customers. You could also provide consultancy services for customers who want to build these add-ins.

So, in summary, the DraftSight API is a powerful SDK available for enterprise and professional users to automate their manual operations and to integrate DraftSight into their existing work flow. It supports both modern and legacy languages and comes with extensive documentation, source code and tools for rapid development. The API provides everything that one needs to migrate their add-ins from other applications.

And that is an introduction to the DraftSight API SDK.  If you are an Enterprise or a Professional user, why not try the SDK for yourself and see what time saving tools you can develop!

To purchase DraftSight Professional with its productivity-boosting features for just $99, click here.

Discover more about DraftSight Professional, a powerful 2D design solution for professionals that includes productivity tools and an API for just $99.




MJ Smyth
The first time I used CAD, it was on a DOS PC with an 8088 processor, 640K of memory and a Hercules Mono Graphics Card... That, well that was a long long time ago. I switched to DraftSight the day it was released and haven't looked back!
MJ Smyth

Latest posts by MJ Smyth (see all)