Skip to main content
gregd
Known Participant
March 7, 2024
Answered

How can I find/GREP objects that have been rotated?

  • March 7, 2024
  • 2 replies
  • 956 views

I want to search a document for objects that have been rotated by 1 to 5 degrees. How can I do this?

This topic has been closed for replies.
Correct answer m1b

Hi @gregd, I don't know how to do this from the normal UI, but since you tagged "scripting" here's a script I wrote to collect page items with a range of rotations. You can see in the script where I've set the range -5 to 5 degrees. The page items are collected in the array `myRotatedPageItems`.

 

I think you have done a bit of scripting... are you able to use this? Let me know if you need more help.

- Mark

 

/**
 * Collect Rotated Page Items.js
 * 
 * Example usage of `doSomethingToThings`
 * that collects page items having a
 * range of rotation.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-can-i-find-grep-objects-that-have-been-rotated/m-p/14474764
 */
function main() {

    // your items will be collected here
    var myRotatedPageItems = [],

        // adjust these to suit
        minRotationDegrees = -5,
        maxRotationDegrees = 5;

    // search every page item
    doSomethingToThings({
        target: app.activeDocument,
        thingPlural: 'pageItems',

        // collect rotated items
        doToThing: function collectRotatedItems(thing, doc) {

            if (
                undefined == thing
                || !thing.isValid
                || !thing.hasOwnProperty('rotationAngle')
                || 0 === thing.rotationAngle
            )
                return;

            if (
                thing.rotationAngle >= minRotationDegrees
                && thing.rotationAngle <= maxRotationDegrees
            )
                myRotatedPageItems.push(thing);

        },

    });

    alert('Collected ' + myRotatedPageItems.length + ' rotated page items.');

    // now you need to decide what to do with the rotation items!
    // -- your code here --

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Collect rotated items');


/**
 * Executes a function for every thing
 * in the document or documents.
 * `thingPlural` is a Document property name,
 * for example 'formFields' or 'swatches'.
 * @author m1b
 * @version 2024-02-29
 * @param {Object} options
 * @param {String} options.thingPlural - collective property of Document eg. 'checkBoxes'.
 * @param {Document|Documents} [options.target] - an Indesign Document or Documents (default: active document).
 * @param {Function} [options.doToDocument] - a function to be executed for each document (default: do nothing).
 * @param {Function} [options.doToThing] - a function to be executed for each thing (default: do nothing).
 */
function doSomethingToThings(options) {

    options = options || {};

    var doc = options.target || app.activeDocument,
        thingPlural = options.thingPlural,
        doToDocument = options.doToDocument,
        doToThing = options.doToThing;

    if ('Documents' === doc.constructor.name) {

        for (var i = 0; i < doc.length; i++) {
            options.target = doc[i];
            doSomethingToThings(options);
        }

        return;

    }

    // do something to document
    if (undefined != doToDocument)
        if (!doToDocument(doc))
            return;

    var things = getThingsFromDocument(doc, thingPlural) || [];

    // do something to things
    for (var i = things.length - 1; i >= 0; i--)
        if (undefined != doToThing)
            doToThing(things[i], doc);

};


/**
 * Returns array of things found in `doc`.
 * `thingPlural` is a Document property name,
 * for example 'formFields' or 'swatches'.
 * @author m1b
 * @version 2024-02-29
 * @param {Document} doc - an Indesign Document.
 * @param {String} thingPlural - collective property of Document eg. 'checkBoxes'.
 * @returns {?Array<*>} - the things.
 */
function getThingsFromDocument(doc, thingPlural) {

    if (
        !doc.hasOwnProperty(thingPlural)
        || 'function' !== typeof doc[thingPlural].everyItem
    )
        return;

    var things = doc[thingPlural].everyItem().getElements();

    if (doc.groups.length > 0)
        // also collect things in groups
        things = things.concat(doc.groups.everyItem()[thingPlural].everyItem().getElements());

    if (doc.stories.length > 0) {

        // also collect any anchored things
        things = things.concat(doc.stories.everyItem()[thingPlural].everyItem().getElements());

        if (doc.stories.everyItem().tables.length > 0)
            // also collect any thing in tables
            things = things.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem()[thingPlural].everyItem().getElements());
    }

    return things;

};


/**
 * Returns a thing with matching property.
 * @param {Array|collection} things - the things to look through, eg. PageItems.
 * @param {String} key - the property name, eg. 'name'.
 * @param {*} value - the value to match.
 * @returns {*} - the thing.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if (things[i][key] == value)
            return things[i];

};

 

2 replies

Robert at ID-Tasker
Legend
March 8, 2024

@gregd

 

If you work on a PC - you could use free version of my tool.

 

After you get list of objects - all from the active document, from all open documents or just selected - you can sort & filter any way you want. 

 

Then, you can do whatever you want with those objects. 

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
March 7, 2024

Hi @gregd, I don't know how to do this from the normal UI, but since you tagged "scripting" here's a script I wrote to collect page items with a range of rotations. You can see in the script where I've set the range -5 to 5 degrees. The page items are collected in the array `myRotatedPageItems`.

 

I think you have done a bit of scripting... are you able to use this? Let me know if you need more help.

- Mark

 

/**
 * Collect Rotated Page Items.js
 * 
 * Example usage of `doSomethingToThings`
 * that collects page items having a
 * range of rotation.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-can-i-find-grep-objects-that-have-been-rotated/m-p/14474764
 */
