Motivation #
This is a post on how to set the gravity network catalog and pressure network catalog via C# code.
Set Gravity Network Catalog folder path #
The gravity network catalog is set on per machine basis; you only have to do it once for a machine and it applies to all the drawings subsequently. The code here is based on the automation of this post
private static string GetUserProductRoot()
{
// e.g. "Software\\Autodesk\\AutoCAD\\R25.1\\ACAD-9100:409"
return HostApplicationServices.Current.UserRegistryProductRootKey;
}
private static string GetActiveProfileName()
{
var acad = (Autodesk.AutoCAD.Interop.AcadApplication)Application.AcadApplication;
return acad.Preferences?.Profiles?.ActiveProfile;
}
private static string GetAeccUiNetworkKeyPath()
{
string root = GetUserProductRoot();
string profile = GetActiveProfileName();
if (string.IsNullOrEmpty(root) || string.IsNullOrEmpty(profile)) return null;
string prefsPath = root + "\\Profiles\\" + profile + "\\Preferences";
using var prefsKey = Registry.CurrentUser.OpenSubKey(prefsPath);
if (prefsKey == null) return null;
foreach (var sub in prefsKey.GetSubKeyNames())
{
if (sub.StartsWith("AeccUiNetwork", StringComparison.OrdinalIgnoreCase))
return prefsPath + "\\" + sub;
}
return null;
}
[CommandMethod(nameof(CmdSetPipeCatalogs))]
public static void CmdSetPipeCatalogs()
{
var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
string keyPath = GetAeccUiNetworkKeyPath();
if (keyPath == null)
{
ed.WriteMessage("\nNo AeccUiNetwork* registry path found.");
return;
}
using var key = Registry.CurrentUser.OpenSubKey(keyPath, writable: true);
if (key == null)
{
ed.WriteMessage("\nUnable to open registry key for writing: {0}", keyPath);
return;
}
// Define the values to update
var updates = new (string Name, string Value)[]
{
("F1FEBE2D-D589-4f85-BF8E-650ED06A5EA5",
@"C:\ProgramData\Autodesk\C3D 2026\enu\Pipes Catalog\Metric Structures\Metric Structures.apc"),
("F670B5B9-DA12-476d-B461-4FB5C5650A82",
@"C:\ProgramData\Autodesk\C3D 2026\enu\Pipes Catalog\Metric Pipes\Metric Pipes.apc"),
("SharedContentPath", @"C:\ProgramData\Autodesk\C3D 2026\enu\Pipes Catalog\Aecc Shared Content")
};
foreach (var upd in updates)
{
key.SetValue(upd.Name, upd.Value, RegistryValueKind.String);
ed.WriteMessage($"\nUpdated {upd.Name} = {upd.Value}");
}
}
Take note that after you run the above Gravity Catalog setting, you will have to restart the Civil 3D application for it to apply. It does appear that the Civil 3D scans the related registry only once during startup.
Set Pressure Network Catalog sqlite path. #
The code here is based on the automation of this post, on the setting of the initial default Pressure Network Catalog to be used in the new Parts List creation. Before you even create a Parts List, you can use the below code to set the default pressure network catalog, so that when you create a new Parts List, this catalog will be copied over.
Take note that even though the UI for pressure Parts List support multiple catalogs, but our API only applies to setting the of the first catalog, when you are creating a new Pressure Parts List.
[CommandMethod(nameof(SetPressureCatalogOnPartsList))]
public void SetPressureCatalogOnPartsList()
{
var asm = typeof(PressureFittingStyle).Assembly;
// Find the internal PressurePartCatalog type
var catalogType = asm.GetType("Autodesk.Civil.DatabaseServices.Styles.PressurePartCatalog",true);
// Get the SetCatalog method
var setCatalog = catalogType.GetMethod(
"SetCatalog",
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
var myPath =
@"C:\ProgramData\Autodesk\C3D 2026\enu\Pressure Pipes Catalog\Metric\Metric_PVC.sqlite";
// This is where the setting of new sqlite file for the default Pressure Catalog is done
setCatalog.Invoke(null, new object[] { myPath });
var doc = CivilApplication.ActiveDocument;
using var ts = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.
MdiActiveDocument.Database.TransactionManager.StartTransaction();
var newPartsList = doc.Styles.GetPressurePartLists().Add("abc");
var partsList = ts.GetObject(newPartsList, OpenMode.ForWrite) as PressurePartList;
// when adding a new Parts List, you can verify that now it has the new default catalog.
var catalogGUID = partsList.CatalogGuid;
ts.Commit();
}