Please add node.indexInParent

In parallel with a GraphicNode’s parent field, it would be wildly useful to have an indexInParent field, so you could quickly clamber around tree structures without scanning a parent for the index of the node in question.

The indexInParent field would of course just be the node’s index in the parent node’s children.

With this, you would have the effect of sibling pointers like you have in an HTML DOM.

Thanks for adding a feature request. As you know, we review feature requests based on the number of votes

I could use this too. Are you just iterating through nodes and getting the index manually?

These seem to work. The second one makes more sense looking at the layers panel (it is index from top to bottom).

function getItemIndex(item) {
	var items = item.parent.children;
	var numberOfItems = items.length;

	for(var i=0;i<numberOfItems;i++) {
		if (items.at(i)==item) {
			return i;
		}
	}
}


function getItemIndexReverse(item) {
	var items = item.parent.children;
	var numberOfItems = items.length;

	for(var i=0;i<numberOfItems;i++) {
		if (items.at(i)==item) {
			var n = parseInt(numberOfItems) - i;
			return n;
		}
	}
}

I am asking for this since summer.
Voting is nice but some things should just be common ground. Having access to an index parameter is not so crazy.

The methods above work for me.

I think it was confusing at first because the layers panel has the highest items at the top but the index at the top is 0 while the lowest item location + previous items.

<group>
   <layer>I am layered above all other layers but my index is 0</layer>
   <layer>My index is 1 but I am shown beneath top layer</layer>
   <layer>My index is 2 but I am beneath 1 and 0</layer>
</group>

They layers panel is interesting because you have different metaphors for layers. Are things ordered like a stack of papers?

<stack>
   <paper>I am at the top of the layers</paper>
   <paper>Item 2</paper>
   <paper>Item 3</paper>
</stack>

Where the item at the top of the screen is the top of the pile? Or do you handle it like reading a book from top to bottom where you are adding one layer and the next layer is added after that like elements in a web page?

<container>
   <div>I am the first added item to the page.</div>
   <div>I am the second added and above first item.</div>
   <div>I am the third item added and above previous items.</div>
</container>

Oh boy. lol. …eh hem cough cough. yes I agree. we should add all APIs. (ducks) :smirk:

1 Like

:raising_hand_man::stuck_out_tongue_winking_eye:


For those new to the forums: @Velara and I have had plenty of discussions in the forums about whether API features which are not really necessary, but may add some level of simplification should get added to the APIs. While I am a bit more conservative (“only add to the APIs what’s necessary for developers to achieve what they want to achieve”), @Velara is a lot more open to such simplifying, but not really necessary API features. We’ve had the discussion so many times by now, that it’s basically become a running gag :slightly_smiling_face:.


On an a bit more serious note:

Personally, I think that this isn’t really necessary, as determining this value is easy to do with the APIs as they are now and there are a lot more pressing matters when it comes to aligning the APIs to what’s possible for a user to do manually. There also aren’t any big performance concerns and if one wants this to be simplified, it’s perfectly reasonable to do this as a library without any need for time of the Adobe team, whose efforts I (personally) appreciate much more when they get devoted to adding more general functionality to the APIs (or perhaps answering to issues on GitHub) :wink:.

1 Like