Script for selecting multiple objects
I have this script where I recognize layer object by color. I now have multiple objects in my list listOfRest but how do I select them and get their combined left and top values?
I have this script where I recognize layer object by color. I now have multiple objects in my list listOfRest but how do I select them and get their combined left and top values?
My apologies. I had a bug in there. I wasn't comparing the values properly.
The part you asked about is a ternary statement. It's just a condensed if/else clause. Here's some reading if you're interested (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
topMost = listOfRest[i].top > topMost ? listOfRest[i].top : topMost;
Here i've broken it down into sections. Green is the variable definition. I'm setting "topMost" equal to the result of the rest of the expression.
Blue is the ternary condition.
If Blue evaluates to true, Green will be set equal to the value of Red
If Blue evaluates to false, Green will be set equal to the value of Orange/yellow
Here's a fixed version. I fixed the bug in the comparrison and i used regular if clauses so it's more clear.
var topMost = listOfRest[0].top;
var leftMost = listOfRest[0].left;
for(var i=0; i < listOfRest.length; i++)
{
listOfRest[i].selected = true;
// topMost = listOfRest[i].top > topMost ? listOfRest[i].top : topMost;
// leftMost = listOfRest[i].left < leftMost ? listOfRest[i].left : leftMost;
//check to see if this piece is "higher" than the topMost piece
//ie.. is the top value of the current piece greater than the topmost
//if it is, set the value of topMost to the top value of this item
if(listOfRest[i].top > topMost)
{
topMost = listOfRest[i].top;
}
//check to see if this piece is "farther left" than the leftMost value
//if it is, set the value of leftMost to the left value of this item
if(listOfRest[i].left < leftMost)
{
leftMost = listOfRest[i].left;
}
}
alert("Non-Red items have been selected.\nCombined top and left vaues:\nleft: " + leftMost + "\ntop: " + topMost);
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.