If you plan to start developing for any new product, a quick ‘getting started’ guide can be very useful. Here is what you need to develop for AutoCAD P&ID/Plant 3D 2013.
Setting up the environment:
- Product: there are two options: AutoCAD P&ID and AutoCAD Plant 3D. Check the trial versions available at http://usa.autodesk.com/products/free-product-trials.
From the API perspective, the second includes the first. An application developed for P&ID can load on Plant 3D and work according to the current project/drawing type.
- Develop interface: to develop for AutoCAD P&ID and Plant 3D we need a programming environment.
The P&ID/Plant 3D API was developed in .NET, which means we can use any .NET programming language, where VB.NET and C# are supported by Autodesk. It’s also possible to use Managed C++, also supported, but recommended for advanced developers.
Microsoft offers the Visual Express edition to get started, just keep in mind that the version 2010 is required for AutoCAD 2013 based products. Make sure you download either Visual C# 2010 Express or Visual Basic 2010 Express.
There is no relevant difference between C# to VB.NET regarding API features, so it’s a matter of which one you fell more confortable. Anytime you find code on one language and want to translate to the other, consider translate using online services like Developer Fusion. Most of posts on this blog are in C#.
- SDK: the software development kit (SDK) contains all the files required to compile the code. Download it from ADN P&ID/Plant 3D Developer Center, make sure you download the proper version, e.g. 2013. As this product is based on AutoCAD, we also need to download the AutoCAD SDK (again make sure you select 2013).
Due changes on the APIs, 2012 is not compatible with 2013, so applications developed for 2012 will not load on 2013. Some code change may be required before recompile.
Documentation is available under \Plant SDK 2013\docs\ folder. The plantsdk_dev.chm file is like a book, with first steps at the beginning and the topics advance throughout the reading. Now the plantsdk_ref.chm contains a full list of API objects and methods, useful for daily basis consult.
The SDK also contains several interesting samples under \Plant SDK 2013\Samples\ folder. The same applies to AutoCAD SDK under \ObjectARX 2013\samples\.
With all the above downloaded and installed, launch Visual C# Express or Visual Basic Express. Here I’ll show some images on Visual C#. Go to menu ‘File’, then ‘New Project’. On the window, select ‘Class Library’ as project type, finally give it a name, that cannot contains spaces or start with numbers (e.g. MyFirstPlant3DApp).
Now, following the image below, (1) go to ‘Solution Explorer’ palette. If you cannot see it, go to menu ‘View’, then submenu ‘Other Windows’ and select it. Now (2) right click on references to ‘Add Reference’.
On the window that opens (not shown), click on ‘Browse’ and navigate to AutoCAD SDK folder. Under \ObjectARX 2013\inc\ select AcMgd.dll, AcCoreMgd.dll and AcDbMgd.dll. These references will be used to access AutoCAD basic features required to build an application, such as command line and selection mechanism.
Now to add P&ID and/or Plant 3D references, navigate to \Plant SDK 2013\inc-x64\ or \Plant SDK 2013\inc-win32\ depending on your OS configuration. References prefixed with PnID*** are for P&ID and Plant 3D, references prefixed with PnP3d*** are for Plant 3D only.
All AutoCAD and P&ID/Plant3D references must be marked with Copy Local equals false. This is extremely important. Otherwise, AutoCAD may crash unexpected.
After copy & paste any sample code or write your own, go to menu ‘Debug’ then ‘Build Solution’, which will build a .dll, for this sample project, it should be at bin\Release\MyFirstPlant3DApp.dll (Visual Express always create .dll at Release folder for Build and at Debug folder while debugging, pay attention).
Now start AutoCAD P&ID/Plant 3D and run NETLOAD command, choose the .dll generated by your project, finally run the custom command.