Selection without selection bounds

I'm using CS2 so I can't call on selection bounds (which seems to be the preferred method of working with selections)
var sb = activeDocument.selection.bounds;
var sbWidth = sb[2]-sb[0];
var sbHeight = sb[3]-sb[1];
alert(sbWidth + " , " + sbHeight)
So the above code won't work for me
How can I find out (1) if a selection is set (selection width & height = 0?) and (2) find the width and height of said selection assuming that only the rectangular marquee is used (not ellipse or lasso).
Cheers

I had to find out bounds of selection that could be any shape for my Photoshop Photo Collage Toolkit the selections are image size and shaped alpha channels in the Photo Collage Template PSD file with the names "Image 1", "Image 2", ..., "Image n".  I had a heck of a time to come up with a way that worked in CS2, CS3, Cs4 and CS5. After consulting with my good friend Rube Goldberg we can up with a contraption that seems to work. This is not a thing of beauty. Some local functions are not shown for the function name states what it does.
// Get Alpha Channel's width and height Selection Bounds did not work???
makeLayer(); // Make Temp Work Layer
loadAlpha("Image " + imageNumber ); // Load Image Alpha Channel
fillBlack();
activeDocument.selection.invert(); // Inverse
// If image size equals canvas size no pixels will be selected clear will fail
try{
activeDocument.selection.clear(); // One clear did not work
activeDocument.selection.clear(); // Two did the trick
}catch(e){}
activeDocument.selection.deselect(); // Deselect
var SB = activeDocument.activeLayer.bounds; // Get the bounds of the work layer
var SWidth = (SB[2].value) - (SB[0].value); // Area width
var SHeight = (SB[3].value) - (SB[1].value); // Area height
activeDocument.activeLayer.remove(); // Remove Work layer
Where there is a will there is a way. Layer bounds does work...
I needed these selections bounds so I could resize and align placed images to these mapping Alpha Channels and mask any Image overflow.
Link to my Photo Collage Toolkit

