How to calculate actual selection or group width and height with clipping

If a group has clipping paths then the height and visible bounds will include the dimensions of all paths selected including the clipped or hidden paths.
However, the width and height shown on the width and height of the AI detail boxes for the selection shows just the visible dimensions.
I want to retrieve the same values that is shown on the screen when a group is selected.
It is somewhat counterintuitive that the "visiblebounds" property does not show just what is visible.
I'm scaling the visible content of a selection to fit within another path but I need to be able to calculate the dimensions of the only what is visible after clipping.
What do you have to do with scripting to get these values? Go through all of the path items in a group recursively and save the min and max values of any visiblebounds for clipping paths? Any better alternatives that I don't see?
Thanks for any help!

I ended up using the visible bounds for both scale and position as I also discovered that attempting to position a group with the position method would also result in missing the mark. The top and left (x,y) bounds I calculated without the clipped dimensions needed to be used to offset the actual position where I wanted the visible paths to be displayed.
The functions I used ended up looking like so:
function GetPoints(dblInch)
     var dpi = 72;
     return dblInch * dpi;
function getRealVisibleBounds(grp) {
     var outerBounds = [];
     for(var i = grp.pageItems.length - 1; i >= 0;i--)  {
          var bounds = [];
          if(grp.pageItems[i].typename == 'GroupItem') {
               bounds =  getRealVisibleBounds(grp.pageItems[i]);
          else if((grp.pageItems[i].typename == 'PathItem' || grp.pageItems[i].typename == 'CompoundPathItem')
               && (grp.pageItems[i].clipping || !grp.clipped)) {
               bounds = grp.pageItems[i].visibleBounds;
          if (bounds.length > 0) {
               outerBounds = maxBounds(outerBounds,bounds);
     return (outerBounds.length == 0) ? null : outerBounds;
function positionVisible(grp,x,y)
     var bounds = getRealVisibleBounds(grp);
     var newX = GetPoints(x) + (grp.left - bounds[0]);
     var newY = GetPoints(y) + (grp.top - bounds[1]);
     grp.position = [newX,newY];
function maxBounds(ary1,ary2) {
     var res = [];
     if(ary1.length == 0)
          res = ary2;
     else if(ary2.length == 0)
          res = ary1;
     else {
          res[0] = Math.min(ary1[0],ary2[0]);
          res[1] = Math.max(ary1[1],ary2[1]);
          res[2] = Math.max(ary1[2],ary2[2]);
          res[3] = Math.min(ary1[3],ary2[3]);
     return res;
and were called like so:
var doc = app.activeDocument;
if (doc.selection.length > 0) {
     var grpOriginal = null;
     if(doc.selection.length == 1 && doc.selection[0].typename == 'GroupItem') {
          grpOriginal = doc.selection[0];
     else {
          grpOriginal = doc.groupItems.add();
     doc.selection = null;
     if(grpOriginal.layer.name != 'approval') {
          grpOriginal.move(doc.layers['approval'],ElementPlacement.PLACEATEND);
     var artBounds = getRealVisibleBounds (grpOriginal);
     var artWidth = artBounds[2] - artBounds[0];
     var artHeight = artBounds[1] - artBounds[3];
     var imprintHeight = GetPoints(0.625);       // 0.625 is new height, hardcoded for demonstration
     var imprintRatio = imprintHeight / artHeight;
     var section = doc.layers['sectionLeft'];    // section where I placed the art
     var grpArt = grpOriginal.duplicate(section,ElementPlacement.PLACEATEND);
     grpArt.resize(100.0 * imprintRatio,100.0 * imprintRatio);
     grpArt.move(section,ElementPlacement.PLACEATBEGINNING);
     grpArt.selected = true;
     positionVisible(grpArt,0.0,16.75);          // x & y hardcoded for demonstration
else {
     alert('artwork needs to be selected');
I'm new at this so are there any better options to do these things?

Similar Messages

  • Current page (not Document) width and height with JSX

    Hi,
    I am trying to create a script that saves every page of the document and add its width and height to the name.
    So far I managed to get the dimensions of the document using:
    app.activeDocument.pages.documentPreferences.pageWidth;
    app.activeDocument.pages.documentPreferences.pageHeight;
    That's ok when all the pages in the document have the same dimensions (Document Preferences).
    However, when I use custom pages that does not work.
    I tried the code below but does not work either.
    for(i=0; i<nb;i++)
         app.activeDocument.pages[i].documentPreferences.pageWidth;
         app.activeDocument.pages[i].documentPreferences.pageHeight;
    I have done some research and I don't seem to find any information regarding custom pages dimensions.
    Can you please help with this?
    Thanks in advance,
    Isko

    Main();
    function Main() {
        var doc = app.activeDocument,
        pages = doc.pages,
        page, width, height;
        for (var i = 0; i < pages.length; i++) {
            page = pages[i];
            width = page.bounds[3] - page.bounds[1];
            height = page.bounds[2] - page.bounds[0];
            $.writeln("Page: " + page.name + " - " + "width = " + width + ", height = " + height);

  • Rotating and scaling a movieclip withing only its parent width and height

    Dear friends,
    I'd like to rotate a movieclip within specific area (its parent width and height) and it can't rotate out of it.
    How can I achieve that.
    When I say for exampe:
    mc.rotation = 10;
    it rotates also outside the parent area.
    How can I restrict it to only parent area.
    Thank you in advance.

    [OTTOMH]
    With each rotation step you could check the bounds of the rotating MC. If it's greater than the containing MC, you can calculate the scale factor and apply it to the x- and y-scale of the rotating clip.
    The clip would have to be deadcentre in the containing clip for this to work though.
    I suppose there would be some mathimatical way with most primitive shapes to calculate the width and height with a certain rotation, but I suppose this would be easiest.

  • Scripting TGetProperty width and height

    Hello all,
    i have a problem with the flash player in IE6 and FF2.
    I have a html page with some flash movie elements on it.
    I'm using SWFObject to bind the movies in.
    After the onload event is fired, for each flash movie the
    javascript function setCorrectSize4Flash will be called to resize
    the html container element (embed, object tag) automatically by the
    given width and height of the flash movie.
    Therefore i'm checking if the movie is completely loaded and
    if width and height is not undefined.
    So if i'm getting width and height, i'm resizing the
    container element to best fit in.
    My problem is now, that the same movie used several times in
    the same html page has every time different width and height
    values. Sometimes the aspect ratio is 1:2 and sometimes it's 2:1.
    Is this a problem of the flash player plugin or am i doing
    something wrong.
    Best regards,
    bartmark

    Thank you for your answer. But I don't understand:
    The question is not the margin. I put in the body margin: 0; padding:0; and there is no margin.
    I want to know the viewport:   the width and height with the iPad in horizontal position and without the address bar.
    This does not coincide with the 1024 x 768. (nor the 946 x 768 if I rest the address bar).  I don't understand why
    Thank you
    Narcís

  • How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, how do I select the first and last message and delete everything in between?

    How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.

    I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
    Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
    I'm astounded that there's so little support for such a common issue for which people have been asking for years.

  • How to get the width and height of the selected rectangle

    Hi,
         I need to get the width and height of the selected rectangle in indesign cs3 and display the values in a dialog box for user verification.
    Regards,
    saran

    Hi Saran,
    InterfacePtr<IGeometry> itemGeo ( objectUIDRef, UseDefaultIID() );
    PMRect ItemCoord = itemGeo->GetStrokeBoundingBox();
    PMReal width  = ItemCoord->Width();
    PMReal height = ItemCoord->Height();

  • How do I save the width and height of a photo for repeated use?

    How do I save the width and height of a picture for repeated use, rather than having to enter it each time in the 'new file' box?
    Thanks,  Ed Jackson.

    It could be that I'm older and have forgotten. I'm now 73 and will admit I have forgotten many things over the years. I have been using Photoshop since Photoshop version 3.  And can not really recall which features or changes were made in ever version of Photoshop I have installed.  Adobe has added many features over the years. The number of bugs introduce has also greatly increased after CS3.  "New Doc Sizes.psp"  in your user id preferences is edited using the two buttons in the new document dialog.
    As for guide lines in new documents Photoshop CS6 or CC seem to add some for video file presets with guide lines.  I do not know how to edit or add guide line to new doc presets. Guide line actions are easy to create. I have also seem some guideline in new documents when I did not expect any perhaps a new bug. Photoshop like most software has bugs. If you do not see Adobe new presets perhaps you copied an old  "New Doc Sizes.psp"  over Adobe's newer default file or Adobe migrared you presets and wand wiped their presets out. There are bugs. Close Photoshop down and rename your current  "New Doc Sizes.psp"  in you user id Photoshop cc preferences folder and start Photoshop it will add a dedault  "New Doc Sizes.psp"  file see if you see Adobe new presets in the new doc pull down when you select video and film...

  • How do you create aligned interactive text boxs in a PDF with the same width and height?

    how do you create aligned interactive text boxs in a PDF with the same width and height?
    Without free hand creating the sizing?

    Assuming by "interactive text boxes" you mean form fields; in Acrobat, make a form field, then copy it and paste. (GIve the pasted copy a different name so they don't genetate the same field feedback.) Now you have two fields of the exact same size. Shift-click or marquee-drag to select both, then right-click and choose a command from the Align, Distribute or Center menu.

  • How can I deploy EFS using Group Policy and automatically encrypt computers for ALL users who login?

    How can I deploy EFS using Group Policy and Active Directory with a goal to automatically encrypt computers for ALL users who login? (NOT an option for me to use BitLocker)
    I was asked to deploy EFS to encrypt the user my documents folder and profile on all of the users laptops. The laptops are in common areas (board meeting rooms, etc) and security of files is a must.
    I successfully created a recovery certificate in AD. I created an OU and setup an EFS policy and users can now login and select to encrypt their own files. The issue is that management would like to have automaticy Encrypt ALL users my documents AUTOMATICALLY
    when a user login.
    Can this be done?
    Please help

    Hi,
    Any update?
    Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.
    Best Regards,
    Andy Qi
    TechNet Subscriber Support
    If you are
    TechNet Subscription user and have any feedback on our support quality, please send your feedback
    here.
    Andy Qi
    TechNet Community Support

  • How to create a map that is larger than the game in width and height?

    hi,
    i wounder how i can create a map(not the design) that is larger than the game in width and height, part of it will appear in the main page and anther part you can move to it after you press the arrow symbol, but the map is just one image so i want put it in line and out line the game page, and the out line part includes buttons and symbols the player can use, but it will be in line and the other part will be out line when you press the left arrow or the down arrow, how i can do that?
    and is that possible to animate it so when the player press the arrow, will give it action to start the animation in one sec, i know how to animate it if that possible but i don't know which code i will use for the mouse click with the arrow symbol, and how to use the same code in the same symbol to start anther animation depending on which part of the map is on?

    I don't know a lot about mask and masked layers and how to work with the normal layers beside i will use some 3D graphics but not in the background, i will explain all this to you to be more clearly.
    first i am using action script 3.0
    close ex,
    you have 2d map"image"  900*300 pixel.
    this image contains some 2d symbols when you click will go to anther normal map (anther normal layer) so they must appear.
    your game 320*320 px, and the place the map will show on 300*300, and there's basics objects will be in most pages including the page that show the map so i don't know a lot about how this will work with mask layers.
    so you can only see the left side of the map image and what it contains, while there's two arrows one to the left and one to the right there's three cases here,
    first when it show the left side(start from x:0 to x:300), the left arrow will not active when you press and the right arrow will start an animation that make the map image move to the mid side in one sec when you press.
    in mid side (start from x:301 to x:600) the same left arrow will active when you press to send you back to the left side while the same right arrow will be active to send you not to the mid side but to the right side,
    when moved to the right side the same left arrow will be active to send you to the mid and the right will not active when you press and depending on that,
    first how to make the large image appear with the three sides in the same place without effecting the other objects "like disappearing them" ?
    and the codes i need in the same left or right arrow symbol to make different actions with the same symbol when clicked depending on which part of the map is on.

  • How to handle multiple selection in the Spark List control with checkbox as itemrenderer?

    Hi All,
    I am using checkbox as an ItemRenderer in spark list.
    I have a query.
    how to handle multiple selection in the Spark List control with checkbox as itemrenderer?
    how to retrieve the selected item label?
    Thank you in advance.

    Hi there, I'll tweak your code a little bit to something like this:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="vertical">
        <mx:Script>
            <![CDATA[
                 import mx.events.ListEvent;
                 import mx.controls.CheckBox;
               [Bindable]
               private var mySelectedIndexes:ArrayCollection=new ArrayCollection();
                private function onChange(e:ListEvent):void
                   if(CheckBox(e.itemRenderer).selected){
                             mySelectedIndexes.addItem(e.rowIndex);
                   }else{
                                  mySelectedIndexes.removeItemAt(mySelectedIndexes.getItemIndex(e.rowIndex));     
                   chkList.selectedIndices=mySelectedIndexes.toArray();
            ]]>
        </mx:Script>
    <mx:ArrayCollection id="collection">
            <mx:Object label="Test A"/>
            <mx:Object label="Test B"/>
            <mx:Object label="Test C"/>
            <mx:Object label="Test D"/>
            <mx:Object label="Test E"/>
            <mx:Object label="Test F"/>
            <mx:Object label="Test G"/>
        </mx:ArrayCollection>
    <mx:List id="chkList" dataProvider="{collection}" itemRenderer="mx.controls.CheckBox"  itemClick="onChange(event);" allowMultipleSelection="true"/>
    </mx:Application>

  • How can I get the image width and height stored in database?

    Hi!I write s servlet to display images store in database.but how can I get the image width and height?

    Have you tryed using PJA or a similar library?
    I presume you get java.lang.NoClassDefFoundError on the line :
    Toolkit.getDefaultToolkit();?

  • How to set a minimum width and height for a stage or scene?

    Hello,
    Does anyone how to set a minimum width and height for a stage or scene?
    I tried listening for width/height property value changes and then adjust the width/height if necessary, but that causes unpleasant flickering of the window.
    In JavaFX 2.1 beta SDK for Mac OS, the Stage class has setMinWidth() and setMinHeight() functions which work very well.
    I'm wondering what's the equivalent way to do that when using the FX SDK for Windows.
    Any help is appreciated!
    Thanks.

    I was wondering how to enforce a minimum stage size with JavaFX 2.0.3.The same flickering way you are currently doing it. See: http://javafx-jira.kenai.com/browse/RT-15200 "Need a way to set the minimum size of a window"

  • How to set field width and height at runtime programatically?

    Hi all,
    I want to set the width and height of a report field by reading its values from the database table.
    Is it possible in Oracle reports?
    How to achieve this in Oracle reports 10g?
    Any help will be highly appreciated.
    Thanks .... Best Regards
    Bilal

    You cannot give it a specific value. During design you can set Horizontal and Vertical Elasticity properties to Variable, so the items are automatically scaled when running the report.

  • Excel 2007. OLAP pivot. How do you resize dropdown width and height?

    Excel 2007. OLAP pivot. How do you resize dropdown width and height?

    hi,
    I'm afraid we can't modify that property in Excel. Someone had suggested to use a custom combo box to replace the built-in drop-down. However it will lose the features which are only available
    for built-in drop-down.
    Hope this
    thread will give you some ideas. Thank you.

Maybe you are looking for