Copy link to clipboard
Copied
I want to change frame contents in masterspread. I tagged needed frame by Label m1.
After getting reference and then retrieving contents of frame:
var mItems = myMaster.textFrames.item ("m1")
alert (mItems.parentStory[0].contents)
i got "object is invalid". Why?
Done through renaming object in layer palette. m1 should be not Label, but name in layer palette.
Copy link to clipboard
Copied
First always test to make sure mItems is valid – I think all that needs is "if (mItems.isValid) …" somewhere. That way you are sure that the problem lies not in the label. (Suppose someone else runs your script and forgets to open the correct template. Also, "someone else" may be you in 3 months )
The problem here lies in "parentStory[0]". Text frames have an array for 'texts' items (even though there is always just one used), so you always have to use "mItems.texts[0]". You are correct, however, to use parentStory, which is a far better way to access the text. But there is only one, and it's not an array .
This should work just fine:
alert (mItems.parentStory.contents);
Copy link to clipboard
Copied
Thanks for comment. But problem is:
var mItems = newMaster.textFrames.item("m1");
always make inValid object.
Does it means, that tagging and retrieving frame by lable is not working method?
Is any method to define frame by its geometrical position?
Copy link to clipboard
Copied
Hi,
let's put it this way. The problem is not retrieving your frame.
The problem is that you are using parentStory[0] which makes no sense.
Look up DOM documentation:
Adobe InDesign CS6 (8.0) Object Model JS: TextFrame
It's just parentStory, not parentStory[0] …
One single text frame cannot be part of several stories. [0] would suggest this.
Yes, sometimes the DOM has its logics, but sometimes it's harder as Jongware's example with texts[0] where there is no example in the whole scripting engine of InDesign where texts[1] is used. Maybe a remnant of a developing strain that never was (fully) developed?
About retrieving a text frame by name:
You could apply the same name to several text frames.
With item("Name") or itemByName("Name") you'll find only a single one, not all with the same name.
This was different in CS4 and below, but changed with CS5.
If you define:
var mitem = newMaster.textFrames.item("m1");
and:
mitem.isValid returns false, you have a different problem:
Your named text frame might be part of a nested structure like a group or it could be anchored or pasted inside a graphic frame.
newMaster.textFrames will only see into text frames directly on newMaster.
Regards,
Uwe
Copy link to clipboard
Copied
Many thanks for explanations.
Yeah, parentStories in Frame cannot be more then 1 item (i didn't thing about it). Although Text should have same properties, but it not))
The main idea, i got:
construction
newMaster.textFrames.item("m1")
addresses to object, named in Layer Palette, but not by Label.
So far, label is an unuseful feature.
Copy link to clipboard
Copied
Laubender wrote
With item("Name") or itemByName("Name") you'll find only a single one, not all with the same name.
This was different in CS4 and below, but changed with CS5.
I have to correct myself. It was not the name property, it was the label property back then.
The name property was introduced with CS5, together with changes in the Layer Panel and other basic ones regarding pages and spreads.
Regards,
Uwe
EDITED AGAIN
Copy link to clipboard
Copied
Done through renaming object in layer palette. m1 should be not Label, but name in layer palette.