• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
4

How to use getDocumentInfoAsText()

Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

While looking at Document properties, I discovered that there is a method called getDocumentInfoAsText. The name might suggest that it is a function that allows us to write out information from the Document Info panel as text. If this is available, it would be very easy to get a list of fonts used in a document from a script.

 

After some trial and error, I found that the first argument is an array and the second argument is a file. If the array is empty, then an empty text file will be created at the specified destination.

 

I assume that the first array is probably keys or something for the information to be written out, but what should I specify to succeed? I couldn't find that information in omv.xml or in the AppleScript dictionary.

 

app.documents[0].getDocumentInfoAsText([], new File('~/Desktop/document_info.txt')) ;

 

TOPICS
Scripting

Views

913

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 03, 2023 Nov 03, 2023

Hi @sttk3, I worked out the parameters I think. Have a look at this:

/**
 * Exploration of Document.getDocumentInfoAsText.
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/how-to-use-getdocumentinfoastext/m-p/14206023/thread-id/386366
 */
(function () {

    /** Whether to return info on the document's selection. */
    var SELECTED_ITEMS_ONLY = false;

    /**
     * Info types for Document.
     * @enum {Number}
     */
    var DocumentInfoType = {
        D
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

Hi @sttk3, I worked out the parameters I think. Have a look at this:

/**
 * Exploration of Document.getDocumentInfoAsText.
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/how-to-use-getdocumentinfoastext/m-p/14206023/thread-id/386366
 */
(function () {

    /** Whether to return info on the document's selection. */
    var SELECTED_ITEMS_ONLY = false;

    /**
     * Info types for Document.
     * @enum {Number}
     */
    var DocumentInfoType = {
        DOCUMENT: 2,
        OBJECTS: 3,
        GRAPHIC_STYLES: 4,
        BRUSHES: 5,
        SPOT_COLOR_OBJECTS: 6,
        PATTERN_OBJECTS: 7,
        GRADIENT_OBJECTS: 8,
        FONTS: 9,
        LINKED_IMAGES: 10,
        EMBEDDED_IMAGES: 11,
        FONT_DETAILS: 12,
        REPEAT_OBJECTS: 13,
    };

    // example:
    var outputFile; // outputFile = File('~/Desktop/document_info.txt');
    var result = getDocumentInfoAsText(app.activeDocument, [DocumentInfoType.FONTS, DocumentInfoType.GRAPHIC_STYLES], SELECTED_ITEMS_ONLY, outputFile);

    if (result)
        alert('Result:\n' + result);

})();


/**
 * Wrapper for `Document.getDocumentInfoAsText`
 * method just for experimenting.
 * Returns the contents of the output file.
 * @param {Documennt} [doc] - an Illustrator Document (default: active document).
 * @param {Array<DocumentInfoType>} [infoTypes] - array of DocumentInfoTypes (default: all types).
 * @param {Boolean} [selectionOnly] - whether to report on just the document's selection (default: false).
 * @param {File} [outputFile] - the file to write result to (default: temporary file, deleted after use).
 * @returns {String}
 */
function getDocumentInfoAsText(doc, infoTypes, selectionOnly, outputFile) {

    // for convenience:
    var ALL_DOCUMENT_INFO_TYPES = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

    var doc = doc || app.activeDocument,
        infoTypes = infoTypes || ALL_DOCUMENT_INFO_TYPES,
        selectionOnly = selectionOnly === true,
        f = outputFile || File(Folder.temp.fsName + '/getDocumentInfoAsText.txt'),
        success;

    if (!f.parent.exists)
        f.parent.create();

    try {
        success = doc.getDocumentInfoAsText(infoTypes, f, selectionOnly);
    } catch (error) {
        alert(error);
    }

    if (!success)
        return;

    f.open('r');
    var result = f.read();

    if (outputFile == undefined)
        f.remove();

    return result;

};

 - Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

@m1b Great job! Works fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

Copy link to clipboard

Copied

Nice work @sttk3 @and @m1b. I've resorted to some hacky tricks to get this information before, so I'm excited to look at this closer. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

Copy link to clipboard

Copied

thanks for bringing that up sttk3!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2023 Nov 04, 2023

Copy link to clipboard

Copied

Amazing!! great work Mark! I tried but it was mostly guessing work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

Hey @CarlosCanto you may be amused at my approach:

 

I made a loop with a try/catch, where I called the method for *every key of Document* and *every value of every key of the active document* such that it would alert me if there wasn't an error.

 

As it happened, the alert came up because one of the values of one of the properties of active document happened to be an integer between 2 and 13! After that I changed the loop to handle just integers (between 0 and 16000) and found that only 2-13 worked. The selectedObjectsOnly flag I discovered by comparing the result using true and falseā€”at first I was baffled at the random way it changed the output.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

@m1b I'm amazed! brilliant method. I was just trying different types for argument #3, thinking #2 was set to File. It got me nowhere.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2023 Nov 07, 2023

Copy link to clipboard

Copied

LATEST

Haha, thank you. You are too kind. I was laughing at myself, throwing every in my kitchen drawerā€”knife, fork, spoon, toasterā€”at my locked door, but, by luck, one was a key! šŸ™‚

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines