Script to register child events in MultiSound?

on selected events
Add multi-sound,
add a child event,
Add programmer sound to child event
I would like to register a child event for the added multi-sound.
I tried a few things but failed.

var event = studio.window.browserSelection()[0];
var track = event.addGroupTrack("audio 1");
var multiInstrument = track.addSound(event.timeline, 'MultiSound', 0, 10);

var childEvent = studio.project.create("Event");
childEvent.name = 'voc1';
childEvent.folder = event;

var childtrack = childEvent.addGroupTrack("Audio 1");

var programInstrument = childtrack.addSound(childEvent.timeline, 'ProgrammerSound', 0, 10);
programInstrument.name = "ProgrammerSound test";


//programInstrument.owner = multiInstrument;  <- fail
//multiInstrument.sounds.push(childEvent); <- fail
//multiInstrument.sounds.push(programInstrument); <- fail

These fail because the programmer instrument belongs to the childEvent.timeline already. You’ll want to create the instrument independently of the timeline, and then add it to the multi instrument, like so:

var programmerInstrument = studio.project.create('ProgrammerSound');
programmerInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(programmerInstrument);

This fails because childEvent isn’t actually an instrument/sound, it’s an event. You’ll need to do create an event instrument, assign the child event to it, then add it to the multi instrument:

var eventInstrument = studio.project.create('EventSound');
eventInstrument.event = childEvent;
eventInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(eventInstrument);

Using the code below means,
multiInstrument.relationships.sounds.add(programInstrument);

This error occurs.
15:35:02 [script-error] An error in the callback “onClicked”: Error: Cannot modify relationship ‘sounds’ as the objects belong to different files., callstack:

I want to insert the child event’s programmer’s instrument into the parent’s multi-instrument.

Just to be clear, are you trying to transfer ownership of the programmer instrument from the child “voc1” event to the parent “attack” event? Or are you trying to have child event retain ownership while also having the programming instrument as an item in the multi instrument?