Adobe Extend Script Toolkit - 最终IF语句中的UnitValue更改?

时间:2015-09-22 00:50:10

标签: javascript adobe photoshop extendscript photoshop-script

这是我在这里发表的第一篇文章。我是java和extendcript的初学者。 我正在使用此脚本查找100x100网格中的黑色像素,它逐行扫描。 X后跟Y增量。

但是当它到达第一行10的末尾时,它会丢失x px单位值,然后它会丢失y px单位值。它仍然有效,但我想知道它们是数字还是单位价值..?

#target photoshop 
app.bringToFront(); 
app.preferences.rulerUnits = Units.PIXELS; 

//Removes All Color Samplers 
app.activeDocument.colorSamplers.removeAll();

// Show Color Sampler/ I don't know how to do this with extend script - generated in console with script listner
// =======================================================
var idShw = charIDToTypeID( "Shw " );
var desc80 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
    var list40 = new ActionList();
        var ref68 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idBckg = charIDToTypeID( "Bckg" );
        ref68.putProperty( idLyr, idBckg );
    list40.putReference( ref68 );
desc80.putList( idnull, list40 );
executeAction( idShw, desc80, DialogModes.NO );
// =======================================================

//Gets Document Width & Height 
var docWidth = activeDocument.width.as('px');
var docHeight = activeDocument.height.as('px');

//Default x Position  - as a Unit Value in pixels needed for sampler     position 
var xPosition = new UnitValue( 0, 'px' );
var yPosition = new UnitValue( 0, 'px'); 

//End point Var - NOT USED 
//var xEndPoint = activeDocument.width.as('px'); 
//var yEndPoint = activeDocument.height.as('px'); 

//Comparison Color Variables [Kind of like a crude memory, add more for more     comparison, or recognized perception] 
var WhiteColor = new RGBColor(); // initial default colour
WhiteColor.red = 255; // rest of the values default to 0
WhiteColor.green = 255; 
WhiteColor.blue = 255

var BlackColor = new RGBColor(); // initial default colour
BlackColor.red = 0; // rest of the values default to 0
BlackColor.green = 0; 
BlackColor.blue = 0;

//======================================================================   

  while( xPosition < docWidth && 
            yPosition < docHeight){ // If the position of the sampler x is less than the doc width  x Height - Stops at end of Doc 

    //Adds a color sampler
    var sample = activeDocument.colorSamplers.add( [ xPosition + .5 , yPosition + .5 ] );  // X, Y position, Y position is set at 0 does not change**
    app.backgroundColor=sample.color;  //Sets thte background color to the sample color, maybe their could be a better way to store this 
    var colorB = new RGBColor();  // New color var to store background color 
    colorB = app.backgroundColor;  //Assigns the background color to previous declare var 

//Nested IF else statements 
//Notes* Alerts Sampled Color - need to store this info, I don't know if I should store this as a RGB value? 

// White Pixel detect 
   if (colorB.rgb.red === WhiteColor.red &&
   colorB.rgb.blue === WhiteColor.blue &&
   colorB.rgb.green === WhiteColor.green)
      {
      //alert("White Pixel");                                               
      }

// Black Pixel detect 
  else if (colorB.rgb.red === BlackColor.red &&         
   colorB.rgb.blue === BlackColor.blue &&
   colorB.rgb.green === BlackColor.green)
      {
      alert("Black Pixel " + "x : " +  xPosition + "    y : " + yPosition + '\n'   
   + "R = " + (colorB.rgb.red) +  '\n' 
   + "G = "+ (colorB.rgb.green) + '\n' 
   + "B = "+ (colorB.rgb.blue)); 
  }

// Other Pixel detect - Error option 
   else {                                   
      alert("Other Color");     
      }

//Final process 

  app.activeDocument.colorSamplers.removeAll(); //Removes the sampler so that there arn't to many 

  xPosition++; //increases the position by one, this is the end of the loop, starts again until while statement is void 

//Once it arrives at the end of the line, increase y -value & reset x position 

    if (xPosition == docWidth) { 
          xPosition = xPosition - docWidth; 
          yPosition++; 
          }


  } //bottom bracket of while statement 

//======================================================================   

1 个答案:

答案 0 :(得分:0)

x && y = z是否有效javascript?
在ESTK中运行以下代码时,它返回undefined

var x,y;
// x = y = 12; // returns 12
x && y = 13; // returns undefined
$.writeln(x);

当我评论第三行并在第二行发表评论时,它甚至更加陌生。结果是:

12

之后评论第二个并再次评论第三个,结果仍然是:

12

这一直持续到我重启ESTK。

反正。我从未在JS中看到像x && y = z这样的表达式。这可能是你的错误。