Similar Messages

  • Selection.bounds operation?

    I have this simple jsx script where I want to get the bounds of a selection:
    try
            var s = app.activeDocument.selection.bounds
            alert(s.toSource())
    catch(e)
            alert("No selection")
    It does detect that there is a selection present but does not return that array of x,y coordinates that bounds the selecton.
    The alert displays [({}),({}),({}),({})]
    all elements of the array are determined to be undefined.
    Any help is appreciated.
    Thanks!
    Ray

    What application are you scripting?

  • Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    Why can't I select an object from its center?  Direct selecttool will only select bounding box.

    You may have turned on "Object selection by path only" in the "Selection Options".

  • Can I write to Modbus I/O Server addresses without creating bound variables?

    Hi all,
    I'm wondering if it's possible to use the Modbus I/O Server without explicitly creating bound variables?
    If I write a value to the bound variable at "ni.var.psp://My Computer/Slave/300001", the master can see the value.
    The variable properties paeg says that the variable is bound to "My Computer\Slave.lvlib\ModbusSlave1\300001"
    I deleted the bound variable and tried a few different ways to write directly to the I/O Server, but all of them gave me Error 0x8BBB0005. I tried the following:
    ni.var.psp://My Computer/Slave/300001
    ni.var.psp://My Computer/Slave/ModbusSlave1/300001
    ni.var.psp://My Computer/Slave.lvlib/ModbusSlave1/300001
    ni.var.psp://My Computer/Slave.lvlib/ModbusSlave1/300001
    I also tried replacing "My Computer" with "localhost" above. No luck.
    Is there anything I've missed? I'm asking because CPU usage is very high, and I thought I might be able to reduce that a bit by removing the 300 bound variables in the system.
    Solved!
    Go to Solution.

    You can use DataSocket with a path like psp:\\localhost\Slave\ModbusSlave1.400001 for read and write access.
    Check out the example VI "Monitor OPC Items with DataSocket.vi" in the LabVIEW examples.

  • Selection Tool behavior

    And here I mean "The Selection Tool" not "direct" or "perspective"...
    I'm taking a Lynda.com video training course (AI CS6 One-on-One/Fundamentals) in which the instructor is demonstrating (Chapter 7) moving and duplicating objects by clicking the anchor point with the black selection tool and dragging to the diagonal alternate selection point. He and I both have Smart Guides turned on...but when he - after clicking on an anchor point in a selected object and with mouse button down - mouses over another anchor point in the selected object the black mouse pointer turns white, giving a solid cue as to where to drop the object to move (or, with alt- on pc or opt- on Mac, exactly duplicate the object) to an adjascent place. Mine doesn't and it's much harder for me to get a visual cue as to where to make the drop. The smart guide says "intersect" at a particular point and it usually seems right but it's different behavior than on Deke McClelland's otherwise excellent and informative video.
    I don't know if I have a preference set differently than the instructor, but I'd much rather have the behavior he is demonstrating than what I've got.
    Also, I note that when mousing around anchor points there is a change to the cursor to a double-headed arrow with a line through the center, that I don't understand (and that if  I get it and try to use it, it doesn't do what I'm trying to do with the anchor point).
    If someone could point me to some documentation that details the use of that tool (particularly for moving and/or duplicating objects and constraining movement/duplication), I'd really appreciate it. Examining the reference PDF I find lots about the other selection tools but not about the primary/original one, and it obviously has multiple behaviors I'd like to see documented.
    Thanks,
    Jay

    JET:
    Thanks for asking and for your interest. I just went back to reproduce the issue and found it's the same with or without the Bounding Box in sight. I get a different cue (the SmartGuides in the middle of where the tile is prospectively moving has the word "Intersection" and two green lines...if I press the Alt key to copy I see a white arrow and a black one with it...but the effect Deke is trying to show, with the black arrow turning white upon hovering or "mousing" over the anchor point, is missing, whether Bounding Box is set to Show or Hide.
    As long as the word Intersection means the same thing I can work with it, but it seems like the arrow turning white is a much more positive cue. Again, thanks...
    Jay

  • Get Selection Size in Pixels

    I can't seem to figure this out.
    var oCurSelection = activeDocument.selection;
    var aSelSize = new Array;
    aSelSize = oCurSelection.bounds;
    I want to take a selection, make a new document at the selection size, and copy the selection to the new document. However, in the Data Browser, under activeDocument.selection.bounds, I see:
    "Error: General Photoshop error occurred. \n. The command \"Get\" is not currently available."
    What does this mean? A function I copied from these forums to detect a Selection (detectSelection) says there is a selection. Why can't my code see it?
    Thanks,
    Matthew Pfluger

    Thanks, Xbytor, for all your help. Here is a copy of my completed script. Please note, all, that it has not been thoroughly tested.
    // (c) Copyright 2008. Digital Age Media Services, LLC. All rights reserved.
    // Written by Matthew Pfluger
    // With the help of Xbytor on the Adobe User-to-User forums
    // enable double-clicking from Mac Finder or Windows Explorer
    #target photoshop
    // this command only works in Photoshop CS2 and higher
    // bring application forward for double-click events
    app.bringToFront();
    // ensure that there is at least one document open; if not, display error message
    if (documents.length == 0) {
    alert("There are no documents open.");
    // ensure that a selection exists; if not, display error message
    else if (!detectSelection()) {
    alert("You must first create a selection.");
    // if both a document and a selection exist and the selection isn't empty, then proceed
    else {
    // remember unit settings
    var originalRulerUnits = preferences.rulerUnits;
    // main
    try {
    // Get information about Current Selection
    var docSource = activeDocument;
    var oCurSelection = docSource.selection;
    var aSelSize = GetSelectionBounds(docSource);
    // Calculate width and height in given units
    var width = aSelSize[2] - aSelSize[0];
    var height = aSelSize[3] - aSelSize[1];
    var lResolution = docSource.resolution;
    // Create new filename so we don't overwrite any files
    var sDocName = GetNewDocName(docSource);
    var sFilePath = docSource.path.fsName + "\\" + sDocName + ".jpg";
    var oMode = docSource.mode;
    // Copy Selection
    oCurSelection.copy()
    // Add new document
    var docNew = app.documents.add(width, height, lResolution, sDocName);
    app.activeDocument = docNew;
    docNew.mode = oMode;
    // Copy image to new document
    docNew.paste()
    // Save New Document as JPEG
    jpgFile = new File(sFilePath);
    jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = 9;
    docNew.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
    // Close document without saving
    docNew.close(SaveOptions.DONOTSAVECHANGES);
    // display error message
    catch (e) {
    // throw e;
    alert("An unknown error has occurred. Copy selection to new JPEG file failed.");
    // restore original unit setting
    preferences.rulerUnits = originalRulerUnits;
    function GetNewDocName(docSource){
    var sPath = docSource.path.fsName;
    // count number of JPEGs in the activeDocument's parent folder
    var lJPEGcount = CountFiles(sPath, "*.jpg")
    // New FileName based on activeDocument.Name
    // Also, ensure no repeat FileNames
    return docSource.name.slice(0, -4) + " - Selection_" + lJPEGcount;
    // Count the number of files in a given folder that match a given mask
    function CountFiles(sFolderPath, sMask) {
    // create folder object from input
    var oFolder = new Folder (sFolderPath);
    // create list of all JPEG files in selected folder
    var docList = oFolder.getFiles(sMask);
    return docList.length;
    // check for a selection
    function detectSelection() {
    // declare local variables
    var userHistory = activeDocument.activeHistoryState;
    var isSelection = false;
    // try Selection, Modify, Border and then undo if selection is detected
    try {
    activeDocument.selection.selectBorder(1);
    activeDocument.activeHistoryState = userHistory;
    isSelection = true;
    // catch errors - no selection detected
    catch (e) {}
    return isSelection;
    // tests for an empty selection
    function selectionEmpty(){
    var rc = true;
    var doc = activeDocument;
    try {
    var me = doc.activeHistoryState;
    doc.activeLayer.translate(0,1);
    doc.activeHistoryState = me;
    rc = false;
    } catch (e) {
    if (!e.toString().match(/initial bounding rectangle is empty/)) {
    throw e;
    return rc;
    // returns the upper-left and lower-right points of the selection
    function GetSelectionBounds (doc) {
    var l = doc.artLayers.add();
    doc.selection.fill(app.foregroundColor);
    var bnds = l.bounds;
    var hs = doc.historyStates;
    if (hs[hs.length-2].name == "Layer Order") {
    doc.activeHistoryState = hs[hs.length-4];
    } else {
    doc.activeHistoryState = hs[hs.length-3];
    for (var i = 0; i < bnds.length; i++) {
    bnds[i] = bnds[i].value;
    return bnds;

  • How to get only the selected layer data?

    Hi All,
              I'm using dissolve sample plugin. I added two layers in photoshop both of different dimensions, say 1000 * 1000 & 2000 * 2000. Now I select the layer with 1000 * 1000 dimension and click on Dissolve plugin. The preview image what is shown in dissolve plugin dialog is not just the selected layer, but also some extra pixels around the selected layer.
    Do I need to set any flag for getting only selected layer data to display in preview?
    Also I need to get only the selected area in a particular layer. When I checked FilterRecordPtr, haveMask flag is TRUE if the part of the layer is selected. But how do I get only the part of the layer that is selected for displaying preview image?
    Please let me know if the description is not clear.
    Thanks,
    Dheeraj

    Thanks Tom Ruark for the response.
    That is exactly the same thing what I'm seeing.
    1.Is there a direct way to know the bounds of the layer without the transparency grid so that I can show only the layer?
    2. If I select an area of 50*50 within a layer(1000*1000) using Rectangular Marquee tool, then I want only that selected area to be shown in preview. For this there is a haveMask flag which indicates whether or not there is selection, but the selected bounds are not available. I'm currently calculating the bounds. I just wanted to know if Photoshop SDK has any field for getting the bounds?

  • How to get the area of a selected rectangle?

    Hi:
    I want to use the selected area in a automation plugin. In my case, the area is rectangle. i can't get the top,left,bottom and right position.
    Is there anyone can help me?

    I'm petty you sure can extract the details you want using a script. I think the method is called Selection Bounds, and it return an array of the unitValue of the rectangle.
    If you look at the scriptlistener code for creating a rectangle, it does record the data you want. So you should be able to extract it using Javascript, Apple Script or VB
    This is what the scriptlistener code looks like,
    // =======================================================
    var id5 = charIDToTypeID( "setd" );
    var desc3 = new ActionDescriptor();
    var id6 = charIDToTypeID( "null" );
    var ref1 = new ActionReference();
    var id7 = charIDToTypeID( "Chnl" );
    var id8 = charIDToTypeID( "fsel" );
    ref1.putProperty( id7, id8 );
    desc3.putReference( id6, ref1 );
    var id9 = charIDToTypeID( "T " );
    var desc4 = new ActionDescriptor();
    var id10 = charIDToTypeID( "Top " );
    var id11 = charIDToTypeID( "#Pxl" );
    desc4.putUnitDouble( id10, id11, 210.000000 );
    var id12 = charIDToTypeID( "Left" );
    var id13 = charIDToTypeID( "#Pxl" );
    desc4.putUnitDouble( id12, id13, 276.000000 );
    var id14 = charIDToTypeID( "Btom" );
    var id15 = charIDToTypeID( "#Pxl" );
    desc4.putUnitDouble( id14, id15, 455.000000 );
    var id16 = charIDToTypeID( "Rght" );
    var id17 = charIDToTypeID( "#Pxl" );
    desc4.putUnitDouble( id16, id17, 613.000000 );
    var id18 = charIDToTypeID( "Rctn" );
    desc3.putObject( id9, id18, desc4 );
    executeAction( id5, desc3, DialogModes.NO );

  • FR: Direct selection/manipulation of clip(s) in Program Monitor

    If you agree with this improved workflow, please add your own voice here www.adobe.com/go/wish.
    *******Enhancement / FMR*********
    Brief title for your desired feature: Direct selection of clip(s) in Program Monitor for modification
    How would you like the feature to work?
    We should be able to directly select a clip/asset in the Program Monitor to move/resize/rotate it.  Even better would be the ability to SHIFT-click-select 2 or more items to move/scale/rotate them in tandem!
    Why is this feature important to you? 
    The current workflow is convoluted/unintuitive since it requires users to: 1) select a single clip for modification under the CTI in the Timeline, 2) click on 'Motion' in the Effect Controls Window. 3) make the desired Motion changes in the ECW and/or Program Monitor. 4) repeat steps 1-3 for any additional clips/titles in the Program Monitor that needed to be changed in tandem.
    While this Feature Request may require a 2 step implementation, first allowing the direct selection of a single clip, and later allowing the selection/Motion manipulation of 2 or more clips at the same time, allowing a single clip to be directly selected in the Program Monitor for now would be a big step towards finally making it possible to change the Motion attributes of 2 or more PIPs at the same time. 
    NOTE: For direct clip selection to work effectively, the 'selectable' bounding box of titles would have to be automatically restricted to the dimensions of the Text itself, and not default to the dimensions of the Video Settings as is currently the case, since otherwise, it would not be possible to directly select a clip under a title of equal video dimensions.

    What to you mean by 'total different fixed effect properties' Ann?
    Modifying the selected clips in the Program Monitor would automatically update each clip's position/scale/rotation values independently.  No need for more than one ECW as you imply.
    So if
    Clip 1 = X:960 Y:200 and
    Clip 2 = X:500 Y:400,
    moving both clips to the right 50 pixels together would result in
    Clip 1 = X:1010 Y:200 and
    Clip 2 = X:5050 Y:400
    Same with scale. Example
    Clip 1 = 25
    Clip 2 = 50
    doubling the size of the clips in the Program Monitor would result in
    Clip 1 = 50
    Clip 2 = 100
    While 2 or more clips are being modified in Program Monitor, any Motion values that are not identical between all selected clips could be displayed as '-', meaning different values are present.  Inputing a number value would automatically add that value to all selected clips.
    For example, Scale:
    Clip 1 = 35
    Clip 2 = 42
    Clip 3 = 12
    ECW value displayed as '-'.  Type 50 into this field and all three selected clips would automatically be given an identical scale value of 50.
    Hope this makes sense.

  • Selecting pixels in a picture and changing their color with a script

    Hi, I'm brand new to photoshop scripting, and I want to make a script that takes every pixel of a color and replaces it with a new color,
    I'm having the hardest time finding any information on the internet on how to do it though.
    I do have some background in other coding, so the concepts are not new, just the language and functions.
    I know there's tools and filters already, but I want to make a script so I can add features.
    Any help would be appreciated.
    Thank you!
    (P.S. Is there a way to open and read code of a pre-exsisting filter, or is that impossible?)

    To create your own filters you would need to download the SDK I think you might find an example of a filter.
    With Photoshop this might be close...
    main();
    function main(){
    if(!documents.length) return;
    var sColour =new SolidColor;
    sColour.rgb.hexValue ='245887';
    selectColorRange(0,sColour);
    try{
    var SB = activeDocument.selection.bounds;
        }catch(e){return;}
    var FillColour =new SolidColor;
    FillColour.rgb.hexValue = 'ff0000';
    activeDocument.selection.fill(FillColour,ColorBlendMode.NORMAL);
    activeDocument.selection.deselect();
    function selectColorRange( fuzz, solidColor){
    var scaleA = (solidColor.lab.a + 128.5) / 256;
        var desc11 = new ActionDescriptor();
        desc11.putInteger( charIDToTypeID( "Fzns" ), fuzz );
            var desc12 = new ActionDescriptor();
            desc12.putDouble( charIDToTypeID( "Lmnc" ), solidColor.lab.l );
            desc12.putDouble( charIDToTypeID( "A   " ), solidColor.lab.a + scaleA);
            desc12.putDouble( charIDToTypeID( "B   " ), solidColor.lab.b + scaleA);
        desc11.putObject( charIDToTypeID( "Mnm " ), charIDToTypeID( "LbCl"), desc12 );
        desc11.putObject( charIDToTypeID( "Mxm " ), charIDToTypeID( "LbCl" ), desc12 );
    executeAction( charIDToTypeID( "ClrR" ), desc11, DialogModes.NO );
    Using Christophs suggestion...
    //Use 1 pixel to colour
    app.activeDocument.colorSamplers.removeAll();
    var mySampler = app.activeDocument.colorSamplers.add([new UnitValue(1,'px'),new UnitValue(1,'px' )]);
    //Get original colour
    var oColour = new SolidColor();
    oColour = mySampler.color;
    app.activeDocument.colorSamplers.removeAll();
    //Select colour
    var sColour = new SolidColor();
    sColour.rgb.hexValue ='31618f';
    activeDocument.selection.select([[0,0],[1,0],[1,1],[0,1]], SelectionType.REPLACE, 0, false);
    activeDocument.selection.fill(sColour,ColorBlendMode.NORMAL);
    //Replacement Colour
    var rColour = new SolidColor();
    rColour.rgb.hexValue ='ff0000';
    activeDocument.selection.similar(0, false);
    activeDocument.selection.fill(rColour,ColorBlendMode.NORMAL);
    activeDocument.selection.deselect();
    //Replace original colour.
    activeDocument.selection.select([[0,0],[1,0],[1,1],[0,1]], SelectionType.REPLACE, 0, false);
    activeDocument.selection.fill(oColour,ColorBlendMode.NORMAL);
    activeDocument.selection.deselect();

  • Save Selection to JPEG

    I just upgraded from Photoshop CS2 to CS4, and I found that a script I wrote no longer works.  I attached a text version of the file to this thread.
    Basically, the script allows me to open a file, make a selection, and quickly save the selection to a JPEG.  When I use ExtendScript to step through the script, it errors on the following line:
         var docNew = documents.add(width, height, lResolution, sDocName, oMode);
    Can someone please download the script, try to run it, and let me know if they have the same error?  If possible, I'd like to know how to fix this problem.  This script saves me huge amounts of time, and I would really like it to work.
    Thanks,
    Matthew Pfluger

    Paul,
    Thank you!  That pointed me in the right direction.  I changed both 'width' and 'height' to unit values of type 'px' and oMode to NewDocumentMode.RGB.  That caused the script to correctly make a new document.
    I also had to change the routine that calculates the selection bounds.  Before, it wasn't checking and setting Units to Pixels before calculating the selection bounds, though the return array implied this was the case.  To solve this, I added the following line:
         app.preferences.rulerUnits = Units.PIXELS
    This caused the subfunction to return an array of pixels defining the selection bounds.
    Paul, thanks again for your help.  I'm normally a VBA and VB.NET programmer, and it's fun to step into a new language.  When I clean up the script, I'll post the revised text.
    Matthew Pfluger

  • Draw line between black pixel : coordinates of selected pixels ?

    Hi
    I want to build a script which can check a Photoshop file and :
    - find black pixel
    - for each black pixel, look for another black pixel within maximum distance of 5 pixels
    - then draw a line between the two black pixels.
    I wrote this script below (my first script ...), but it's VERY slow (and my final image is VERY big), I think because I test the colour for each pixel of the image.
    So another solution would be to first select black pixel with magic wand, then the script save all coordinates of selected pixels, then my script wil test only this pixels (less than 1% of the pixels are black in my image).
    Is it possible with JavaScript ?
    Thank you for your response !
    Marc
    function main(){
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var myHeight = app.activeDocument.height;
    var myWidth = app.activeDocument.width;
    // Find black pixel
    for(var i=5; i<myWidth; i++) {
      for(var j=5; j<myHeight; j++) {
       activeDocument.colorSamplers.removeAll()
       var sampler = activeDocument.colorSamplers.add([new UnitValue (i, 'px'), new UnitValue (j, 'px')]);
       if (sampler.color.rgb.hexValue === "000000") {
    // For each black pixel, search another black pixel below left up to 5 pixels
        for (var m=i-5; m<i; m++) {
         for (var n=j+1; n<j+5; n++) {
          activeDocument.colorSamplers.removeAll()
          var test = activeDocument.colorSamplers.add([new UnitValue (m, 'px'), new UnitValue (n, 'px')]);
          if (test.color.rgb.hexValue === "000000") {
    // Then draw a black line between the two black pixels
           var FillColour = new SolidColor;
           FillColour.rgb.hexValue = '000000';
           var ad=activeDocument;
           ad.selection.select([[m,n],[i,j],[m,n+1],[i,j+1]], SelectionType.REPLACE, 0, true);
           ad.selection.fill(FillColour);
           ad.selection.deselect()
    // For each black pixel, search another black pixel below right up to 5 pixels
         for (var m=i+1; m<i+5; m++) {
          for (var n=j; n<j+5; n++) {
           activeDocument.colorSamplers.removeAll()
           var test = activeDocument.colorSamplers.add([new UnitValue (m, 'px'), new UnitValue (n, 'px')]);
           if (test.color.rgb.hexValue === "000000") {
    // Then draw a black line between the two black pixels
            var FillColour = new SolidColor;
            FillColour.rgb.hexValue = '000000';
            var ad=activeDocument;
            ad.selection.select([[i,j],[m,n],[m,n+1],[i,j+1]], SelectionType.REPLACE, 0, true);
            ad.selection.fill(FillColour);
            ad.selection.deselect()
    main();

    The first alert should have shown the first pathPoint.anchors for all the subPaths in the path.
    The xyArray is just something I added for the alerts. The array 'myPathInfo' should have all the info extracted from the path.
    myPathInfo.length will tell you how many subPaths are in the Path.
    myPathInfo[index].entireSubPath.length will tell you how many pathPoints are in that subPath
    myPathInfo[index].entireSubPath[index].anchor will tell you the position of that pathPoint.
    The indexes start with zero.
    The bounding box of the entire subPath can be hard to work out just from the pathPoints. Unless all the point are corner points the path may extend beyond the anchors. One think you can do is create a new path from just one of the subPaths, convert by to a selection, and then get the bounds from the selection. You can make a new path from a subPath using the 'myPathInfo' array from above.
    app.activeDocument.pathItems.add("myPath1", [myPathInfo[0]]);
    That line will make a new path from the first subPath. Change the index to use a different subPath.
    Some other info that may help.
    app.activeDocument.histogram[0] will tell you how may black pixels are in the document. But its no help determining where they are. If that returns 0 there are no black pixels.
    If you don't have any luck working with converting the original color range selection into a path and need to go back to searching with the colorSampler it may help to use a grid approach. For example make a square selection, the size depending on how scattered the black pixels are, say 25x25px. Then use color range to select black. With an active selection it will only select pixels in that selected area( if any). You could then check to see if there is a selection. If not make another same size square to the right edge of the last area. If there is a selection, the solid property will tell you if more than one black pixel was selected( unless they are right next to each other ). If solid == true the selection bounds will tell you where the pixel is. If false you have to then search that square. But if there are areas where there are no black pixels checking a square range of pixels at once should be quite a bit faster than checking every pixel. And checking the historgram first will let you know if you should bother searching to start with.

  • How to check the availability of selection

    Hello to all !
    I have a script fills in the  selected area. But if the user has not made a selection, the string Mybounds = doc.selection.bouns an error. How I can check is the selection are not ?

    You could wrap (var myBounds = app.activeDocument.selection.bounds) in a try clause.

  • Verify if a selection exists

    Sorry to bother You all with such a question, but how can I verify if an active selection exists in a document?
    Actually I seem to be able to verify it by way of a whack try-catch-construction set to some selection-property (which returns undefined if no Selection exists), but obviously a more simple way should exist. 
    I want to do so in order to set up a condition to delete the Layer Mask if no Selection is active on creating an Adjustment Layer (a basic setting seemingly lost in CS4).
    Thanks for any suggestions.

    > A nifty construction, but it seems to indicate that the fact of a Selection being active is indeed not an easily accessed property.
    This is true.
    > I wonder if
    >
    > var myDocument = app.activeDocument;
    > try {var forgetIt = myDocument.selection.bounds}
    > catch (a) {alert (has no selection)};
    >
    > might not be shorter after all?
    >
    Marginally shorter, but bad form. A general rule for good programming is that
    you do not use try/catch for stuff like this. There are times when you
    absolutely have to because there is no other choice or times when it saves you
    20 or 30 lines of code. But, in this case, the hasSelection function is small
    enough that there is no real benefit to doing the try/catch.
    [email protected] wrote:
    > Likely the reason X used the form shown in the first example is that earlier
    versions of Photoshop had problems when requesting selection bounds and it seems
    I recall some versions where it didn't work at all.
    Selection.bounds didn't work in CS2 and accessing the property would always
    raise an exception. I'm not really sure how I implemented earlier versions but
    using the history state stack trick has simplified a lot of code.
    -X

  • How can I automatically create a rectangular layer mask from an irregularly shaped selection?

    I am trying to automatically crop images. The subject is on a white background and extends from the left edge of the image to the right. The top and bottom of the subject are within the frame. I need to crop a certain distance from the top and bottom of the subject and a predefined width that would be calculated from the height of the subject.
    My current idea is to create a duplicate layer and run Threshold on it, which allows me to select the subject clearly. Once I have the subject selected I can use Image -> Crop to create the desired rectangle, but I can't figure out a way to create a mask from the irregularly selected subject. Does anyone know a way to take a selection and convert it to a rectangle? I hope this makes sense, I can try to explain better if not. Thanks.
    --Chris

    // make selection rectangular;
    // 2013, use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    try {
    var theBounds = myDocument.selection.bounds;
    var theArray = [[theBounds[0], theBounds[1]], [theBounds[2], theBounds[1]], [theBounds[2], theBounds[3]], [theBounds[0], theBounds[3]]];
    myDocument.selection.select(theArray, SelectionType.REPLACE, 0, false);
    catch (e) {}

Maybe you are looking for

  • HT204266 unauthorised purchase - how do I get a refund

    I have a debit done that is not authorised - how do I get a refund and to cancel any further actions

  • Upgrade solaris 8 to 10 from CD on running system

    hello, is it possible to upgrade to version 10 on a running solaris 8 system? It's a proliant dl380 (1st gen). I try to get solaris 10 to see the raid controller but it doesn't recognize it. However, 8 works perfectly. Since the 10 CD number 1 doesn'

  • Aligning SQL reports in a region so that all top edges are aligned

    I have 3 SQL report regions in column 2. I would like these to display so their top edges are aligned. 40           Approved Tests     Report (Column 2)     Conditional 60           Unapproved Tests     Report (Column 2)     Conditional 80           

  • External HD in use?

    I have a: Model: LaCie BigDisk Extreme, Capacity: 467.52 GB, Bus: FireWire 800, Bus Location: External, LaCie Big Disk Extreme. It keeps "clicking"(like something is happening, & the "blue lite" flashes for a few seconds every now & then BUT I'm NOT

  • Script Text Editor alignment

    Hi Folks, I have an allignment problem w.r.t the text editor in a Script. C5   ,,&printtab-wt_qsshh(IC)& <b>/:   IF &PRINTTAB-BUDAT(ICZ)& NE '..' C5   ,,   &printtab-BUDAT(ICZ)& /:   ELSE C5 /:   ENDIF =    ,,,,&printtab-wt_qbshh(IC)&,,&printtab-qsat