一键导入
c3d-data-shortcuts
Data shortcut references, cross-drawing objects, broken reference repair
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Data shortcut references, cross-drawing objects, broken reference repair
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Corridors, baselines, regions, assemblies, subassemblies, corridor surfaces
Custom subassembly .NET design — CorridorState, SubassemblyGenerator, targets, SATemplate
Stock-subassembly pattern catalog — need→file index, worked DrawImplement recipes, point/link/shape code reference, mined from Autodesk's 120 VB stock subassemblies
Superelevation design, attainment, cross slope, pivot points, lane config
Block definitions, references, attributes, dynamic block properties, exploding
Dimensions — aligned, rotated, arc, radial, angular, ordinate, text overrides
| name | c3d-data-shortcuts |
| description | Data shortcut references, cross-drawing objects, broken reference repair |
Use this skill when working with data shortcuts, creating or managing cross-drawing references, synchronizing imported references, repairing broken references, or configuring data shortcut working and project folders.
Data shortcuts allow Civil 3D objects in one drawing (the source) to be referenced read-only into other drawings (the host). The .NET API exposes this through the DataShortcuts static class and the DataShortcutManager class in Autodesk.Civil.DataShortcuts. The assembly is AeccDataShortcutMgd.dll.
Working Folder
└── Project Folder (_Shortcuts/ subfolder)
├── Alignments.xml
├── Surfaces.xml
├── Pipe Networks.xml
├── Pressure Pipe Networks.xml
├── Corridors.xml
└── View Frame Groups.xml
The DataShortcuts.RefType enumeration defines the publishable entity types:
using Autodesk.Civil.DataShortcuts;
// Available RefType values:
// RefType.Surface
// RefType.Alignment (parent alignments)
// RefType.AlignmentChildren (child offset/widening alignments)
// RefType.Profile
// RefType.PipeNetwork
// RefType.PressureNetwork
// RefType.Corridor
// RefType.ViewFrameGroup
using Autodesk.Civil.DataShortcuts;
// Get current working folder path
string workingFolder = DataShortcuts.GetWorkingFolderPath();
ed.WriteMessage("Working folder: {0}\n", workingFolder);
// Set a new working folder path
DataShortcuts.SetWorkingFolderPath(@"C:\Civil3D Projects");
// Get current project folder (relative to working folder)
string projectFolder = DataShortcuts.GetProjectFolderPath();
ed.WriteMessage("Project folder: {0}\n", projectFolder);
// Set project folder (relative path from working folder)
DataShortcuts.SetProjectFolderPath("MyProject");
// Get the data shortcut project ID for a given path
int projectId = DataShortcuts.GetDSProjectId(@"C:\Civil3D Projects\MyProject");
// Associate a data shortcut project with the current drawing
DataShortcuts.AssociateDSProject(projectId);
// Get all published items in the current project
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
int count = dsMgr.GetPublishedItemsCount();
for (int i = 0; i < count; i++)
{
DSEntityInfo info = dsMgr.GetPublishedItemAt(i);
ed.WriteMessage("Name: {0}, Type: {1}, Source: {2}\n",
info.Name, info.RefType, info.SourceDrawing);
}
// Clean up (DataShortcutManager implements IDisposable)
dsMgr.Dispose();
using Autodesk.Civil.DataShortcuts;
using Autodesk.Civil.ApplicationServices;
// Create a reference to a published surface in the current drawing
DataShortcuts.CreateReference(
doc.Database, // target database (host drawing)
"EG Surface", // entity name in the source drawing
RefType.Surface // entity type
);
int projectId = 0;
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
// Find the published item index by name and type
int itemIndex = -1;
int count = dsMgr.GetPublishedItemsCount();
for (int i = 0; i < count; i++)
{
DSEntityInfo info = dsMgr.GetPublishedItemAt(i);
if (info.Name == "Main Road CL" && info.RefType == RefType.Alignment)
{
itemIndex = i;
break;
}
}
if (itemIndex >= 0)
{
// Create the reference in the current drawing
dsMgr.CreateReference(itemIndex, doc.Database);
ed.WriteMessage("Reference created for alignment 'Main Road CL'.\n");
}
dsMgr.Dispose();
int projectId = 0;
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
RefType[] typesToImport = {
RefType.Surface,
RefType.Alignment,
RefType.PipeNetwork
};
int imported = 0;
int count = dsMgr.GetPublishedItemsCount();
for (int i = 0; i < count; i++)
{
DSEntityInfo info = dsMgr.GetPublishedItemAt(i);
if (Array.IndexOf(typesToImport, info.RefType) >= 0)
{
try
{
dsMgr.CreateReference(i, doc.Database);
imported++;
ed.WriteMessage("Imported: {0} ({1})\n", info.Name, info.RefType);
}
catch (System.Exception ex)
{
ed.WriteMessage("Failed to import {0}: {1}\n", info.Name, ex.Message);
}
}
}
ed.WriteMessage("Total imported: {0}\n", imported);
dsMgr.Dispose();
using (Transaction ts = db.TransactionManager.StartTransaction())
{
Alignment align = ts.GetObject(alignId, OpenMode.ForRead) as Alignment;
// Check if this entity is a data reference (read-only cross-drawing ref)
if (align.IsReferenceObject)
{
ed.WriteMessage("'{0}' is a data reference.\n", align.Name);
// Get reference information
DataShortcutKey dsKey = align.GetReferenceInfo();
ed.WriteMessage(" Source drawing: {0}\n", dsKey.SourceDrawing);
ed.WriteMessage(" Source entity: {0}\n", dsKey.SourceEntityName);
ed.WriteMessage(" Ref type: {0}\n", dsKey.RefType);
}
// Check for sub-objects (e.g., profiles that came along with an alignment ref)
if (align.IsReferenceSubObject)
{
ed.WriteMessage("'{0}' is a reference sub-object.\n", align.Name);
}
ts.Commit();
}
CivilDocument doc = CivilApplication.ActiveDocument;
using (Transaction ts = db.TransactionManager.StartTransaction())
{
// Check surfaces
foreach (ObjectId surfId in doc.GetSurfaceIds())
{
var surf = ts.GetObject(surfId, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;
if (surf.IsReferenceObject)
ed.WriteMessage("DREF Surface: {0}\n", surf.Name);
}
// Check alignments
foreach (ObjectId alignId in doc.GetAlignmentIds())
{
var align = ts.GetObject(alignId, OpenMode.ForRead) as Alignment;
if (align.IsReferenceObject)
ed.WriteMessage("DREF Alignment: {0}\n", align.Name);
}
// Check pipe networks
foreach (ObjectId netId in doc.GetPipeNetworkIds())
{
var network = ts.GetObject(netId, OpenMode.ForRead) as Network;
if (network.IsReferenceObject)
ed.WriteMessage("DREF Network: {0}\n", network.Name);
}
ts.Commit();
}
When the source drawing changes, data references in host drawings must be synchronized. References auto-synchronize on drawing open, but can also be forced programmatically.
using Autodesk.Civil.DataShortcuts;
// Synchronize all data references in the active drawing
DataShortcuts.SynchronizeImport(doc.Database);
ed.WriteMessage("All data references synchronized.\n");
using (Transaction ts = db.TransactionManager.StartTransaction())
{
Alignment align = ts.GetObject(alignId, OpenMode.ForRead) as Alignment;
if (align.IsReferenceObject)
{
// Synchronize this specific reference entity
DataShortcuts.SynchronizeImport(db, alignId);
ed.WriteMessage("Synchronized reference: {0}\n", align.Name);
}
ts.Commit();
}
References break when the source drawing is moved, renamed, or deleted. The API provides repair methods.
int projectId = 0;
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
int brokenCount = dsMgr.GetBrokenDRefCount(doc.Database);
ed.WriteMessage("Broken references: {0}\n", brokenCount);
for (int i = 0; i < brokenCount; i++)
{
ObjectId brokenId = dsMgr.GetBrokenDRefEntityId(doc.Database, i);
Entity ent = ts.GetObject(brokenId, OpenMode.ForRead) as Entity;
ed.WriteMessage(" Broken: {0} (ObjectId: {1})\n", ent.Name, brokenId);
}
dsMgr.Dispose();
// Repair a broken DREF by pointing it to a new source drawing path
DataShortcuts.RepairBrokenDRef(
brokenEntityId, // ObjectId of the broken reference entity
@"C:\Projects\Source\Design.dwg", // new target drawing full path
true // auto-repair other broken refs to the same source
);
int projectId = 0;
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
// Repair broken shortcut by index (in the project XML, not the drawing)
bool repaired = DataShortcuts.RepairBrokenDataShortcut(
shortcutIndex, // index of the broken shortcut
@"C:\Projects\Source\Design.dwg", // new target drawing full path
true // auto-repair others pointing to same source
);
if (repaired)
ed.WriteMessage("Data shortcut repaired.\n");
else
ed.WriteMessage("Repair failed.\n");
dsMgr.Dispose();
int projectId = 0;
DataShortcutManager dsMgr = DataShortcuts.CreateDataShortcutManager(ref projectId);
int brokenCount = dsMgr.GetBrokenDRefCount(doc.Database);
if (brokenCount > 0)
{
// Repair first broken ref with autoRepairOther = true to fix all from same source
ObjectId firstBrokenId = dsMgr.GetBrokenDRefEntityId(doc.Database, 0);
DataShortcuts.RepairBrokenDRef(firstBrokenId, newSourceDrawingPath, true);
ed.WriteMessage("Attempted repair of {0} broken reference(s).\n", brokenCount);
}
dsMgr.Dispose();
DataShortcutManager holds unmanaged resources; always call Dispose() or use a using blockSynchronizeImport requires the source drawing to be accessible at the stored path; if moved, repair firstSetWorkingFolderPath and SetProjectFolderPath do not validate the path; invalid paths cause failures on next shortcut operationRepairBrokenDRef with autoRepairOther = true only repairs entities referencing the same source drawing; entities from other sources need separate repair callsIsReferenceObject first_Shortcuts subfolder is created automatically by Civil 3D in the project folder; do not manually create or modify its XML filesAECCFORCESYNCHRONIZEREFERENCES built-in command can synchronize all references interactively, but the API method SynchronizeImport is the programmatic equivalentPipeNetworkc3d-root-objects — CivilDocument, transactions, and collection access patterns used with reference entitiesc3d-alignments — Alignment creation and queries; alignment DREFs are the most common reference typec3d-surfaces — Surface objects that can be published and referenced across drawingsc3d-profiles — Profiles that accompany alignment references as sub-objectsc3d-pipe-networks — Gravity and pressure pipe networks publishable via data shortcuts