Building Applications for DraftSight
We’re going to step away from the Customer Stories just for the moment and get tech heavy. Today’s blog, as you can guess from the title, deals with building applications for DraftSight. So, why exactly might you want to build an application for DraftSight? Well, DraftSight customers are constantly looking for ways to improve their efficiency while working with it. How? Well, I give some examples below:
- Customers need to automate their work flow.
- Customers work with other systems (ERP, PDM, databases, etc…) and need to integrate DraftSight into those work flows
- Customers have migrated from other CAD applications, where they have some add-ins working which no longer work in DraftSight.
In addition to this, DraftSight Partners, Resellers and Service Providers also like to develop add-ins to improve the DraftSight experience for their users. How do they do all this? They use the DraftSight API. What is the DraftSight API? Well, let me explain.
High Level Solution
DraftSight API is a set of methods and interfaces available for users to customise DraftSight to automate their workflow and interact with all the elements which make up DraftSight (UI, drawings, etc…). It allows customers and partners to develop powerful add-ins which seamlessly work with DraftSight and make use of the same core elements with which DraftSight is 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.
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 develop either 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) or 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 so users can add menus, toolbars, dockable windows and so on, so that the add-in would look like a native DraftSight feature. All the entities in the drawing are available through the API so developers can query, update and run rich modifications to the entities.
The C++ and .NET add-ins can be developed using Visual Studio 2008 and above. To assist developers in getting started, DraftSight provides templates for Visual studio through which a lot of boiler plate code is pre-generated to connect the add-in to DraftSight. Users can then focus on writing code relevant to their workflow rather than spending time in writing this connection.
AutoLISP can be loaded directly inside DraftSight and run. Visual Lisp support is on the product future plan.
Existing add-ins from other CAD applications need to be re-written in DraftSight API.
Another quick way to develop add-ins is through the Macro feature. Users can record their operations in any of the supported languages. Users can either build add-ins to replay those sequences, or use Macros as a start to automate more sophisticated workflows.
In addition to standard programming languages like C++, C# and VB.NET, developers can write add-ins using JavaScript and HTML. This way, developers can build compelling web pages to 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.
The following graphic displays some of the interfaces and event enumerations available with the API. The entire list is available in the API documentation:
Developers can choose to develop an application either using scripting in
- VBA
- JavaScript
Or compiled languages in:
- VB/C#.NET
- C++ COM
- C++
Rapid Application Development Using DraftSight Add-in Templates
To assist developers to build new add-ins or migrate their existing customisation from other applications, DraftSight installer ships pre-built templates for Visual Studio. These templates are available for the programming languages that DraftSight supports, C++, C# and VB.Net. For C++, DraftSight provides templates for both COM and native C++ add-ins. Please refer to image below that shows the template for C#:
These templates automatically generate all the boiler-plate code required for an add-in to be loaded inside DraftSight. Please see image below:
In addition, the auto generated code includes all the code, along with toolbars, that is required to execute a sample command that developers can use as a starting point to either extend or implement sophisticated additional customisation. Please see image below:
The benefit to developers is that without writing a line of code, you have a working add-in to load inside DraftSight. All that developers needs to do is to add your changes to implement specific commands, compile the code and load the resulting output DLL in DraftSight using the “Load Application” button available on the ribbon. Please see image below:
After loading the add-in, for the above sample project, the user can now see the toolbar with the button for the sample command. Please see image below.
Summary
To summarise, DraftSight API is a powerful SDK available for users to automate manual operations and to integrate DraftSight into the existing work flow. It supports both modern and legacy languages and comes with documentation and tools for rapid development. The breadth of the API is wide so users have everything needed to migrate existing add-ins from other applications to DraftSight.
And that is an introduction to the DraftSight API SDK and Building Applications for DraftSight. I told you it was going to get a bit tech heavy! If you are an Enterprise, Premium or a Professional user, why not try the SDK for yourself and see what time saving tools you can develop!
Learn more about DraftSight and how to start a free 30-day trial here.