Skip to main content
Known Participant
August 3, 2017
Answered

About Project Item's ID

  • August 3, 2017
  • 2 replies
  • 1353 views

Hi everyone,

I can get an item's ID with : var id = app.project.item.id;

like id = 966900432;

but if I have an number : 966900433;

my question is how to judge this number is legal or not?

thanks;

This topic has been closed for replies.
Correct answer Tomas Sinkunas

There's default method app.project.itemByID(itemID) that get's project item by ID. However, it will raise error if such itemID is not valid. To overcome this, use it in try/catch block.

var itemID = 1;

var item = getItemByID(itemID);

alert(item);

function getItemByID(itemID) {

    try {

        return app.project.itemByID(itemID);

    } catch(e) {

        return null;

    }

}

Hope that helps.

2 replies

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
August 3, 2017

There's default method app.project.itemByID(itemID) that get's project item by ID. However, it will raise error if such itemID is not valid. To overcome this, use it in try/catch block.

var itemID = 1;

var item = getItemByID(itemID);

alert(item);

function getItemByID(itemID) {

    try {

        return app.project.itemByID(itemID);

    } catch(e) {

        return null;

    }

}

Hope that helps.

UQg
Legend
August 4, 2017

Thanks Tomas, i never noticed that.

Xavier

UQg
Legend
August 3, 2017

I don't think there is another way than runnning through all app.project.item(xxx) until you hit one that has the desired id.

Xavier