function main() {

    // your items will be collected here
    var myRotatedPageItems = [],

        // adjust these to suit
        minRotationDegrees = -5,
        maxRotationDegrees = 5;

    // search every page item
    doSomethingToThings({
        target: app.activeDocument,
        thingPlural: 'pageItems',

        // collect rotated items
        doToThing: function collectRotatedItems(thing, doc) {

            if (
                undefined == thing
                || !thing.isValid
                || !thing.hasOwnProperty('rotationAngle')
                || 0 === thing.rotationAngle
            )
                return;

            if (
                thing.rotationAngle >= minRotationDegrees
                && thing.rotationAngle <= maxRotationDegrees
            )
                myRotatedPageItems.push(thing);

        },

    });

    alert('Collected ' + myRotatedPageItems.length + ' rotated page items.');

    // now you need to decide what to do with the rotation items!
    // -- your code here --

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Collect rotated items');


/**
 * Executes a function for every thing
 * in the document or documents.
 * `thingPlural` is a Document property name,
 * for example 'formFields' or 'swatches'.
 * @author m1b
 * @version 2024-02-29
 * @param {Object} options
 * @param {String} options.thingPlural - collective property of Document eg. 'checkBoxes'.
 * @param {Document|Documents} [options.target] - an Indesign Document or Documents (default: active document).
 * @param {Function} [options.doToDocument] - a function to be executed for each document (default: do nothing).
 * @param {Function} [options.doToThing] - a function to be executed for each thing (default: do nothing).
 */
function doSomethingToThings(options) {

    options = options || {};

    var doc = options.target || app.activeDocument,
        thingPlural = options.thingPlural,
        doToDocument = options.doToDocument,
        doToThing = options.doToThing;

    if ('Documents' === doc.constructor.name) {

        for (var i = 0; i < doc.length; i++) {
            options.target = doc[i];
            doSomethingToThings(options);
        }

        return;

    }

    // do something to document
    if (undefined != doToDocument)
        if (!doToDocument(doc))
            return;

    var things = getThingsFromDocument(doc, thingPlural) || [];

    // do something to things
    for (var i = things.length - 1; i >= 0; i--)
        if (undefined != doToThing)
            doToThing(things[i], doc);

};


/**
 * Returns array of things found in `doc`.
 * `thingPlural` is a Document property name,
 * for example 'formFields' or 'swatches'.
 * @author m1b
 * @version 2024-02-29
 * @param {Document} doc - an Indesign Document.
 * @param {String} thingPlural - collective property of Document eg. 'checkBoxes'.
 * @returns {?Array<*>} - the things.
 */
function getThingsFromDocument(doc, thingPlural) {

    if (
        !doc.hasOwnProperty(thingPlural)
        || 'function' !== typeof doc[thingPlural].everyItem
    )
        return;

    var things = doc[thingPlural].everyItem().getElements();

    if (doc.groups.length > 0)
        // also collect things in groups
        things = things.concat(doc.groups.everyItem()[thingPlural].everyItem().getElements());

    if (doc.stories.length > 0) {

        // also collect any anchored things
        things = things.concat(doc.stories.everyItem()[thingPlural].everyItem().getElements());

        if (doc.stories.everyItem().tables.length > 0)
            // also collect any thing in tables
            things = things.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem()[thingPlural].everyItem().getElements());
    }

    return things;

};


/**
 * Returns a thing with matching property.
 * @param {Array|collection} things - the things to look through, eg. PageItems.
 * @param {String} key - the property name, eg. 'name'.
 * @param {*} value - the value to match.
 * @returns {*} - the thing.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if (things[i][key] == value)
            return things[i];

};

 

gregd
gregdAuthor
Known Participant
March 8, 2024

Thanks, this is very helpful! I just want to identify them to deal with each individually later, so I added this:

 

	var pageNumbers = '';

	for (var i = 0; i < myRotatedPageItems.length; i++) {
		// Apply red stroke
		myRotatedPageItems[i].strokeColor = app.activeDocument.colors.itemByName("C=15 M=100 Y=100 K=0");
		myRotatedPageItems[i].strokeWeight = 1;

		// Get page number and append it to the string
		pageNumbers += "Page " + myRotatedPageItems[i].parentPage.name + "\n";
	}

	alert(pageNumbers);

 

m1b
Community Expert
Community Expert
March 8, 2024

Very nice! 😊