Dictionary for storing and managing AcDbLayout objects.

This class extends AcDbDictionary to provide specialized functionality for managing layout objects, including searching by block table record ID and tracking the maximum tab order.

const layoutDict = new AcDbLayoutDictionary(database);
const layout = layoutDict.getBtrIdAt('some-block-id');
const maxOrder = layoutDict.maxTabOrder;

Hierarchy (View Summary)

Constructors

Properties

_recordsById: Map<string, AcDbLayout>

Map of records indexed by object ID

_recordsByName: Map<string, AcDbLayout>

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 maxTabOrder(): number
  • Gets the maximum tab order value of layouts in the layout dictionary.

    Returns number

    The maximum tab order value, or -1 if no layouts exist

    const maxOrder = layoutDict.maxTabOrder;
    console.log('Maximum tab order:', maxOrder);
  • 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 | AcDbLayout

    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
    }
  • Searches the dictionary for a layout associated with the specified block table record ID.

    Parameters

    • id: string

      The block table record ID to search for

    Returns undefined | AcDbLayout

    The layout associated with the block table record ID, or undefined if not found

    const layout = layoutDict.getBtrIdAt('some-block-id');
    if (layout) {
    console.log('Found layout:', layout.layoutName);
    }
  • 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: AcDbLayout

      The new object to add to the dictionary

    Returns void

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