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

Script for loop all items

Contributor ,
Jun 21, 2023 Jun 21, 2023

Copy link to clipboard

Copied

Hello all,

I could use a little help, maybe you can help me?

 

I have on a layer "LayerX" text fields in a group with certain name "TextX".

There are several groups on the layer with the same text fields and I want to apply my script to all text fields in the document with the name "TextX".

 

but unfortunately i can't get the loop to run it only selects the 1st "TextX" on the layer "LayerX" and then the script stops.

 

try{

var myDoc = app.documents[0];  
var myLoop = myDoc.allPageItems;


   
    for(var i = 0; i < myLoop.length; i++){
        
var doc = app.documents[0];   


app.select(NothingEnum.NOTHING);
doc.layers.itemByName("LayerX").pageItems.itemByName("TestX").select(SelectionOptions.ADD_TO);

var myStory = app.selection[0].parentStory;  
var myOversetEnd = myStory.characters.length-1; 
var myOverset = myStory.characters.itemByRange(4, myOversetEnd); 

myOverset.remove();}



}catch(e){alert("Something gone wrong!" + e);};

 

TOPICS
Scripting

Views

343

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 Expert , Jun 22, 2023 Jun 22, 2023

itemByName only finds the first instance of a given object, even if multiple objects have the same name. Instead you have to loop through all page items and check each name, then act. Also simplified your code a bit below.

 

 

try{

var myDoc = app.documents[0];  
var myLoop = myDoc.allPageItems;
for(var i = 0; i < myLoop.length; i++){
       if (myLoop[i].itemLayer.name == "LayerX" && myLoop[i].name == "TestX") { 
            var myStory = myLoop[i].parentStory;  
            myStory.characters
...

Votes

Translate

Translate
Community Expert ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

itemByName only finds the first instance of a given object, even if multiple objects have the same name. Instead you have to loop through all page items and check each name, then act. Also simplified your code a bit below.

 

 

try{

var myDoc = app.documents[0];  
var myLoop = myDoc.allPageItems;
for(var i = 0; i < myLoop.length; i++){
       if (myLoop[i].itemLayer.name == "LayerX" && myLoop[i].name == "TestX") { 
            var myStory = myLoop[i].parentStory;  
            myStory.characters.itemByRange(4, -1).remove(); 
       }
}catch(e){alert("Something gone wrong!" + e);};

 

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
Contributor ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

Vielen Dank brianp311 !

 

Das hilft mir wirklich sehr 👍

 

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
Engaged ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

Hello @brian_p_dts , do you know much about scripting in Premiere Pro? I would have some questions if possible.

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 ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

LATEST

The Premiere Pro forum, that's the place to go.

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