-
1. Re: Change Text in a Text Box with Script
Eli.Shklovsky Sep 6, 2011 2:05 PM (in response to RichardM0701)Hi
The label property depends if you use CS5 or up.
CS4 and previous versions it was sufficient to use the script label.
Select the frame with the selection tool and write the name on the Script Label palette.
CS5 and up you need to select the text frame, open the Layers palette, find the text frame you wish to name, you will see the color indication, then you should click the <text frame> label on that palette and give it the label you want.
anyway, the code to use it is, if you call your frame as "a":
myFrame = app.activeDocument.textFrames.itemByName("a");
hope this help
Cheers,
Eli
-
2. Re: Change Text in a Text Box with Script
RichardM0701 Sep 6, 2011 4:30 PM (in response to Eli.Shklovsky)Worked like a charm. I filled it using the myFrame.contents = "Spanish" and it works great.
You wouldn't happen to know how to reference the layers group would you? The layers group that is named "Rev line". I tried and was unsuccessful:
myFrame = app.activeDocument.textFramesGroup.itemByName("Rev Line").textFrames.itemByName("a");I tried looking it up in the Scripting Object Library and there was a Group.textFrame but not sure how to use it here.
-
3. Re: Change Text in a Text Box with Script
Eli.Shklovsky Sep 6, 2011 10:45 PM (in response to RichardM0701)Did you mean the whole layer? or a group of objects?
I will answer both:
Reference the whole layer:
app.activeDocument.layers.itemByName("Rev Line")
Reference a group of objects in a specified layer:
app.activeDocument.layers.itemByName("Rev Line").groups.itemByName("myGroup").name
or reference the group from the page items collection:
app.activeDocument.pageItems.itemByName("myGroup").name
or reference the group from the document's groups collection:
app.activeDocument.groups.itemByName("myGroup").name
I hope this helps
Regards,
Eli
-
4. Re: Change Text in a Text Box with Script
RichardM0701 Sep 7, 2011 7:43 AM (in response to Eli.Shklovsky)Thank you Eli, this is very helpful and educational as well. I really appreciate your help.
Here is a screenshot of the layer:
As you can see, "Rev Line" is a group and holds my Language text box. Its basicly a text box inside a text box. So would this be correct?
var myFrame = app.activeDocument.layers.itemByName("Rev Line").groups.itemByName("Language").name; myFrame.contents = "Spanish" -
5. Re: Change Text in a Text Box with Script
Eli.Shklovsky Sep 7, 2011 11:28 PM (in response to RichardM0701)I cannot figutre exactly from your screenshot for each object what type it is.
"Its basicly a text box inside a text box" - Inside means that the frame text is anchored inside the parent text frame? if so the 'child' text frame will be considered as a character inside the 'parent' text frame, so you should reference it from the characters collection.
Anyway, in order to reference an object, simply go through the collection->object->collection->object, figure out which type it is and try to debug it on the javaScript console.
good luck
Eli
-
6. Re: Change Text in a Text Box with Script
Harbs. Sep 7, 2011 11:46 PM (in response to RichardM0701)No.
You probably need something like this:
var myFrame = app.activeDocument.groups.itemByName("Rev Line").textFrames.itemByName("Language").name;Alternatively, you can do something like this to find your frame:
var myFrame = getObjectByName(app.documents[0],"Language"); function getObjectByName(container,name){ var objects = container.allPageItems.slice(); for(var i=0;i<objects.length;i++){ if(objects[i].name == name){ return objects[i]; } } return null; }You can feed into the function any item which has an allPageItems property. That includes Document or Layer among others...
Harbs
-
7. Re: Change Text in a Text Box with Script
RichardM0701 Sep 9, 2011 7:14 AM (in response to Harbs.)Eli and Harbs,
Thank you so much for your help. I was unable to call it using the:
var myFrame = app.activeDocument.groups.itemByName("Rev Line").textFrames.itemByName("Language").name;But your other code worked like a charm!!!
var myFrame = getObjectByName(app.documents[0],"Language"); function getObjectByName(container,name){ var objects = container.allPageItems.slice(); for(var i=0;i<objects.length;i++){ if(objects[i].name == name){ return objects[i]; } } return null; }I will add an if statement to this so if the text box is not in the document, the user will get an message box.
Thanks again for your help.




