Skip to main content
Participating Frequently
August 24, 2018
Question

How to get filename in Rectangle object?

  • August 24, 2018
  • 2 replies
  • 902 views

I have a rectangle object with a placed file.

Adobe InDesign CS6 (8.0) Object Model JS: Rectangle

Is it possible to get the file name for the placed file in the Rectangle? For instance, in Illustrator this is how I would get the filename for a placed file in a placed item. I'm trying to find the equivalent action in InDesign.

return placedItem.file.fsName;

This topic has been closed for replies.

2 replies

Community Expert
August 25, 2018

You can try the following

var rectangle = app.selection[0]  //I am taking the rectangle object ref from selection, you can use your own object if you already have it

if(rectangle && rectangle.allGraphics.length)

     alert("Path of the image inside rectangle is" + rectangle.allGraphics[0].itemLink.filePath)

else

     alert("The rectangle does not have an image inside it")

-Manan

-Manan
Legend
August 24, 2018

You could try just inserting a "Text Variable"!

Legend
August 24, 2018

Here's another option if you want to use a script, plus it gives you more options..........this has been shared on the forum.

#targetengine "Harbs";

//Header

(function(){

var err;

var HarbsUI = {}

HarbsUI.StandardButtonGroup = function (container,okayButton,cancelButton,spacer,newButton,editButton,deleteButton,size,orientation,alignChildren){

    if(!container){alert("You Must Provide a Container for the Button Group!");return;}

    //if(!alignChildren){alignChildren='fill';}

    //if(!orientation){orientation='column'}

    var group = container.add('group');

    group.orientation = orientation || 'column';

    group.alignChildren = alignChildren || 'fill';

    group.spacing = 0;

    if(size){

        if(group.orientation=='column'){

            group.preferredSize.width = size;

            }

        else if(group.orientation=='row'){

            group.preferredSize.height = size;

            }

        }

    if(okayButton || (okayButton == undefined && group.window.type == 'dialog')){

        if(!okayButton){okayButton="OK"}

        group.okayButton = group.add('button', undefined, okayButton, {name:'ok'});

        }

    if(cancelButton|| (cancelButton == undefined && group.window.type == 'dialog')){

        if(!cancelButton){cancelButton='Cancel'}

        group.cancelButton =group.add('button', undefined, cancelButton, {name:'cancel'});

        }

    group.cancelButton.onClick = function(){

        group.window.close();

        }

    if(spacer){

        group.spacer = group.add('group');

        if(group.orientation=='row'){

            group.spacer.preferredSize.width=spacer;

            }

        else{

            group.spacer.preferredSize.height=spacer;

            }

        }

    if(newButton){

        group.newButton =group.add('button', undefined, newButton);

        }

    if(editButton){

        group.editButton =group.add('button', undefined, editButton);

        }

    if(deleteButton){

        group.deleteButton =group.add('button', undefined, deleteButton);

        }

    return group;

    }

//

HarbsUI.DropdownGroup = function(container,dropdownLabel,dropdownList,selectedIndex,labelWidth,ddWidth,height){

    var group = container.add('group');

    group.orientation = 'row';

    group.alignChildren = 'top';

    if(height){group.maximumSize.height = height}

    group.group = group.add('group');

    group.group.orientation = 'column';

    group.group.alignChildren = 'right';

    group.group.margins = 0;

    if(labelWidth){group.group.preferredSize.width = labelWidth}

    group.label = group.group.add('statictext',undefined,dropdownLabel);

    group.dropdown = group.add('dropdownlist',undefined,undefined,{items:dropdownList});

    group.dropdown.selection = selectedIndex;

    if(ddWidth){group.dropdown.preferredSize.width = ddWidth;}

    group.dropdown.name = group.label;

    return group.dropdown;

    }

//

HarbsUI.DropDownDialog = function (title,dropdownLabel,dropdownList,selectedIndex){

    var w = new Window ('dialog', title);

    w.orientation = 'row';w.alignChildren = 'top';

    w.dropdown = new HarbsUI.DropdownGroup(w,dropdownLabel,dropdownList,selectedIndex);

    w.buttons = new HarbsUI.StandardButtonGroup(w);

    w.buttons.cancelButton.active = true;

    return w;

    }

//

try{

    var doc = app.documents[0];

    var variables = doc.textVariables;

    var variableNames = variables.everyItem().name;

    var d = HarbsUI.DropDownDialog("Pick a Variable","Variables",variableNames,0);

    d.dropdown.active=true;

    if(d.show()){

        var variableIndex = d.dropdown.selection.index;

        var selectedVariable = variables[variableIndex];

        app.selection[0].textVariableInstances.add({associatedTextVariable:selectedVariable});

        }

    }

catch (err){}

//Trailer

})();