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;

Similar Messages

  • Preview Selection Tool-How to get selection size in Preview?

    One of my favorite tricks in Preview (prior to Leopard) was being able to hold the alt-key to get the selection size. Leopard killed this amazing feature and now I have to open Photoshop every time I want to get the size of something. Does anyone out the have any idea how to quickly get selection size in Preview in Leopard? I thought I would just be able to make a selection, crop the image and get the size that way, but worst of all, the image size only reflects the original image size and not the newly cropped size. The latter seems like a bug and the former is annoying.

    I've been on Leopard for a year and I was always able to just put the cursor on the image, draw my box and hit the crop button. In the last week, I've lost the ability to draw my box. It's like it's been disabled. I've restarted to no avail. This was a great little feature as I do not want to load every picture into iPhoto.

  • Get parent control size in pixels

    Hi experts
    How can I retrieve parent control size in pixels?
    Thanks an advice.
    Edited by: Artem Zyuzko on Nov 24, 2011 3:11 PM

    hi John
    I'm using BusinessGraphics control and there is no way to bind a width or height attribute to it - it's not bindable.
    But I need to reduce or extend control to browser window. I rely on do this through wdDoModifyView method.

  • Dvt:pivotFilterBar - how to get selected values from filter

    Hi all,
    I have a question: how to programmatically get selected values from pivot table's filter bar?
    I have tried to use
    pivotTable.getDataModel().getDataAccess().getValueQDR(startRow, startCol, DataAccess.QDR_WITH_PAGE);but for page edge dimensions it returns BAD DATA, it seems that it returns some cached values.
    Environment: JDev 11.1.1.3.0 without any patches.
    thanks,
    Miroslaw

    Hi,
    You can retrieve the selected value in the PivotFilterBar through the model of PivotFilterBar, instead of dataaccess:
    // get the model from the pivot filter bar instance
    QueryDescriptior queryDescriptor = (QueryDescriptor)pivotFilterBar.getValue();
    // retrieve a list of criterion, each one is used to populate each lov within the pivot filter bar
    ConjunctionCriterion conjunctionCriterion = queryDescriptor.getConjunctionCriterion();
    List<Criterion> criterionList = conjunctionCriterion.getCriterionList();
    for (int i=0; i<_criterionList.size(); i++) {
    AttributeCriterion criterion = (AttributeCriterion)criterionList.get(i);
    // _selected is the currently selected value
    Object selected = criterion.getValues().get(0);
    System.out.println(_selected);
    Hope that helps,
    Chadwick

  • How can I get the size of a file with apple script

    I try to get the size of a file within an apple script. But I did not find information how to do this.

    There are two ways. I think Apple is moving toward using System Events, which is listed first.tell application "Finder"
    set myFile to selection as alias
    --this just gets a file for me to work with
    --coercing it into an alias is required for the other functions
    end tell
    tell application "System Events"
    get size of myFile
    end tell
    set myInfo to (info for myFile)
    get size of myInfo

  • How can I get the old CS3 pixel aspects into CS5

    Hello,
    i'm trying to get the old cs3 pixel aspect ratio into cs5. I don't need the hyper-correct- BBC 1.4587 for DV widescreen which leads to black bars left and right if I import HD footage into a SD widescreen timeline. Or if I export a HD timeline to Encore and downconvert to a SD PAL DVD - black bars...
    I have asked the adobe support, and they told me to change the Interpretation Rules.txt. But they have no further knowledge about these entries.
    For AfterEffect I found this solution: http://forums.adobe.com/message/3016005#3016005
    But I need it also for Premiere and Encore. Photoshop will be fine, but this is no must.
    What I Have tried so far:
    - changing the interpretation rules.txt from ... 768/702... to ..768/720  -> doesn't change anything
    - I copiued the whole interpretation rules.txt from Premiere CS3  -> doesn't change anything
    - I deleted the interpretatio rules.txt and reboot premiere -> doesn't change anything and premiere don't ask for the missing file.
    now I think that the interpretation rules.txt is not the right place to change the Pixel aspect ratio.
    can anybody help me? Is there a patch, which change all these settings in the whole cs5 production bundle...
    thanks a lot
    Johannes
    btw: sorry for my bad englisch

    Hi J-MS
    of course is PP interpreting my footage very well in terms of the cs5 PAR. but I want the PAR of CS3 becouse of the black bars left and right.
    One example step by step:
    - I render an AE Comp in 1920x1080
    - import that into premiere and create a HD timeline which fits perfectly to the footage
    - send this to Encore and create a PAL DVD
    ---> now you will find these ugly bars left and right
    the same if you put the 1920x1080 (that is truly 16/9) in a dv Pal widescreen timeline in premiere ( since CS4 with the PAR of 1.4587). right-click on scale to frame size. and again the black bars!
    For me, the old PAR 1.422 and 1.06 worked really fine and there for I try to get them back. and I know that I'm not the only one..

  • Selection  problem (No pixels are more than 50% selected)

    whenever I use ANy selction tool I get this message: No pixels are more than 50% selected. So I can't do anything to separate area of a photo. BTW, magic selection works. this just started a week ago after years of never seeing this message. Thanks for the help.

    Quit the editor (quit PSE if you have a mac), then restart it while holding down ctrl+alt+shift command+option+shift for a mac). Keep holding the keys till you see a window asking if you want to delete the settings file. You do.

  • How to get the size of partition?

    The following SQL will get the rows of the fact table & aggregation. But how to get the size (MB) of the partition. select * from $system.discover_partition_stat That should be doable, because in BIDS, we can see the size of a partition, but from which
    view we can do that?

    This is the best bet you have SELECT * FROM SystemRestrictSchema($system.discover_partition_stat ,DATABASE_NAME = 'Adventure Works DW' ,CUBE_NAME = 'Adventure Works' ,MEASURE_GROUP_NAME = 'Internet Sales' ,PARTITION_NAME = 'Internet_Sales_2003') Refer
    this article: http://geekswithblogs.net/darrengosbell/archive/2008/12/02/ssas-are-my-aggregations-processed.aspxvinu

  • Bug in the table selection size

    An annoying bug in Table controls (LV 8.5/Windows XP/ MacOS 10.5)
    When dealing with whole rows/colums (click in the row/column header), the Table Selection Size is always wrong :
    when columns are selected, the overall table size is returned,
    when rows are selected, the right row number is returned, but the column number is set to 1 !..
    The attached vi shows the problem.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Table select bug.vi ‏17 KB

    Since this bug was a showstopper for my application, I spent some time trying to find a workaround...
    Found one by accident. I don't understand why it works : it should not do anything :
    Detect a mouseUp event in the row/column headers, then read the Selection start position and write it back in the... Selection start position (ie : do nothing) ! That's enough to get the right value out of the Selection size...
    The attached vi illustrate the above story.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Table select bug.vi ‏28 KB

  • How to get the size of the blob file uploaded ?

    Hi ,
    Is there anyway to get the size of the file i have uploaded to a blob type attribute ?
    What i can see is that when we upload a file in contributor UI ,once the file is uploaded successfully and if we hover on it , it will show the filename , type and size of the uploaded file .
    From where can we get that details so that we can reuse these details in our code ?
    Thanks and Regards,
    Praveen

    A filter is a sensible solution, or you can get it in a roundabout way like this for example if you have the blobid (this is paraphrased from OpenMarket/Gator/AttributeTypes/IMAGEPICKERShowImages.jsp):
    <ics:sql sql='<%="select urldata,filevalue from MungoBlobs where id=" + ics.GetVar("blobid")%>' listname="blobdata" table="MungoBlobs" />
    <ics:listget listname="blobdata" fieldname="urldata" output="urldata" />
    <ics:setvar name="blobpath" value='<%=ics.GetProperty("cc.urlattrpath", "gator.ini", true) + ics.GetVar("urldata")%>' />
    <%
    File blobFile = new File(ics.GetVar("blobpath"));
    long length = blobFile.length();
    %>
    Phil
    Message was edited by: pgleghorn

  • Let me know to get Select certified partnership.

    Hello Team,
    I've certified CCNA & CCNP and it'll expires on 2015 Nov. Now I want to know the formalities to get select certified partnership. Here we have a small business institution and planing to operate a service with Cisco. Let me know the procedures to get Cisco partnership. Hope you will expedite..
    Rgds,
    Joe

    Look at Re: SAPgui window size (+)
    Regards

  • When I try to print a photo downloaded from Facebook in iPhoto, I can't get the size I specify to print correctly. Example: 5x7 prints smaller than 5x7. What do I do to solve this problem?

    When I try to print a photo downloaded from Facebook in iPhoto, I can't get the size I specify to print correctly. Example: 5x7 prints smaller than 5x7. What do I do to solve this problem?

    Those pixel dimemsions have aspect ratios that are not the same as a 5 x7 print:
    1360 x 1360 = 1.0
    790 x 640 = 1.23
    2048 x 1366 = 1.5
    An 7 x 5 image = 1.4.
    So you'll need to crop the images to 5 x 7 before printing.  The first two images are a little light in the pixels to produce a high resolution 5 x 7 print. 
    Happy Holidays

  • Get the size of the table as per row wise.( Rows in group by clause)

    Hello,
    I am using ORACLE 11g Standard edition and RHEL 4.
    I have a situation in which i want to know the size of the limited rows of the table.
    I am moving table's rows from one table(one tablespace) to another table(another tablespace) While moving the rows I want to be sure that the size of the rows is good enough to fit in the another table's tablespace free size. So before inserting rows in another table i will check the size of rows and the free space in tablespace and perform the action as per.
    Here is the senario with example :-
    I have a table called MAIN_TAB which has a column as DATE_TIME which stores the systimestamp when the data was inserted. See the code below ...
    select * from main_tab;
    ID     VALUE DATE_TIME
    1     DATA      18-MAY-11 12.00.00.000000000 AM
    2     DATA      18-MAY-11 12.00.00.000000000 AM
    3     DATA      17-MAY-11 12.00.00.000000000 AM
    4     DATA      17-MAY-11 12.00.00.000000000 AM Now i will fire a group by date_time query to know how many rows for each systimestamp.
    select trunc(date_time),count(id)
    from MAIN_TAB
    group by trunc(date_time)
    DATE_TIME     COUNT(ID)
    17-MAY-11               2
    18-MAY-11               2So now you can see i have 2 rows for 17th and 18th May. I want to know what is the size of the data for 17th and 18th May in MB. I know how to get the size of the whole table but i want only the limited rows size as per date.
    So the question is how can i get the size of a table's 2 rows data ???
    Provide me some guidance.
    If the question is not clear to you , let me know ....
    Thanks in advance ...

    Thanks Pravan for your reply. But Its still not so usefull for me. Can you please give some clear idea about what you wanna say ??
    I fired the DBA_TABLES view for my table i.e. 'MAIN_TAB' The AGV_ROW_LEN column showed 0 but that does not mean that my table has no data it, for sure it has 4 rows in it and consists of some data . . . . .
    Please clarify what i can do to get the size of rows related to that particular date ......
    thanks.

  • Query for  to get  database size, used size, freesize, db size after drop

    Pls give me a query for to get database size, used size, freesize, tablespacesize of sometables which is starting with 'RQ%'
    I have to get result like this
    Total size, used size, free size ,tablespace size of RQ tables alone
    Reason why i go for "tablespace size of RQ tables" i want to know the size of database after deleting the rq tables
    Pls reply
    S

    i tried with
    SELECT
    --fs.tablespace_name name,
    df.totalspace/1024/1024 mbytes,
    (df.totalspace - fs.freespace)/1024/1024 used,
    fs.freespace/1024/1024 free
    FROM
    (SELECT
    --tablespace_name,
    ROUND(SUM(bytes)) TotalSpace
    FROM
    dba_data_files
    ) df,
    (SELECT
    --tablespace_name,
    ROUND(SUM(bytes)) FreeSpace
    FROM
    dba_free_space
    ) fs
    i AM GETTING total bytes, used bytes, free bytes
    I WANT TO include one more column.. database size after deleting rq tables
    Pls reply
    S
    Edited by: AswinGousalya on Jul 10, 2009 2:17 PM

  • Getting the size of a jpeg image

    Hello,
    I'm looking for a way to get the size (height and width in
    pixel) of a jpeg file before actually loading the file.
    Is it possible ?
    Thanx.
    Vincent

    This is a flaw in Pages IMHO.
    As for many things the information and manipulating the properties is oblique to say the least.
    You have to do what you have done or do some calculations based on size, and known resolution.
    A way around might be to tag the image in the name with the actual pixel size.
    I work from my images marked in folders as vLoRes, LoRes, MedRes, HiRes, vHiRes and uHiRes.
    Given a basic requirement of a bare minimum 100 pixels/cm (roughly 254dpi) for commercial reproduction the images will cover (with bleed):
    vLoRes = A7
    LoRes = A6
    MedRes = A5
    HiRes = A4
    vHiRes = A3
    uHiRes = beyond A3
    But then I happen to be very systematic in the way I work. It is a useful skill I have taught in my studios. Unfortunately many designers, and users in general, are sloppy and short sighted.
    Peter

Maybe you are looking for

  • How do I re-establish a single virtual monitor across two 30" screens?

    How do I re-establish a single virtual monitor across two 30" screens? The fact that the screens are now separate with two menu bars, and the inability for images to appear across both of them is a great inconvenience to me. I have used this system s

  • Use of URL in Smartforms

    HI all, I've downloaded the output of a smartform in PDF format. In the layout i've inserted URL for a text element. My requirement is, when user clicks the text, it's to link with one more transaction. How to do the same? Expecting reply...Urgent

  • Gray toolbar items at top of Safari 5.0.2 are gone

    On Safari 5.0.2, I suddenly had all the top toolbar (gray) empty when I launched Safari this morning.. I managed to get back the address bar, the Google search field, and some buttons. But I am still missing my "favorites" from the Bookmarks, which u

  • Is there an up to date manual for iMovie 10.01?

    I'm a first time Mac user looking to use iMovie.   The on-line help manual provided appears to be out of date.   Does a 2013 / 2014 manual / tutorial exist?

  • Business Objects TO OBI conversion

    Hi, We are planning to convert Business Objects to OBI( reporting). We are new to OBI. Let me know how can we proceed Please advice!! Cheers..