Page 1 of 1
Get all parent folders to project root
Posted: January 26th, 2014, 12:33 pm
by axymark
Hello,
I need to figure out where an item resides inside my project. I can get parent folder with app.project.item(index).parentFolder and could loop my way through until i hit the Root but i'd rather not if there's a better way.
So, to be precise, if i have:
Code: Select all
Project Root
|-- Folder1
|-- Folder2
|-- Item
and i know item index, i would like to get that as a path (/Root/Folder1/Folder2/Item).
Please tell me there's an easy way to do this...

Re: Get all parent folders to project root
Posted: January 26th, 2014, 2:10 pm
by axymark
Another question, is it possible to get item index under parent folder?
If structure is something like this:
Code: Select all
Root
|-- FolderA
|-- FolderB
|-- ItemA
|-- ItemB
|-- ItemC
ItemC is of an index 5 but, knowing that, how would i figure out that this item is of an index 3 under its own parent folder?
Trying to do this through scripting, of course...
Thanks a bunch.
Re: Get all parent folders to project root
Posted: January 27th, 2014, 5:18 pm
by Paul Tuersley
For your first question, I don't think there isn't an easier way to get the folder path than looping through the parentFolder. That's what I would do.
The only way I can think of finding the item index in the folder is to loop through the folder items and compare to your existing item to find a match. i.e. if (item.id == folderObject.item(x).id)
Paul
Re: Get all parent folders to project root
Posted: January 28th, 2014, 10:03 am
by axymark
I suspected that would be the case. Made these functions to deal with it:
Code: Select all
function getItemProjectPath(item) {
var parent = item.parentFolder;
var string = "";
while (parent != app.project.rootFolder) {
var name = "/" + parent.name;
string = name.concat(string);
parent = parent.parentFolder;
}
return string;
}
function getItemFolderIndex(item) {
var parent = item.parentFolder;
for (var i = 1; i <= parent.numItems; i++) {
if (item.id == parent.item(i).id) {
return i;
}
}
}