Script to extract loop length

I wonder if there is a way to obtain the length of a loop region and then store it as a rounded-up int value in the user properties. I have a javascript script that helps me handle accessing and creating user properties for things such as key and tempo:

    event.userProperties.every(function (p) {
        //Tempo
        if (p.key === ("Tempo")) {
            p.value = tempoValue;
            tempoExist = true;
        }

// More code 

        return true;
    });

Is there a way to get the length of a loop region and then store it as a userproperty? I want to add that I will only ever have a single loop marker per event, no more than that.

An array of marker tracks of an event can be accessed from the member markerTracks - each row of logic markers in the editor corresponds to a marker track. You can then access the markers belonging to the track from the markerTrack’s markers member. In the case of just wanting to check for loop regions, you can use .isOfExactType('LoopRegion') to check whether a marker is a loop region, and then access the region’s position and length from position and length respectively.

For example, the following script will iterate through all marker tracks for loop regions, and print their names, positions, and lengths to console:

var myEvent = studio.window.browserCurrent();
myEvent.markerTracks.forEach(function(track) {
	track.markers.forEach(function(marker) {
		if (marker.isOfExactType('LoopRegion')){
			console.log("Name = " + marker.name);
			console.log("Position = " + marker.position);
			console.log("Length = " + marker.length);
		}
	});
});

For your purposes, it should just be a matter of storing this information, and writing it to the event’s user properties.