Sincpac C3D Source Code

If you are interested in learning how to customize Civil 3D, then you may find this source code helpful.  It contains a small portion of the functionality of the Sincpac-C3D, with several fully-functional commands.  In addition, it includes some core frameworks that provide many routines that you may find useful in your own programs.

This source code is written in C#, although you may also use the enclosed libraries for developing your own routines in any other .NET language.

If you are just starting with .NET, you may find it helpful to keep an eye on the Civil3DReminders blog, where Christopher will shortly have a series of posts on how to customize Civil 3D, using this Free Edition code as a starting point.

License

For this software, we have decided to utilize the same terms currently being used by the #ziplib team.

The library is released under the GPL with the following exception:

Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination.

As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.

In other words, you may freely use this source code in your commercial closed-source applications.

Download

The source code may be downloaded from the following link.  This download contains solutions created in Visual Studio, with versions for Civil 3D 2008, 2009, 2010, and 2011.

All solutions are in the same download file, and share the same source code files.  You may build any or all of the solutions, as you desire.

Sincpac-C3D FreeEditionV2 Source Code
(released May 27, 2010)

Latest Sincpac-C3D Help file
(optional download, but required for Help functionality to work)

Usage Notes

Here are some important notes about how this source code is configured, and how to use it.

Extension Methods

The AcadUtilities and C3DUtilities subprojects in this source code are subsets of the same libraries from the Full Edition of the Sincpac-C3D.  The actual Sincpac-C3D source code is much more elaborate, but there is quite a bit of useful functionality in this free source code.

Most of the functionality in the AcadUtilities and C3DUtilities subprojects is implemented in the form of extension methods.  These methods extend the classes found in the Autodesk APIs, adding additional methods to those classes.  These extension methods behave the same way as the methods defined within the class itself, just as if the extension methods were built-in to the Autodesk APIs.  If you include references to the AcadUtilities.Extensions and C3DUtilities.Extensions namespaces in your code, you will see the additional methods in Intellisense as you write your code.  For example, the AcadUtilities subproject adds a SelectLayer() method to Autocad's Editor class.

ObjectARX

These solutions are configured to reference the ObjectARX libraries.  So prior to opening this source code, it is helpful to download and install the ObjectARX libraries from Autodesk.

Development Environment

The solutions in this download were created using Visual Studio 2008.  If you do not have Visual Studio, you may wish to download Visual Studio Express C# Edition or SharpDevelop in order to edit and compile this source code.  (Both options are available for free download.)

The remaining instructions on this page are for Visual Studio, but much of the information also applies to SharpDevelop, with minor modifications to account for the differences between the two development environments.

This source code was written in C#.  However, you can use AcadUtilities and C3DUtilities library frameworks in any .NET-enabled language.  For example, to use these libraries in VB.NET, simply add references to the AcadUtilities.dll and C3DUtilities.dll to your VB.NET project, and you may then utilize the functionality just as if it had been written in VB.

64-bit vs. 32-bit Operating System

The 2008-2010 solutions are configured to build on a 32-bit system with the appropriate ObjectARX libraries installed.

If you are using a 64-bit Vista or Windows 7 system, the easiest way to get the source code to build on your system is to create a link in the "C:/Program Files" directory, using the mklink command.

To do this, first start up a command window, using administrative privileges.  In other words, go to the Start Menu and find the Command Prompt, then right-click on it and select "Run as administrator".  Then create the link as shown in the image below (which you may need to modify slightly, depending on your version of Civil 3D).

MKLINK console window output

Once you have created this link, you should be able to start up Visual Studio and open the solution, and all the references should resolve correctly.

The other option is to fix all the references, so that they load from the correct directory.  If you are using Windows XP x64, you will probably need to use this option, since the mklink command is not available in Windows XP.

The 2011 solution should build correctly on either 32-bit or 64-bit systems, since Civil 3D 2011 gets installed in the "C:\Program Files" directory on both types of systems.

Security Warning

The first time you open a solution in Visual Studio, you will see a Security Warning.  This is because the project files were edited to add an intermediate build path for each version, to keep the different versions from conflicting with each other.  Configure the dialog to load all projects normally, as shown below, and hit OK:

Visual Studio security warning

You will see this dialog for each solution (2008 through 2011), but you should only see this message the first time you open each solution.  After that, you should no longer see this message.

Configuring for Debugging

To configure each solution so that it automatically launches the correct version of Civil 3D when you run the project in Visual Studio, first make sure that the SincpacC3D project is set as the startup project.  If necessary, right-click on the SincpacC3D project, and select "Set as StartUp Project".

Next, make sure Visual Studio is configured to start Civil 3D when you run the project.  This is specified on the Debug tab of Visual Studio.  If you have Visual Studio Express, you cannot set this up inside of VSE, but instead must edit the .csproj.user file in another editor such as Notepad.  The provided solutions contain .csproj.user files for each solution (these files can be found in the SincpacC3D project).  These files are preconfigured to point to the default install location for the appropriate version of Civil 3D, so you may not need to modify these files.

Finally, it is also convenient to configure Civil 3D to automatically load our debug DLL as it starts up, so we don't have to manually load it.  This can be accomplished by adding a line like the following to your acad.lsp file:

(command "netload" "C:/FreeEditionV2/SincpacC3D/bin/Debug2011/Quux.SincpacC3DFree2011.dll")

Depending on where you have placed the source code, you may need to edit the path to point to the correct location on your system.  (You can also eliminate the path from the netload command, and make sure the DLL is in a directory in your Autocad support path.)  This string is for the 2011 version; you will also need to modify the netload command as necessary for the 2008, 2009, and 2010 versions.

(Note: if you do not have an acad.lsp file, you can simply create one in a text editor such as Notepad, and place it in a directory in your Civil 3D support path in OPTIONS -> Files.)

.NET vs. ActiveX (COM)

The Civil 3D API is still mostly an ActiveX (COM) API, but it is gradually moving toward becoming a .NET API.  Unfortunately, at the moment, most Civil 3D customization requires simultaneously using both the ActiveX and .NET APIs, because each API contains functionality that is unavailable in the other.

As a result, you will see many places in the code where objects are converted from one form to the other.  A .NET DBObject can be converted to a COM object using the DBObject's AcadObject property, while a .NET ObjectID can be extracted from a COM object by using the DBObject.FromAcadObject() method.

Since much of this sample source code was written using Civil 3D 2008, all interactions with Civil 3D in this source code use the ActiveX API.  Much of the core interaction with Autocad is done using .NET, but all Civil 3D entities are converted to ActiveX objects in order to access their civil capabilities.

However, each version of Civil 3D has included greater and greater access to Civil 3D objects using the .NET API.  Starting with Civil 3D 2010, you can include references to the managed libraries (AecBaseMgd.dll and AeccLandMgd.dll), and then you can work with at least some Civil 3D entities completely in .NET.  Eventually, once the .NET API is complete enough, we will post a new version of this source code, with all ActiveX references converted to .NET.  However, that won't happen until the Civil 3D .NET API is complete enough, which may be several more years yet.