Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Access and return properties of placedItem.file

Contributor ,
Nov 18, 2014 Nov 18, 2014

I'm trying to assign properties of placedItem.file. However, whenever I try to access placedItem.file it prints/returns "undefined is not an object".

I've used the alert command to print the object e.g. alert(placedItem.file) and it prints the file location of the image. However, when I try to assign that value to a variable ( var exampleName = placedItem.file ) it also returns the same error.

I've also tried accessing sub properties of file, like file.fullName and file.displayName. It returns the same error. If anyone has insight that would be awesome. I really just need to return the path of an image to a variable.

TOPICS
Scripting
2.4K
Translate
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

Valorous Hero , Nov 19, 2014 Nov 19, 2014

I have ran the following with no problem such as you are experiencing. 

function test(){

    if(app.documents.length>0){

        var doc=app.activeDocument;

        var s = doc.placedItems[0];

        var info = s.file;

       

        alert(info);

    }

}

test();

Translate
Adobe
Guide ,
Nov 18, 2014 Nov 18, 2014

CHAPTER 1: JavaScript Object Reference PageItems 119

Getting references to external files in page items

Before running this script, open a document that contains one or more linked images.

// Gets all file-references in the current document using the pageItems object,

// then displays them in a new document

if ( app.documents.length > 0 ) {

var fileReferences = new Array();

var sourceDoc = app.activeDocument;

var sourceName =sourceDoc.name;

for ( i = 0; i < sourceDoc.pageItems.length; i++ ) {

artItem = sourceDoc.pageItems;

switch ( artItem.typename ) {

case "PlacedItem":

fileReferences.push( artItem.file.fsName );

break;

case "RasterItem":

if ( ! artItem.embedded ) {

fileReferences.push( artItem.file.fsName );

}

break;

}

}

// Write the file references to a new document

var reportDoc = documents.add();

var areaTextPath = reportDoc.pathItems.rectangle( reportDoc.height,0,

reportDoc.width, reportDoc.height );

var fileNameText = reportDoc.textFrames.areaText( areaTextPath );

fileNameText.textRange.size = 24;

var paragraphCount = 3;

var text = "File references in \'" + sourceName + "\':\r\r";

for ( i = 0; i < fileReferences.length; i++ ) {

text += ( fileReferences + "\r" );

paragraphCount++;

}

fileNameText.contents = text;

}

Translate
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
Valorous Hero ,
Nov 19, 2014 Nov 19, 2014

I have ran the following with no problem such as you are experiencing. 

function test(){

    if(app.documents.length>0){

        var doc=app.activeDocument;

        var s = doc.placedItems[0];

        var info = s.file;

       

        alert(info);

    }

}

test();

Translate
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
Contributor ,
Nov 19, 2014 Nov 19, 2014

Thank you for the example guys. I feel very very silly - turns out I was trying to read the 'file' property of a PathItem (which obviously doesn't exist). I should have started printing the typenames from the beginning to double check what I was passing to the function. I appreciated the quick feedback.

While we're hear though - I was curious if you're familiar with the property 'absoluteZOrderPosition'. I couldn't find it in the AI CC Javascript manual, but it is a property that appears on my pageItems.

Translate
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
Valorous Hero ,
Nov 19, 2014 Nov 19, 2014

Hey looks like some hidden undocumented gem, I cannot make sense of it right now.  For example, I have an item which has ZOrderPosition of 13, but absoluteZOrderPosition is 30.  Hmm.

Translate
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 20, 2014 Nov 20, 2014

no such property on CS5

Translate
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
Contributor ,
Nov 20, 2014 Nov 20, 2014

I'm seeing it on CC '14.

As silly noted, what its value means isn't readily apparent. If I find a pattern I'll report back on it.

Translate
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
Guide ,
Nov 21, 2014 Nov 21, 2014

I have no idea if this has any merit, but I go with it anyway.

zOrderPosition is object stacking order.

Could absoluteZOrderPosition be stacking order of points?

Not found in CS5, CS5 has no gradient on strokes so no need for stacking order of points?

rickardart has just posted this: Is there a way to chose when a path flows above itself and when it flows behind?

that's what made me think.

Can't test any of this as I only have CS5 here and am not back at work for a few days

Translate
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
Guide ,
Nov 23, 2014 Nov 23, 2014

From what I can tell this is not the case... Booo.

But am yet to find a zOrderPosition that differs from absoluteZOrderPosition.

will keep looking as I open files.

I have always done my scripting in Notepad++.

after having a play with ExtendScript Toolkit over the weekend I like the ability to run the script without even saving etc.

may be a dumb question, but there are obviously other features I can use.

such as how you found

it is a property that appears on my pageItems.

am I missing something important that I should be aware of?

Maybe this should have been a new Question...

Translate
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 23, 2014 Nov 23, 2014

he probably meant it appeared in the Object Model Viewer, under the Help menu in the ESTK, you can find all kind of undocumented objects there.

Translate
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
Guide ,
Nov 24, 2014 Nov 24, 2014

Thanks Carlos.

I'll have a play there.

Translate
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
Valorous Hero ,
Nov 24, 2014 Nov 24, 2014

The mystery property does not appear to be documented in the CC OMV, but it does appear in the Data Browser.

function test(){

    var doc = app.activeDocument;

    var p = doc.pageItems[0];

    alert(p.name+". Normal Z-Order: "+p.zOrderPosition+", Absolute Z-Order: "+p.absoluteZOrderPosition);

}

test();

The above code used on doc screen-shot below prints out: Grp_2. Normal Z-Order: 7, Absolute Z-Order: 13

My experiment here, suggests that absolute order takes into account the child elements of all elements (to show z-order in entire document), and the 'regular' z-order is about the stacking within a container element.

Like layer.pageItems vs document.pageItems ? 

Though when I first looked at this property inside one of my more cluttered real-life documents, I remember that I couldn't verify this relationship.  Maybe I was tired or something.

2014-11-24 09_01_59-.jpg

Translate
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
Contributor ,
Nov 24, 2014 Nov 24, 2014

Actually I found AbsoluteZOrderPosition by writing a function that prints the names of every attribute of an object pasted to it. I don't think it's in the ESTK.

Translate
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
Guide ,
Nov 24, 2014 Nov 24, 2014

any chance of seeing that code snippet slowMotion?

and silly-v, that actually sounds quite logical.

now i wish there was a pointZOrderPosition.

Translate
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
Contributor ,
Nov 24, 2014 Nov 24, 2014

function GetKeys(obj)

{

   var keys = [];

   for(var key in obj){

   keys.push(key);

  }

   return keys;

}

var props = GetKeys(yourPlacedItemGoesHere);

alert(props);

Translate
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
Guide ,
Nov 24, 2014 Nov 24, 2014
LATEST

Thanks,

I'l have a play with it.

Translate
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