Class AcDbDictionary<TObjectType>

A database-resident object dictionary that maintains a map between text strings and database objects.

An instance of this class represents a single object, such as Drawing Symbol Table, to which objects derived from AcDbObject may be added, accessed, and removed. Entries in an AcDbDictionary must be unique. Entries consist of a unique AcDbObject and string, which comprises the entry's key name. The key may be either a text string, or an asterisk ('*') as the first character in the string to signify an anonymous entry. An anonymous entry's key will be constructed internally by appending an 'A' plus a unique integer value to the asterisk; for example, '*A13'. When an object is placed in a dictionary, the dictionary is established as the object's owner, the lookup key string is associated with the object's object ID, and the dictionary itself is attached to the object as a persistent reactor so that the dictionary is notified when the object is erased.

const dictionary = new AcDbDictionary<AcDbLayout>(database);
const layout = new AcDbLayout();
dictionary.setAt('MyLayout', layout);
const retrievedLayout = dictionary.getAt('MyLayout');

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_recordsById: Map<string, TObjectType>

Map of records indexed by object ID

_recordsByName: Map<string, TObjectType>

Map of records indexed by name

Accessors

  • get database(): AcDbDatabase
  • Gets the database in which this object is resident.

    When an object isn't added to a database, this property returns the current working database. After it is added to a database, it will be set automatically. You should never set this value manually.

    Returns AcDbDatabase

    The database this object belongs to

    const db = obj.database;
    
  • set database(db: AcDbDatabase): void
  • Sets the database for this object.

    This is typically set automatically when the object is added to a database. Manual setting should be avoided unless you know what you're doing.

    Parameters

    Returns void

    obj.database = myDatabase;
    
  • get numEntries(): number
  • Gets the number of entries in the dictionary.

    Returns number

    The number of entries in the dictionary

    const count = dictionary.numEntries;
    console.log(`Dictionary has ${count} entries`);
  • get objectId(): string
  • Gets the object ID.

    AutoCAD uses 64-bit integers to represent handles, which exceed the maximum integer value of JavaScript. Therefore, strings are used to represent object handles.

    Returns string

    The object ID as a string

    const id = obj.objectId;
    console.log(`Object ID: ${id}`);
  • set objectId(value: string): void
  • Sets the object ID.

    Parameters

    • value: string

      The new object ID

    Returns void

    obj.objectId = 'new-object-id';
    
  • get ownerId(): string
  • Gets the object ID of the owner of this object.

    Returns string

    The owner object ID

    const ownerId = obj.ownerId;
    
  • set ownerId(value: string): void
  • Sets the object ID of the owner of this object.

    Parameters

    • value: string

      The new owner object ID

    Returns void

    obj.ownerId = 'parent-object-id';
    

Methods

  • Closes the object.

    All changes made to the object since it was opened are committed to the database, and a "closed" notification is sent. This method can be overridden by subclasses to provide specific cleanup behavior.

    Returns void

    obj.close();
    
  • Gets the object with the specified name from the dictionary.

    Parameters

    • name: string

      Name of the object to retrieve

    Returns undefined | TObjectType

    The object with the specified name, or undefined if not found

    const layout = dictionary.getAt('MyLayout');
    if (layout) {
    console.log('Layout found:', layout);
    }
  • Gets the value of the specified attribute.

    This method will throw an exception if the specified attribute doesn't exist. Use getAttrWithoutException() if you want to handle missing attributes gracefully.

    Parameters

    • attrName: string

      The name of the attribute to retrieve

    Returns any

    The value of the specified attribute

    When the specified attribute doesn't exist

    try {
    const value = obj.getAttr('objectId');
    } catch (error) {
    console.error('Attribute not found');
    }
  • Gets the value of the specified attribute without throwing an exception.

    This method returns undefined if the specified attribute doesn't exist, making it safer for optional attributes.

    Parameters

    • attrName: string

      The name of the attribute to retrieve

    Returns any

    The value of the specified attribute, or undefined if it doesn't exist

    const value = obj.getAttrWithoutException('optionalAttribute');
    if (value !== undefined) {
    // Use the value
    }
  • Gets the object with the specified ID from the dictionary.

    Parameters

    • id: string

      ID of the object to retrieve

    Returns undefined | TObjectType

    The object with the specified ID, or undefined if not found

    const object = dictionary.getIdAt('some-object-id');
    
  • Checks if the dictionary contains an object with the specified name.

    Parameters

    • name: string

      Name to search for

    Returns boolean

    True if the dictionary contains an object with the specified name, false otherwise

    if (dictionary.has('MyLayout')) {
    console.log('Layout exists');
    }
  • Checks if the dictionary contains an object with the specified ID.

    Parameters

    • id: string

      ID to search for

    Returns boolean

    True if the dictionary contains an object with the specified ID, false otherwise

    if (dictionary.hasId('some-object-id')) {
    console.log('Object exists');
    }
  • Removes the entry specified by name from the dictionary.

    Parameters

    • name: string

      String representing the entry's key (or name)

    Returns boolean

    True if the entry was found and removed, false otherwise

    const removed = dictionary.remove('MyLayout');
    if (removed) {
    console.log('Layout removed successfully');
    }
  • Removes the entry specified by object ID from the dictionary.

    Parameters

    • id: string

      ID of the object to delete

    Returns boolean

    True if the entry was found and removed, false otherwise

    const removed = dictionary.removeId('some-object-id');
    
  • Adds a new entry to the dictionary.

    If an entry with the specified key already exists, the existing entry is erased and replaced with the new one.

    Parameters

    • key: string

      String representing the object's search key name

    • value: TObjectType

      The new object to add to the dictionary

    Returns void

    const layout = new AcDbLayout();
    dictionary.setAt('MyLayout', layout);