ZeroTouch for Dynamo for Civil 3D

In the world of programming for Dynamo, when you create a package of custom nodes, it’s referred to as ZeroTouch. I don’t know where that comes from, but I’m sure someone out there knows. This post will cover how to setup a Visual Studio project for the minimum requirements to create your own ZeroTouch node package. This post will only deal with a single version of Civil 3D, but if you’d like to set up your project to be multi-version compatible, you can follow the steps in this blog post and make adjustments to these steps accordingly. The first part of this process is just like setting up a standard Autocad or Civil 3D project, so I will not show many screenshots. You can see the blog post I just referenced for more info on that.

I am using Visual Studio 2019 for this post, but you should be able to use any version that will work with your version of Civil 3D. Start by selecting the Create New Project option and select the Class Library (.NET Framework) template for your language of choice. I will be using C#, but I believe VB will also work. In the Configure your new project dialog, provide a name for the project, a location and solution name. Click the Create button once you’re done and you’ll be presented a blank project.

Configure your new project

The next step is to add your references. Add the standard Civil 3D and AutoCAD references: AcDbMgd, AcMgd, AcCoreMgd, AecBaseMgd and AeccDbMgd. Make sure to add the correct ones for your targeted Civil 3D, if you have multiple versions installed. Change the Copy Local setting on the references to False.

Edit the project Properties to change the Debug options. Toggle the Start action to “Start external program” and select your version of acad.exe. Edit your Start options and Command line arguments as you see fit. I make mine match the Civil 3D shortcut so that I am loading it as a typical user would.

At this point, you have a standard Civil 3D development project. In order to target Dynamo you will need to add the NuGet packages as references. Either right-click the References item in the Solution explorer or go to the Project pull-down and select “Manage NuGet packages…”

Right-click the References node or use the Project menu.

A new tab will open called the NuGet Package Manager. If it is not already current, select the Browse tab. There is a pull-down option called Package source, ensure it is pointed at nuget.org. In the search bar, type in “DynamoVisualProgramming”. You will get a list of possible NuGet packages. Install the Core, DynamoServices and ZeroTouchLibrary packages. You install the package by selecting the package, selecting the version you’d like to use (often you can use the Latest stable version) and clicking the Install button. A Preview Changes dialog may be displayed (depending on your settings) that will warn you the project is installing the selected package. You can click OK on that window. You may also get a File Conflict for a logo.png file. You can opt to overwrite or not, it won’t affect the project.

At this point, run your project to make sure it loads Civil 3D as intended. Once Civil 3D has opened, switch to the Manage tab and click the Dynamo button. Once Dynamo has loaded, create a new blank file. From the File menu, select Import Library and select your dll file in your projects Debug folder. If all went well, you should now see your ZeroTouch library under the Add-ons section on the left side of Dynamo. If you expand the library, you will see the structure matches the defaults that your project currently has.

The default class structure, in Dynamo.

By default, Dynamo organizes your library based on the internal structure. The project name, or dll file, will control the library name. Any namespaces will be the first level under that and each class in each namespace will be the second level. In each class, any methods and constructors will be the nodes you can insert into the Dynamo canvas. If you click the Class1 item, you will create a Class1.Class1 node with a single output.

Before closing down your debugging session, in the Settings menu, select the Manage Node and Package Path option. At the bottom of the list of paths you will see your recently loaded library file. Select the file and click the minus sign to the left. This will remove the file from future loads of Dynamo so that we can adjust our project to automatically copy the files to the default package location and not have any conflicts. Once you’ve removed the path, click Accept Changes and close down Dynamo and Civil 3D.

Back in Visual Studio, we’re going to add some Build Events in order to automatically copy all the necessary files to the default package location. In this way, Dynamo will auto-load the library each time it runs. Double click the Properties node in Solution Explorer. In the Build Events tab, paste the following code into the Post-build event section:

xcopy /Y "$(TargetDir)." "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\bin\"
xcopy /Y "$(ProjectDir)pkg.json" "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\"
xcopy /Y "${ProjectDir)ZeroTouch_DynamoCustomization.xml" "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\bin\"

Let’s look at these three lines a little bit and try to understand what’s happening.

xcopy /Y "$(TargetDir)." "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\bin\"

This line is going to copy everything in the “TargetDir”, which is your project’s bin\Debug folder, to the bin folder of your ZeroTouch package folder.

xcopy /Y "$(ProjectDir)pkg.json" "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\"

This line is going to copy the pkg.json file (which we haven’t created yet) to the root folder of your package.

xcopy /Y "${ProjectDir)ZeroTouch_DynamoCustomization.xml" "$(AppData)\Autodesk\C3D 2021\Dynamo\2.5\packages\ZeroTouch\bin\"

This line is going to copy your DynamoCustomization file to the package bin folder. We haven’t created this file either, but it controls the naming convention that is displayed in the Dynamo library.

Now that we have the project setup to load into Civil 3D and Dynamo, let’s create the other files that Dynamo wants in order to read your library more effectively. Right click your project name in the Solution Explorer and select Add->New Item. Select a .json file type and name it pkg.json. If a json file type isn’t listed, you can select a text file and give it a json extension. Paste in the following content:

{
"license": "",
"file_hash": null,
"name": "ZeroTouch",
"version": "",
"description": "",
"group": "",
"keywords": null,
"dependencies": [],
"host_dependencies": [ "Civil 3D" ],
"contents": "",
"engine_version": "2.5.0.0",
"engine": "dynamo",
"engine_metadata": "",
"site_url": "",
"repository_url": "",
"contains_binaries": true,
"node_libraries": [
"ZeroTouch, Version=0.1.0, Culture=neutral, PublicKeyToken=null"
]
}

This file can also be generated by Dynamo by publishing your library, but I like to start with it to ensure my project is copying the data it needs as I go. Most of the data items listed can be filled in either manually or during the publishing process.

Next, Add another item. This will be a XML file. Name the file ZeroTouch_DynamoCustomization.xml and paste the following content into it:

<?xml version="1.0"?>
<doc>
<assembly>
<name>Zero Touch</name>
</assembly>
<namespaces>
<!--Remap Namespaces-->
<namespace name="ZeroTouch">
<category>My Zero Touch</category>
</namespace>
</namespaces>
<classes>
<!--Remap Class names-->
</classes>
</doc>

At this point, test the project again by starting to debug again. Once Civil 3D loads, start up Dynamo. Once Dynamo loads, you can check if your project auto-loaded as intended by going to the Packages menu and selecting Manager Packages. Your package should be listed and you can click the ellipses on the right to expand the data listed or to open the folder containing the library. If you create a new dynamo file, you will even see your library listed on the left. If everything went smoothly, you should even notice the library name was changed.

Library modified by the DynamoCustomization.xml file

The library was transformed by the ZeroTouch_DynamoCustomization.xml file to change the name of the ZeroTouch namespace to My Zero Touch. Using this method, you can rename any of your namespaces or classes after the fact.

This concludes setting up a ZeroTouch project for Civil 3D. We’ll look at creating ZeroTouch nodes and working with the Dynamo graphics in future posts.

Published by Adam Reilly

An Autodesk Civil 3D Certified Professional with almost 15 years of experience in Civil 3D and over 20 years in the civil engineering industry. I love working with, learning about and teaching Civil 3D.

Leave a comment

Design a site like this with WordPress.com
Get started