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

Script Label

Enthusiast ,
Feb 04, 2013 Feb 04, 2013

Copy link to clipboard

Copied

Hi All,

For my requirement i want to get a list of all page items with "id" value  in script label.

Script Label concept in entirely new for me.

Below script get the ID value of every page items in the active document.

But i dont know how to save all the values [alert(("ID:" + myPgItems) in the script label.

Trying script:

var myDoc = app.activeDocument

var myPageItems = myDoc.allPageItems

alert(myPageItems.length)

for(i=0; i<myPageItems.length; i++)

{

    var myPgItems = myPageItems.id

    alert("ID: " + myPgItems)

    }

Please find the attachment for more information

Screen Shot 2013-02-05 at 12.12.28 PM.png

Kindly give solution as soon.

Thanks in advance

BEGINNER

TOPICS
Scripting

Views

2.2K

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

Guide , Feb 06, 2013 Feb 06, 2013

Hi BEGINNER,

1. Why don't you store data in the document label?

2. To faciliate IDs comparison (new objs and/or removed ones), an object structure might be easier than an array.

Here is a possible approach (although not optimized):

function createList(/*PageItem[]*/a)

// -------------------------------------

{

    var i = a.length,

        r = {};

    while( i-- ){ r['_'+a.id]=null; }

    return r;

}

function compareList(o1, o2)

// -------------------------------------

{

    var k, a=[], z=0;

    for( k in o1 )

...

Votes

Translate

Translate
Enthusiast ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

Hi All,

Please can anyone help me for the above mentioned requirement regarding the script label.

Thanks

BEGINNER

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
Mentor ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

Hi,

Every object could has a script label and you manage this using insertLabel("key", "value") method.

There are two parameters: "key" and "value" - both string.

Since every label has its "key" (name) you are able to assign as many labels to an object as you want.

You have to collect labels names cause there is no option to list these names in global.

So to get a label value you have to know its "key".

Method: extractLabel("key").

Before/after alert use:

myPageItems.insertLabel("ID", myPgItems.toString() )

rgds

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 ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

The property "label" differs from the data stored and extracted by "insetLabel(key, value)" and "extractLabel(key)" functions.

But "label" property is uneditable by "script Label" panel.

app.activeWindow.activePage.label = app.activeWindow.activePage.id.toString();

alert(app.activeWindow.activePage.label);

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 ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

Of course you can assign the string representation of the id number of an selected object to the label property.

app.selection[0].label = app.selection[0].id.toString();

The problem might be that to see the assigned label string you have to close and re-open the Script Label Panel after script execution…

Uwe

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 ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

And for all page items you could use:

var myPage = app.activeWindow.activePage;

var allMyPageItems = myPage.allPageItems;

var myIDArray = new Array();

for(var n=0;n<allMyPageItems.length;n++){

    myIDArray = allMyPageItems.id;

    };

//Sort all id numbers:

myIDArray.sort(function(a,b){return a-b;});

//You need one object that has a "label" property to assign the string.

//In this case a selected object (eg. a rectangle on the pasteboard).

//To get a string from that sorted number array,

//we could join it setting the delimiter to a paragraph sign, or, if you prefer, with commata, or ...

app.selection[0].label = myIDArray.join("\r");

Just as an example...

Uwe

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 ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

But instead of the label you could also write the joined array of numbers to a text frame on the pasteboard:

//This time the selection is a text frame on the pasteboard:

app.selection[0].contents = myIDArray.join("\r");

Uwe

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
Enthusiast ,
Feb 06, 2013 Feb 06, 2013

Copy link to clipboard

Copied

Hi Laubender/Jump_Over/Junaid,

Thanks for your all response especially thanks for Laubender. Myself and lot of beginners are very inspired of Laubender.

My Requirement:

I want to compare two arrays using 'script label'. Is it possible in Adobe Indesign CS5. If possible means can you explain me. Because i am a beginner.

For example,

Before starting the composing my document has 8 Page items.                        //Stored as 1st array

After finishing composing my document has 7 or 9 Page items                        //Stored as 2nd array

I want to compare both the arrays using script label if any discrepancy generate REPORT.

or we can select a frames (app.selection[0].contents = myIDArray.join("\r");) and generate a REPORT

Below mentioned script are working fine:

var myDoc = app.activeDocument

var myPageItems = myDoc.allPageItems

var myID = new Array()

alert(myPageItems.length)

for(i=0; i<myPageItems.length; i++)

{

   var IDArray = myPageItems.id

  

     myID.push(IDArray)

   

    alert(myID)

    }

myID.sort(function (a,b){return a-b})

//~ app.selection[0].label = myID.join("\r")

app.selection[0].contents = myID.join("\r");

Thanks in advance all legends

BEGINNER

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
Guide ,
Feb 06, 2013 Feb 06, 2013

Copy link to clipboard

Copied

Hi BEGINNER,

1. Why don't you store data in the document label?

2. To faciliate IDs comparison (new objs and/or removed ones), an object structure might be easier than an array.

Here is a possible approach (although not optimized):

function createList(/*PageItem[]*/a)

// -------------------------------------

{

    var i = a.length,

        r = {};

    while( i-- ){ r['_'+a.id]=null; }

    return r;

}

function compareList(o1, o2)

// -------------------------------------

{

    var k, a=[], z=0;

    for( k in o1 )

        {

        if( o2.hasOwnProperty(k) ) continue;

        a[z++] = k.substr(1); // as k is in the form '_id'

        }

    return a;

}

function showReport(oldList, newList)

// -------------------------------------

{

    var r = [],

        a;

    r[0] = (a=compareList(newList, oldList)).length ?

        ("NEW ids: " + a.join(" | ")) :

        ("No NEW item.");

    r[1] = (a=compareList(oldList, newList)).length ?

        ("REMOVED ids: " + a.join(" | ")) :

        ("No REMOVED item.");

    alert( r.join("\r") );

}

// -------------------------------------

// MAIN

// -------------------------------------

var doc = app.activeDocument,

    s = doc.label,

    // ---

    oldList = s && (new Function('return '+s)()),

    newList = createList(doc.allPageItems);

if( oldList ) showReport(oldList,newList);

doc.label = newList.toSource();

alert( "Data properly saved." );

@+

Marc

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 ,
Feb 06, 2013 Feb 06, 2013

Copy link to clipboard

Copied

@BEGINNER_X – I inspected your code and it is more than unfortunate, if you are using statements that are technically working well, but sematically are misleading. For you (sometime in the future, if you'll look again on your code), for everyone else who is trying to debug your code.

Specifically I mean this line:

var IDArray = myPageItems.id


A variable is variable, you can nearly name it as you like, but to use a name that seems to hint, that the variable contains an Array object, when in fact it contains a Number object, that is misleading. The property "id" returns a Number.

And that one:

var myID = new Array()


I just want to say: be very careful with var names in regard of semantics.

And don't forget the ";" at the end of every statement.

Believe me, this is just for security reasons.

Uwe

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
Enthusiast ,
Feb 06, 2013 Feb 06, 2013

Copy link to clipboard

Copied

Hi Mr. Laubender and Mr. Marc,

Thanks a lot for helping me....

Mr. Marc script working fine for me.

Mr. Laubender script helpful for my script.

Forum genius are always helpful and motivate  the new beginners and developers.

Again thanks

BEGINNER

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
Enthusiast ,
Feb 07, 2013 Feb 07, 2013

Copy link to clipboard

Copied

LATEST

Hi Marc/All,

I  want to get master spreads pageitems  as well.

But the given script get pageitems from spreads not from Master Spreads.

function createList(/*PageItem[]*/a)
// -------------------------------------
{
    var i = a.length,
        r = {};

    while( i-- ){ r['_'+a.id]=null; }
    return r;
}


function compareList(o1, o2)
// -------------------------------------
{
    var k, a=[], z=0;

    for( k in o1 )
        {
        if( o2.hasOwnProperty(k) ) continue;
        a[z++] = k.substr(1); // as k is in the form '_id'
        }
    return a;
}

function showReport(oldList, newList)
// -------------------------------------
{
    var r = [],
        a;

    r[0] = (a=compareList(newList, oldList)).length ?
        ("NEW ids: " + a.join(" | ")) :
        ("No NEW item.");

    r[1] = (a=compareList(oldList, newList)).length ?
        ("REMOVED ids: " + a.join(" | ")) :
        ("No REMOVED item.");

    alert( r.join("\r") );
}

// -------------------------------------
// MAIN
// -------------------------------------

var doc = app.activeDocument,
    s = doc.label,
    // ---
    oldList = s && (new Function('return '+s)()),
    newList = createList(doc.allPageItems);

if( oldList ) showReport(oldList,newList);

doc.label = newList.toSource();
alert( "Data properly saved." );

Please can anyone help me.

Thanks in advance

BEGINNER

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