You must be logged in to post Login

Search Forums:


 






Resize graphic frames with an Object style applied

UserPost

3:39 am
September 21, 2011


Mike Agate

Community Member

posts 8

Hi all

My scripting's not great, hoping someone can help?

I need to search my document for graphic frames that have the Object style 'CarImage' applied and resize those frames to 26mm wide by 13mm high (using top left as the reference). I don't need to scale the content, just resize the frames.

All help much appreciated.

Mike

6:47 am
September 21, 2011


David Blatner

Admin

posts 823

This isn't exactly the same, but check out the tomaxxiResizeEach script:

http://tomaxxi.com/downloads/

co-host, InDesignSecrets.com

8:22 am
September 21, 2011


Mike Agate

Community Member

posts 8

Thanks David – that's cool but not quite it. It's a doc of over 100pp – I can find all the objects I need and apply an object style to them, but can't then resize them. (It's a template change of a long doc to a new page size).

Cheers

Mike

4:20 am
September 27, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Main();

function Main() {
    if (app.documents.length > 0) {
        var doc = app.activeDocument;
        var objStyle = doc.objectStyles.item("CarImage");
        if (objStyle.isValid) {
            doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            
            var objPref = app.findObjectPreferences;
            objPref.appliedObjectStyles = objStyle;
            var found = doc.findObject();
            
            for (var i = 0; i < found.length; i++) {
                frame = found[i];
                gb = frame.geometricBounds;
                gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];
                frame.geometricBounds = gb_new;
            }
        }
        else {
            alert("Object style "CarImage" doesn't exist");
        }
    }
    else {
        alert("No open documents.");
    }
}

4:21 am
September 27, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Forgot to add var in the following lines:

var frame = found[i];
var gb = frame.geometricBounds;
var gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];

4:25 am
September 27, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Oops! My fingers work faster than my brain. Unfortunately I can't edit the post!

Here's a new version:

Main();

function Main() {
    var frame, gb, gb_new;
    if (app.documents.length > 0) {
        var doc = app.activeDocument;
        var objStyle = doc.objectStyles.item("CarImage");
        if (objStyle.isValid) {
            doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            
            var objPref = app.findObjectPreferences;
            objPref.appliedObjectStyles = objStyle;
            var found = doc.findObject();
            
            for (var i = 0; i < found.length; i++) {
                frame = found[i];
                gb = frame.geometricBounds;
                gb_new = [ gb[0], gb[1], gb[0]+13, gb[1]+26 ];
                frame.geometricBounds = gb_new;
            }
        }
        else {
            alert("Object style "CarImage" doesn't exist");
        }
    }
    else {
        alert("No open documents.");
    }
}

9:04 am
September 27, 2011


David Blatner

Admin

posts 823

Thanks, Kasyan! Cool. Sorry… we are working on a new forum and site software, and one of the things we will definitely try to do is allow people to edit their own posts!

co-host, InDesignSecrets.com

10:42 am
September 27, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Hi Dave,

I have a suggestion: the new forum software should provide for possibility to post code. In the code I posted, backslashes have been removed before the quotes surrounding the CarImage in the line 24, which will result in error in case the object style doesn't exist in the document.

The line should have been be like so:

alert("Object style [backslash]"CarImage[backslash]" doesn't exist");

Formerly I tried to enclose the code in

tag in the HTML source editor, but this didn't help.

Regards,
Kasyan


5:36 am
September 28, 2011


Mike Agate

Community Member

posts 8

Hi Kasyan, thanks for your help on this.


It's giving me:

Error Number: 55

Error String: Object does not support the property or method 'isValid'

Line: 8

Source: if (objStyle.isValid) {


Make any sense?

Mike


8:01 am
September 28, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Hi Mike,

What version of InDesign are you on? I guess you're on CS3.

It's always a good idea to specify the InDesign version and the platform — Mac or PC — for which you want the script.


Let's try to replace

if (objStyle.isValid) {

with

if (objStyle != null) {

to make it compatible with CS3.


Regards,
Kasyan


8:16 am
September 28, 2011


Mike Agate

Community Member

posts 8

Genius, that works a charm – great script.

Thanks a million for taking time to help and will be sure to include version number next time.


Cheers my friend

Mike

10:31 am
September 30, 2011


Chuckie

Bainbridge Island, WA

Member

posts 37

This is a pretty good thread.  And another reason why — maybe with our new ID Secrets website coming — we should have an ID wishlist portal.  

Because if Adobe's listening here … Object Styles should also contain geometry that include X,Y position, proxy & X,Y proportion, maybe even scaling percentage would be nice.

Talk about efficiency.  This is a cross-court winner.  Obj Styles could contain it, but even BETTER would be Object Tags in which values relating to print & digital media are tagged & controlled by the text frame attributes themselves.  

As InDesign begins to merge print with digital platform export, there are huge advantages here.


2 cents …

5:35 am
November 23, 2011


Mike Agate

Community Member

posts 8

Hi Kasyan

Thanks again for sorting this – I had it working, but now when I run it it seems to do nothing – code below. Any thoughts at all? All help appreciated. Running InDesign CS3.

Mike


Main();

function Main() {
    var frame, gb, gb_new;
    if (app.documents.length > 0) {
        var doc = app.activeDocument;
        var objStyle = doc.objectStyles.item("Review Pic Box Stroked");
        if (objStyle != null) {
            doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
            
            var objPref = app.findObjectPreferences;
            objPref.appliedObjectStyles = objStyle;
            var found = doc.findObject();
            
            for (var i = 0; i < found.length; i++) {
                frame = found[i];
                gb = frame.geometricBounds;
                gb_new = [ gb[0], gb[1], gb[0]+39.25, gb[1]+24 ];
                frame.geometricBounds = gb_new;
            }
        }
        else {
            alert("Object style "Review Pic Box Stroked" doesn't exist");
        }
    }
    else {
        alert("No open documents.");
    }
}

12:04 am
November 24, 2011


Kasyan Servetsky

Kiev, Ukraine

Member

posts 65

Hi Mike,

Try to add this line:

app.findChangeObjectOptions.objectType = ObjectTypes.GRAPHIC_FRAMES_TYPE;

It corresponds to the "Type: Graphic Frame" option in the "Object" tab of the "Fing/Change" dialog box. Most probably it is set to a wrong type e.g. "Text Frame" at the moment and the script finds nothing.

Hope this helps.

Kasyan

8:27 am
November 24, 2011


Mike Agate

Community Member

posts 8

You're a lifesaver, thanks Kasyan.

If you ever need Filemaker Pro help, please do shout.

All the best

Mike


7:11 am
April 25, 2012


Chuckie

Bainbridge Island, WA

Member

posts 37

A twist down memory lane on this.


Can this script be modified to specify layer and scale the layer's elements by percentage?