• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

An error was thrown when selecting a layer using jsfl

Participant ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

Select a column of frames on the timeline, and then execute the command to select these layers, the following code will throw“Error: setSelectedLayers:Invalid parameter number 1”,
How can it be improved, and where is it wrong?

微信图片_20230820210322.png

 

var selectedFrames = fl.getDocumentDOM().getTimeline().getSelectedFrames();
var selectedLayers = [];
for (var i = 0; i < selectedFrames.length; i++) {
	var currFrame = selectedFrames[i];
	var currLayer = currFrame.layer;
	if (selectedLayers.indexOf(currLayer) === -1) {
		selectedLayers.push(currLayer);
	}
}
if (selectedLayers.length > 0) {
	fl.getDocumentDOM().getTimeline().setSelectedLayers(selectedLayers);
}

 

 

 

 

TOPICS
Code

Views

304

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Aug 20, 2023 Aug 20, 2023

The problem is that you are not using functions correctly.
The "selectedFrames" function returns, as the documentation says: "An array containing 3n integers, where n is the number of selected regions. The first integer in each group is the layer
index, the second integer is the start frame of the beginning of the selection, and the third integer specifies the ending
frame of that selection range", array does not contain frames, and frames do not contain a "layer" property.
Also, the "setSelectedLay

...

Votes

Translate

Translate
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

setSelectedLayers selects one layer at a time.  using the 2nd parameter you can can select more than one, but you select one at a time. ie, you want to loop through the selected layers.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

Thanks! I'm still learning, thanks for pointing out the problem,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

The problem is that you are not using functions correctly.
The "selectedFrames" function returns, as the documentation says: "An array containing 3n integers, where n is the number of selected regions. The first integer in each group is the layer
index, the second integer is the start frame of the beginning of the selection, and the third integer specifies the ending
frame of that selection range", array does not contain frames, and frames do not contain a "layer" property.
Also, the "setSelectedLayers" function takes as the first argument the index of the desired layer to be selected.
Here is the correct code

var document = fl.getDocumentDOM();
var timeline = document.getTimeline();
var layers = timeline.layers;

var selectedFrames = timeline.getSelectedFrames();

for (var i = 0; i < selectedFrames.length; i += 3) {
	var [layerIndex, rangeBegin, rangeEnd] = selectedFrames.slice(i, i + 3);

	timeline.setSelectedLayers(layerIndex, i == 0 ? true : false);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

You are right, thank you very much for the detailed explanation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines