Abt. Script Operators and Page Class

Hello everyone,

I want to use the appendMenu method documented in this documentation and menuLabels from this one in a Script Chop. Yet, I am having a hard time to figure out how to determine the labels of the menu since there is no an example usage in the documentation.

I tried this method:

    waveformMenu = page.appendMenu('Waveform', label='Waveform')
    waveformMenu.menuNames = ['sine', 'square', 'sawtooth']
    waveformMenu.menuLabels = ['Sine', 'Square', 'Sawtooth']
    waveformMenu.val = 'sine'  # Default to Sine

and this one:

    # Adding a menu parameter for waveform selection
    p = page.appendMenu('Waveform', label='Waveform')
    
    # Setting the menu items 
    waveformNames = ['Sine', 'Square', 'Sawtooth', 'Triangle', 'Noise']
    p.menuNames = waveformNames
    p.menuLabels = waveformNames
    p.val = 0  # Default to Sine

but having this error:

td.tdError: Can only assign a scalar or a value with the same number of components.

Could you please share a documentation of example usage of appendMenu and similar methods?

Ps: I don’t want to use TDJSON.addParametersFromJSON since I don’t want it to be hard-coded.

Best regards

Please post your network and I can help you. If it’s private, send to ivan@derivative.ca

This looks okay in a vaccum, but my suspicion is that your “page” variable is incorrect.

1 Like

Sure,
Here you can find my toe file:

ScriptChop_EXAMPLE.toe (5.9 KB)

The names of the items in the menu do not appear and the same error resists.

Ah yes I missed it too.
The append functions return a ParGroup, not a parameter. You just need to get the first (and only) par in the ParGroup, like this:

p[0].menuNames = waveformNames
1 Like

It worked very well. Thank you! :slight_smile: