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

Only loop through links on Page (not pasteboard)

Community Beginner ,
Oct 14, 2015 Oct 14, 2015

Hi I'm looping through links with a script at the moment, but forgot about Pasteboard items, is there any simple adjustment to make it only look at parentPage=1 links for example?

    var doc = app.activeDocument;      

    var links = doc.links ;   

    // start loop .......................    

  for(var i = 0; i < links.length; i++) {   

link = links;

....

TOPICS
Scripting
381
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
Engaged ,
Oct 14, 2015 Oct 14, 2015

var objs = app.activeDocument.pageItems.everyItem().getElements(); 

while(obj=objs.pop()){ 

     if(obj.parentPage == null)  // Check the condition it will only  find the links in the page

          } 

}

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
Enthusiast ,
Oct 14, 2015 Oct 14, 2015

Try this,

var doc = app.activeDocument;

var links = doc.links;  

for(var i = 0; i < links.length; i++)

{  

if(links.parent.parent.parentPage != null)
{
        alert(links.name)
    }

}

Regards,

Chinna

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
Engaged ,
Oct 14, 2015 Oct 14, 2015

(obj.parentPage != null)  /

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
Enthusiast ,
Oct 14, 2015 Oct 14, 2015
LATEST

Hi newtoindesign

Give this a try. You may have to refine it further.

main();

exit();

function main() {

 

    var myDoc = app.activeDocument;

    var myLinks = myDoc.links.everyItem().getElements();

    for(var i = 0; i < myLinks.length; i++) {

        // parent = e.g. imported Page

        // parent.parent = rectagle

        // parent.parent.parentPage is a page or null

        if (myLinks.parent.parent.parentPage != null) alert("I am on a page");

        else alert("I am not on a page");

    }

}

kind regards

Daniel (from Switzerland)

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