Civil 3D Project Template for Visual Studio

By Augusto Goncalves

This is a long time request: an easy way to create a Visual Studio project for Civil 3D using VB.NET or C#.

If you visit the AutoCAD Developer Center you’ll see some AutoCAD .NET Wizards for both VB.NET and C#, which is very powerful and can be customized. Some time ago I started by doing some templates for Revit, which still in use, so now I decided to try one for Civil 3D, and here it is.

Basic benefits:

  • Create a simple project, nothing else;
  • Configure all required references (AcMgd, AcCoreMgd, AcDbMgd, AecBaseMgd and AeccDbMgd) with respective reference paths;
  • Debug settings ready;

Extra benefits:

  • Create a basic PackageContents.xml with the basic required tags and attributes for Civil 3D;
  • On build, copy all the files (DLL and XML) to a newly created folder under Application Plugins folder;
  • On clean, remove the plugin folder from Application Plugins

Cons:

  • The path are hardcoded to 2015 release. If you are using a different version, you’ll need to open and change the paths and reference versions.

To use it, simple download the packages below and place under [My Documents]\Visual Studio 2012\Templates\ProjectTemplates\Visual Basic\ folder for VB.NET or [My Documents]\Visual Studio 2012\Templates\ProjectTemplates\Visual C#\ folder for C#. Do not unzip the files.

VB.NET Template

C# Template

With the template .ZIP file in place, you should see the following:

new_project

Tip: you can organize it better by creating a subfolder “Autodesk” and placing the ZIP at this location.

Finally, I will be using these template at the AU Russia next week, if you are attending, come and say ‘hi’.

au_russia


Comments

4 responses to “Civil 3D Project Template for Visual Studio”

  1. Hi Augusto,
    I was wondering if you know anything about the unhandled exception in the following code:
    PromptEntityOptions prompt = new PromptEntityOptions(“\nSelect Base Line Region:”);
    prompt.SetRejectMessage(“\nObject must be a Base Line Region:\n”);
    prompt.AddAllowedClass(typeof(BaselineRegion), true);
    The last line throws the following exception:
    System.IndexOutOfRangeException was unhandled
    HResult=-2146233080
    Message=Index was outside the bounds of the array.
    Source=Acdbmgd
    StackTrace:
    at Autodesk.AutoCAD.Runtime.RXObject.GetClass(Type type)
    at Autodesk.AutoCAD.EditorInput.PromptEntityOptions.AddAllowedClass(Type type, Boolean exactMatch)
    InnerException:

  2. Mehdi,
    In fact this Prompt option will only work for Database resident entities… as the BaselineRegion is not one of those, it will not work…
    Note there is no ObjectId property, meaning is not a database entity…
    Hope this clarifies.
    Regards,
    Augusto Goncalves
    (Some comments are requiring a manual approval, so don’t worry, we’re receive the notification)

  3. Jeremy Avatar
    Jeremy

    Augusto,
    I also have a question about an Unhandled Exception. I wrote a program that downloads GIS data. The URL has the year in it, and this varies from file to file. It runs through a loop using different years and calls the following function to check the URL before downloading:
    Public Function CheckURL(ByVal URL As String) As Boolean
    Try
    Dim request As WebRequest = WebRequest.Create(URL)
    Dim response As WebResponse = request.GetResponse()
    response.Close()
    request = Nothing
    response = Nothing
    Catch ex As Exception
    Return False
    End Try
    Return True
    End Function
    When I compile a standalone executable, it runs perfect. When I copy this into the Civil3d template and call the command after net-loading the .dll, it crashes at the “GetResponse()” line when the URL is not valid. Why does it work in a standalone, but not in Civil3D? I can’t figure out why the ‘try-catch-ex’ doesn’t catch this exception like it is supposed to.
    Any thoughts would be greatly appreaciated. Thanks!

  4. Jeremy,
    I would suggest check permissions and/or .NET version. As this question is not on this post, please create a new question at http://forums.autodesk.com/t5/autocad-civil-3d-customization/bd-p/190 so we can discuss it.
    Regards,
    Augusto Goncalves

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading