4 Replies Latest reply on Oct 13, 2008 9:58 PM by (charles_darwin)

    [CS2][JS] How to scale all inline images to 70%

    Level 1
      To all the script gurus out there. can you help me make a script that scale all inline images to 70%? 'coz we got this client and they supply us with lots of eps files then the instruction would be to reduce the size of all images without touching the original ones. it takes time to process all of them in indesign manually.
      help please.
        • 1. Re: [CS2][JS] How to scale all inline images to 70%
          Martin Fischer Level 2
          Hi charles,

          first you will have to distingish between images and inline images for you only want to modify inline images.

          Then you will reset the images to 100% before you will scale them to another value for the scaling values should be relative to 100% and not relative to another possible scaling value.

          Then scale to your value and fit the frame to content.

          Maybe you wish that only certain types of graphics are affected by this scaling.
          Therefore you will have to add an if-inquiry for the type of graphic.


          var aFactor = 70/100;
          for ( var s = 0; s < app.activeDocument.stories.length; s++ )
          {
          for ( var g = 0; g < app.activeDocument.stories[s].allGraphics.length; g++ )
          {
            app.activeDocument.stories[s].allGraphics[g].horizontalScale =
             app.activeDocument.stories[s].allGraphics[g].verticalScale = 100; // reset to 100%
            app.activeDocument.stories[s].allGraphics[g].absoluteHorizontalScale =
             app.activeDocument.stories[s].allGraphics[g].horizontalScale * aFactor;
            app.activeDocument.stories[s].allGraphics[g].absoluteVerticalScale =
             app.activeDocument.stories[s].allGraphics[g].absoluteVerticalScale * aFactor;
            app.activeDocument.stories[s].allGraphics[g].fit(FitOptions.FRAME_TO_CONTENT);
          }
          }


          Martin
          • 2. Re: [CS2][JS] How to scale all inline images to 70%
            Level 1
            shouldn't be:

            (...).absoluteHorizontalScale = (...).absoluteHorizontalScale * aFactor;

            robin

            --
            www.adobescripts.com
            • 3. Re: [CS2][JS] How to scale all inline images to 70%
              Martin Fischer Level 2
              Robin,

              you are right.

              In this context you shouldn't mix horizontalScale and absoluteHorizontalScale.
              You should decide your relation (graphic itself or containing object) and consequently use horizontalScale or absoluteHorizontalScale (verticalScale or absoluteVerticalScale) .

              Sorry for this mishmash above.

              Martin
              • 4. Re: [CS2][JS] How to scale all inline images to 70%
                Level 1
                Thank you so much guys. I'll try it later. Although I have one more problem. I got this LabelGraphics script from Indesignsecret.com modified for CS2 (originally from CS3), and it works fine for displayed figures but for inline it only labels the figures in first page.
                here's the code:

                //LabelGraphics.jsx

                main();

                //=============================================================\\
                function main(){
                if(app.documents.length != 0){
                if(app.documents.item(0).allGraphics.length != 0){
                myDisplayDialog();
                }
                else{
                alert("Document contains no graphics.");
                }
                }
                else{
                alert("Please open a document and try again.");
                }
                }

                //=============================================================\\
                function myDisplayDialog(){
                var myLabelWidth = 100;
                var myStyleNames = myGetParagraphStyleNames();
                var myDialog = app.dialogs.add({name:"Graphics name"});
                with(myDialog.dialogColumns.add()){
                //Label type
                with(dialogRows.add()){
                with(dialogColumns.add()){
                staticTexts.add({staticLabel:"Label Type", minWidth:myLabelWidth});
                }
                with(dialogColumns.add()){
                var myLabelTypeDropdown = dropdowns.add({stringList:["File name", "File path", "XMP description", "XMP author","Paste from clipboard"], selectedIndex:0});
                }
                }
                with(dialogRows.add()){
                with(dialogColumns.add()){
                staticTexts.add({staticLabel:"Label Offset", minWidth:myLabelWidth});
                }
                with(dialogColumns.add()){
                var myLabelOffsetField = measurementEditboxes.add({editValue:0});
                }
                }
                //Style to apply
                with(dialogRows.add()){
                with(dialogColumns.add()){
                staticTexts.add({staticLabel:"Label Style", minWidth:myLabelWidth});
                }
                with(dialogColumns.add()){
                var myLabelStyleDropdown = dropdowns.add({stringList:myStyleNames, selectedIndex:4});
                }
                }


                }

                //=============================================================\\
                var myResult = myDialog.show();
                if(myResult == true){
                var myLabelType = myLabelTypeDropdown.selectedIndex;
                var myLabelHeight = 24; // A generic label height that will be adjusted later
                myPasteFailure = false;
                var myLabelOffset = myLabelOffsetField.editValue;
                var myLabelStyle = myStyleNames[myLabelStyleDropdown.selectedIndex];
                myDialog.destroy();
                var myOldXUnits = app.documents.item(0).viewPreferences.horizontalMeasurementUnits;
                var myOldYUnits = app.documents.item(0).viewPreferences.verticalMeasurementUnits;
                app.documents.item(0).viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                app.documents.item(0).viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

                try{
                myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myLabelStyle);
                }
                catch(e){
                alert("Unable to add lables. " + e);
                }

                try{
                resizeOverset() ;
                }
                catch(e){
                alert("Unable to correct overset text. " + e);
                }

                if (myPasteFailure == true){
                alert("Unable to paste from clipboard.");
                }

                app.documents.item(0).viewPreferences.horizontalMeasurementUnits = myOldXUnits;
                app.documents.item(0).viewPreferences.verticalMeasurementUnits = myOldYUnits;
                }
                else{
                myDialog.destroy();
                }
                }

                //=============================================================\\
                function myAddLabels(myLabelType, myLabelHeight, myLabelOffset, myLabelStyleName){
                var myDocument = app.documents.item(0);
                myStoriesArray = new Array();

                if (app.selection.length == 0) // If nothing is selected apply caption to all graphics in the document
                {
                var myConfirmation = confirm("Add captions to all images in the document?", false, "LabelGraphics.jsx" );
                if (myConfirmation == true)
                {
                var myGraphics = myDocument.allGraphics;
                }
                }
                else
                { // If graphics are selected, just add captions to the selected items, as long as they are rectangles(image frames)
                var myConfirmation = true;
                var mySelections = app.selection;
                myGraphics = new Array();

                for(i = 0; i < mySelections.length; i++){
                if(mySelections[i] == "[object Rectangle]"){ //Check to make sure selection only includes rectangles
                myGraphics.push(mySelections[i].allGraphics[0]);
                }
                else{
                //alert("Objects other than graphics were selected!");
                //Nothing happens if you don't select at least one graphic
                }
                }
                }

                myLabelStyle = myDocument.paragraphStyles.item(myLabelStyleName);

                if (myConfirmation == true){
                for(var myCounter = 0; myCounter < myGraphics.length; myCounter++){
                try{
                myAddLabel(myDocument, myGraphics[myCounter], myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myStoriesArray);
                }
                catch(e){};
                }
                }
                }

                //=============================================================\\
                function myAddLabel(myDocument, myGraphic, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myStoriesArray){
                var myLabel;
                var myLink = myGraphic.itemLink;
                var myPasteFromClipboard = false;
                //Create the label layer if it does not already exist.
                var myLabelLayer = myDocument.layers.item("Grapiks");
                try{
                myLabelLayer.name;
                }
                catch (myError){
                myLabelLayer = myDocument.layers.add({name:"Grapiks"});
                }
                //Label type defines the text that goes in the label.
                switch(myLabelType){
                //File name
                case 0:
                myLabel = myLink.name;
                break;
                //File path
                case 1:
                myLabel = myLink.filePath;
                break;
                //XMP description
                case 2:
                try{
                myLabel = myLink.linkXmp.description;
                }
                catch(myError){
                myLabel = "No description available.";
                }
                break;
                //XMP author
                case 3:
                try{
                myLabel = myLink.linkXmp.author
                }
                catch(myError){
                myLabel = "No author available.";
                }
                break;
                //Paste from the clipboard
                case 4:
                try{
                myPasteFromClipboard = true;
                }
                catch(myError){
                myLabel = "No clipboard data available.";
                }
                break;
                }
                var myFrame = myGraphic.parent;
                myX1 = myFrame.geometricBounds[1];
                myY1 = myFrame.geometricBounds[2] + myLabelOffset;
                myX2 = myFrame.geometricBounds[3];
                myY2 = myY1 + myLabelHeight;

                if (myPasteFromClipboard ==true)
                {
                try{
                var myTextFrame = myFrame.parent.textFrames.add(myLabelLayer, undefined, undefined,{geometricBounds:[myY1, myX1, myY2, myX2]});
                myTextFrame.insertionPoints.item(0).select();
                app.paste();
                }
                catch(e){
                myTextFrame.remove();
                myPasteFailure = true;
                }
                }
                else{
                var myTextFrame = myFrame.parent.textFrames.add(myLabelLayer, undefined, undefined,{geometricBounds:[myY1, myX1, myY2, myX2], contents:myLabel});
                }

                myTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;
                myTextFrame.paragraphs.item(0).appliedParagraphStyle = myLabelStyle;


                myFrameParentStory = myTextFrame.parentStory;
                myStoriesArray.push(myFrameParentStory);

                }

                //=============================================================\\
                function myGetParagraphStyleNames(){
                var myStyleNames = app.documents.item(0).paragraphStyles.everyItem().name;
                return myStyleNames;
                }

                function resizeOverset() {
                for (var j = myStoriesArray.length - 1; j >= 0; j--) {
                myLastFrame = myStoriesArray[j].texts[0].parentTextFrames[myStoriesArray[j].texts[0].parentTextFrames.l ength - 1];

                myNewY2 = myLastFrame.geometricBounds[3]; //get the width of the text frame before doing fit()

                myLastFrame.fit(FitOptions.FRAME_TO_CONTENT);

                myNewY1 = myLastFrame.geometricBounds[1];
                myNewX1 = myLastFrame.geometricBounds[2];
                myNewX2 = myLastFrame.geometricBounds[0];

                }
                }