SymbolTableRecord is the abstract base class for all objects stored in a SymbolTable. Common examples include LayerTableRecord (Layers), BlockTableRecord (Block Definitions), LinetypeTableRecord, and TextStyleTableRecord. It defines the common properties for named table items, such as the entry name.
Autodesk.AutoCAD.DatabaseServices
System.Object
└─ RXObject
└─ DBObject
└─ SymbolTableRecord
├─ LayerTableRecord
├─ BlockTableRecord
├─ LinetypeTableRecord
├─ TextStyleTableRecord
├─ DimStyleTableRecord
├─ RegAppTableRecord
├─ UcsTableRecord
├─ ViewTableRecord
└─ ViewportTableRecord
| Property | Type | Description |
|---|---|---|
Name |
string |
The name of the record (e.g., Layer name "0"). |
IsDependent |
bool |
True if the record belongs to an XRef. |
IsResolved |
bool |
True if the XRef record is resolved. |
IsRenamable |
bool |
True if the record can be renamed. |
| Method | Return Type | Description |
|---|---|---|
GetName() |
string |
Gets the name safely. |
// Typically you instantiate a derived class, not SymbolTableRecord directly
LayerTableRecord layer = new LayerTableRecord();
layer.Name = "MyNewLayer";
// Set other specific properties...using (Transaction tr = db.TransactionManager.StartTransaction())
{
SymbolTableRecord rec = tr.GetObject(recordId, OpenMode.ForWrite) as SymbolTableRecord;
if (rec.IsRenamable) // Check system protection (e.g., Layer "0")
{
rec.Name = "RenamedRecord";
}
tr.Commit();
}public void CheckDependency(SymbolTableRecord rec)
{
if (rec.IsDependent)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n{rec.Name} is an XRef dependent record.");
}
}// BlockTableRecord is a SymbolTableRecord, but also a container!
// Note: Only BlockTableRecord behaves as an Entity container.
// Other records (Layer, Linetype) are just definitions.public void SetName(SymbolTableRecord rec, string newName)
{
try
{
// SymbolTableRecord validates names (no invalid chars)
rec.Name = newName;
}
catch (Exception ex)
{
// Handle invalid name error
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInvalid name characters.");
}
}using (Transaction tr = db.TransactionManager.StartTransaction())
{
SymbolTableRecord original = tr.GetObject(id, OpenMode.ForRead) as SymbolTableRecord;
SymbolTableRecord clone = original.Clone() as SymbolTableRecord;
clone.Name = original.Name + "_Copy";
// You would then add 'clone' to the owner table...
tr.Commit();
}// Since it inherits DBObject, all DBObject methods apply
SymbolTableRecord rec = tr.GetObject(id, OpenMode.ForRead) as SymbolTableRecord;
ObjectId ownerId = rec.OwnerId; // The SymbolTable (e.g., LayerTable)if (rec is LayerTableRecord) return "Layer";
if (rec is BlockTableRecord) return "Block";
if (rec is LinetypeTableRecord) return "Linetype";- Name Validation: Be aware that setting
Namethrows exceptions if the name contains invalid characters (<,>,/,:, etc.). - XRef Safety: dependent records (
IsDependent == true) are generally read-only; attempting to modify them or rename them will fail. - Renamable Check: Always check
IsRenamablebefore changingName(some system records like "0" or "Defpoints" are locked).
- SymbolTable - The container for these records.
- LayerTable - Example table.
- LayerTableRecord - Example derived record.