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

Can't Select a Layer by Name in JSFL

Community Beginner ,
Aug 29, 2023 Aug 29, 2023

I'm stuck with trying to select a layer by name.
I must be missing something super basic but I can't figure it out.

var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();

var targetLayer = timeline.findLayerIndex('Keys')
if (targetLayer !== undefined) {
	fl.trace(targetLayer)
	timeline.currentLayer = targetLayer;}

// If the target layer is not found, create a new layer and select it
else {
	timeline.addNewLayer('Keys');}

 The fl.trace(targetLayer) returns a number (7), but the selected layer doesn't change. I also tried setSelectedLayers with the same result.

timeline.setSelectedLayers(targetLayer);

 If I put a plain number in place of targetLayer it selects that layer no problem. Is this a bug or is there a work around?

TOPICS
Code , Timeline
389
Translate
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 Expert , Aug 29, 2023 Aug 29, 2023

targetLayer (if it's defined) is an array.  ie, if you use unique layer names, try:

 

timeline.setSelectedLayers(targetLayer[0]);
Translate
Community Expert ,
Aug 29, 2023 Aug 29, 2023

targetLayer (if it's defined) is an array.  ie, if you use unique layer names, try:

 

timeline.setSelectedLayers(targetLayer[0]);
Translate
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 30, 2023 Aug 30, 2023

That makes sense, thank you!

Translate
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 30, 2023 Aug 30, 2023
LATEST

you're welcome.

Translate
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 30, 2023 Aug 30, 2023

Hi.

 

Please try this:

var tl = fl.getDocumentDOM().getTimeline();
var layerIndex = tl.findLayerIndex("Keys");
tl.setSelectedLayers(layerIndex[0]);

 

Regards,

JC

Translate
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