Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Oh, help! What am I doing wrong.

New Here ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

I am a definite scripting newbie and I just can't figure out what I'm doing wrong.  I have the javascript below as an exercise and I'm trying to figure out why the approach in the second part gives me errors and the 1st works fine.  I have a text frame named SourceLbl on the pasteboard containing some text. It is also selected.   When I run this, it tells me that myFrame is a TextFrame, but then I get "Object is Invalid" errors when trying to reference the parent or obtain the text.  In the next few lines, dealing with the same object as a selection, the same things work fine.  It's parent is the Spread. I can display the text.  There's clearly something I just don't get about these two different methods.  I've set the Find/Change preferences for the document to use all hidden layers.  That didn't seem to have any effect.  I'm thinking the fact that it's the Pasteboard that's causing my issues.  Can anyone give me any insight into the differences here.  Just working at learning this scripting thing.  I had 30 years of programming experience "back in the day" working with everything from Autocoder to Fortran to COBOL to Assembler, but this object-oriented thing has me scratching my head!  

Here's the code.  I've attached a screenshot of the spread, etc.

if (app.documents.length > 0) {
//this part works fine
var selFrame = app.selection[0];
var selText =selFrame.texts[0].contents;
var look = selFrame.parent;
alert(selText)
//this part gives me "object is invalid" errors when setting variable lookie, myText
var myDoc = app.activeDocument;
var mySpread = app.activeWindow.activeSpread;
var myFrame = mySpread.textFrames.itemByName("SourceLbl");
var lookie = myFrame.parent;
myText = myFrame.texts[0].contents;
alert(myText)
alert("Finished");

TOPICS
Scripting

Views

68

Likes

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

Adobe Community Professional , Feb 25, 2021 Feb 25, 2021
 For itemByName to work the text frame page item needs to be named SorceLbl in the Layers panel. So this doesn’t work But this does: A text frame can have a script label, but that would be the .label property not the .name property —there isn’t an itemByLabel() method

Likes

Translate

Translate
Adobe Community Professional ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

I don't think your frame is actually named SourceLbl. If it were named that, it wouldn't have the carrots around it (<SourceLbl>). Try tripleclicking on the name in the layers panel and see if you can rename it.

But, what version of InDesign is that? In older versions, that may not have been the case...

 

You are getting myFrame instanceof TextFrame because the DOM thinks it's getting a text frame, but the object is invalid because there is nothing of that name. 

You can check for:

 

if (myFrame.isValid) ...

 

to see if the object resolved correctly, or:

 

if (!myFrame.isValid) alert("Not valid!);

 

Likes

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
Adobe Community Professional ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

 

 

 

 For itemByName to work the text frame page item needs to be named SorceLbl in the Layers panel. So this doesn’t work

 

Screen Shot 34.png

But this does:

Screen Shot 33.png

A text frame can have a script label, but that would be the .label property not the .name property —there isn’t an itemByLabel() method

 

 

Likes

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
New Here ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

LATEST

That was it...I corrected the layer name to SourceLbl from <SourceLbl> and everything was fine!  I must have looked at that label 100 times and never twigged that the <> was part of the actual name!  Should have posted for help about 6 hours (and one glass of wine) ago!  Thank you! Thank you! Thank you!

Likes

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