Skip to main content
loyal_operator154A
Legend
November 9, 2014
Answered

HOW TO: set anchoredObjectSettings for .palce() object?

  • November 9, 2014
  • 1 reply
  • 1254 views

Hi, I'm currently working on interesting script for GREP placing, and I'm wondering how I can set anchoredObjectSettings for .palce() object?

for(i=0; i < found.length; i++)

{

    foundElem = new File (myFolder + "/" + found.contents);

    found.place(foundElem); // Placing Ancored Object

  

    // HERE IS WHERE I NEED SOME HELP: how to set "anchoredObjectSettings" for just placed Ancored Object

    //anchoredObjectSettings.anchoredPosition = AnchorPosition.ABOVE_LINE;

    //anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.TEXT_ALIGN;

}

Here you can download example files - script, InDesign file and images, that should be placed into InDesign file with script

Dropbox - GREP placing.zip

PS: I believe this script will be very useful, so if anybody have any ideas/suggestions, and want to help me with further development - this would be great!

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

Right, It was too fast...

That line returns an array of placed graphics - and we have to set property for its container in fact.

so make it for

//.......

mPlacedObj = found.place(foundElem)[0].parent;

//.......

Jarek

1 reply

Jump_Over
Legend
November 9, 2014

Hi,

line 04 returns an array of placed objects. Store it as variable and set properties of 1st element.

mPlacedObj = found.place(foundElem)[0];

mPlacedObj.anchoredObjectSettings.anchoredPosition = AnchorPosition.ABOVE_LINE;

// and so on

Jarek

loyal_operator154A
Legend
November 9, 2014

Hi,

Thanks for reply, but its seems its not working - I tried before asking here.. or it's work on your computer?))

/*

    GREP place files.

    This script will ask to select source folder with files to place,

    and then, with dialog box (or prompt) [this is not implemented yet, so I use static GREP value while developing]

    will ask to type GREP find expresion to search for text placeholder, that need to be replaced with file from source folder we just selected.

  

    TODO: for now, I want to figure out how I can set:

    anchoredObjectSettings.anchoredPosition = AnchorPosition.ABOVE_LINE;

        AND

    anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.TEXT_ALIGN;

        once I placed file as ancoredObject (this part is at the very ending)

      

    Also, this might be usefull to make anchored frame with column widh, and fit image proportionally

*/

var myFilteredFiles;

//Make certain that user interaction (display of dialogs, etc.) is turned on.

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

var myExtensions = []; // initialize array

myExtensions.push(".jpg", ".jpeg", ".png", ".gif"); // raster images

myExtensions.push(".psd", ".tif", ".tiff", ".pdf"); // raster images (layered)

myExtensions.push(".ai", ".eps", ".svg", ".cdr"); // vector graphics

myExtensions.push(".mp3"); // audio files

myExtensions.push(".mp4"); // video files

myExtensions.push(".swf"); // flash files

myExtensions.push(".doc", ".docx", ".rtf", ".txt"); // text documents

myExtensions.push(".xls", ".xlsx"); // table documents  

//Display the folder browser.

var myFolder = Folder.selectDialog("Select the source folder with files for placing", "");

//Get the path to the folder containing the files you want to place.

if(myFolder != null)

{

    if(File.fs == "Macintosh")

    {

        myFilteredFiles = myMacOSFileFilter(myFolder);

    }

    else

    {

        myFilteredFiles = myWinOSFileFilter(myFolder);

    }

    if(myFilteredFiles.length != 0)

    {

        for(i = 0; i < myFilteredFiles.length; i++)

        {

            /* TEMPORARILY NOT USED var myTextFrame = app.selection[0];  var myPlaceFile = new File (myFilteredFiles);  myTextFrame.place(myPlaceFile);        */

        }

    }

}

//Windows version of the file filter.

function myWinOSFileFilter(myFolder)

{

  var myFiles = new Array;

  var myFilteredFiles = new Array;

  for(myExtensionCounter = 0; myExtensionCounter < myExtensions.length; myExtensionCounter++)

    {

        myExtension = myExtensions[myExtensionCounter];

        myFiles = myFolder.getFiles("*"+ myExtension);

  if(myFiles.length != 0)

        {

            for(var myFileCounter = 0; myFileCounter < myFiles.length; myFileCounter++)

            {

  myFilteredFiles.push(myFiles[myFileCounter]);

            }

        }

  }

  return myFilteredFiles;

}

function myMacOSFileFilter(myFolder)

{

  var myFilteredFiles = myFolder.getFiles(myFileFilter);

  return myFilteredFiles;

}

//Mac OS version of file filter

//Have to provide a separate version because not all Mac OS users use file extensions and/or file extensions are sometimes hidden by the Finder.

function myFileFilter(myFile)

{

    var myFileType = myFile.type;

    switch (myFileType)

    {

        case "JPEG":

        case "EPSF":

        case "PICT":

        case "TIFF":

        case "8BPS":

        case "GIFf":

        case "PDF ":

            return true;

            break;

        default:

        for(var myCounter = 0; myCounter<myExtensions.length; myCounter++)

        {

            var myExtension = myExtensions[myCounter];

            if(myFile.name.indexOf(myExtension)>-1)

            {

                return true;

                break;

            }

        }

  }

  return false;

}

findWhat = "\\<\\l+\\.\\l{2,4}\\>"; // \\< means "begining of the world", and \\> means end of the world;

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = findWhat; // our GREP that search for image placeholder text;

found = app.activeDocument.findGrep();

for(i=0; i < found.length; i++)

{

    foundElem = new File (myFolder + "/" + found.contents);

    //found.place(foundElem); // Placing Ancored Object - this line works

  

    mPlacedObj = found.place(foundElem)[0]; // this one also working

  

    // those lines cause error

    //mPlacedObj.anchoredObjectSettings.anchoredPosition = AnchorPosition.ABOVE_LINE;

    //mPlacedObj.anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.TEXT_ALIGN;

}

app.changeGrepPreferences.changeTo = "";

app.activeDocument.changeGrep();

Jump_Over
Jump_OverCorrect answer
Legend
November 9, 2014

Hi,

Right, It was too fast...

That line returns an array of placed graphics - and we have to set property for its container in fact.

so make it for

//.......

mPlacedObj = found.place(foundElem)[0].parent;

//.......

Jarek