GetObjectName

Returns the name of a chart object by its index.

Syntax

GetObjectName(index: number, isStatic?: boolean, window?: number): string

Parameters

Parameter
Type
Description

index

number

The index of the object

isStatic

boolean

Optional. Whether to look in static objects (default: false)

window

number

Optional. Target window: 0 = MainChart, 1+ = OscWin. Default: current chart

Return Value

Returns a string representing the object's name.

Description

The GetObjectName method retrieves the name of a chart object based on its index in the list of objects. Objects are indexed from 0 to GetObjectCount() - 1. This method is useful for iterating through all objects on a chart. Use the optional window parameter to read from a specific window (MainChart or OscWin).

Example

// Get name of first object
const firstName = this.api.GetObjectName(0)
console.log(`First object name: ${firstName}`)

// Get name of first static object
const firstStaticName = this.api.GetObjectName(0, true)
console.log(`First static object name: ${firstStaticName}`)

// List all objects
const count = this.api.GetObjectCount()
for (let i = 0; i < count; i++) {
    const name = this.api.GetObjectName(i)
    const type = this.api.GetObjectType(name)
    console.log(`Object ${i}: Name=${name}, Type=${type}`)
}

// List all static objects
const staticCount = this.api.GetObjectCount(true)
for (let i = 0; i < staticCount; i++) {
    const name = this.api.GetObjectName(i, true)
    const type = this.api.GetObjectType(name, true)
    console.log(`Static object ${i}: Name=${name}, Type=${type}`)
}

// List objects from MainChart (window = 0)
const mainChartCount = this.api.GetObjectCount(false, 0)
for (let i = 0; i < mainChartCount; i++) {
    const name = this.api.GetObjectName(i, false, 0)
    console.log(`MainChart object ${i}: ${name}`)
}

Last updated