Hey all!
And again I'm having trouble in a pretty simple thing. I searched for a code that searches the Paragraph Style that i want to, till here no problem. I fount the item, swap to selection tool so that it can change the selection to the text box instead of the text and then I want to name this object. Just that, but I just can't do it! hahahaha
Take a look:
// LOCALIZA O PARAGRAPH STYLE DA REFERÊNCIA var oDoc = app.activeDocument; //First loop through all stories then through all paragraphs in each story for(n=0; n< oDoc.stories.length;n++){ for(i=0;i<oDoc.stories[n].paragraphs.length;i++){ // If paragraph style is "Silkeborg" then select paragraph and insert "S " before if (oDoc.stories[n].paragraphs[i].appliedParagraphStyle.name == "referencia") { oDoc.stories[n].paragraphs[i].select(); } } } // SELECIONA O BOX app.toolBoxTools.currentTool = UITools.SELECTION_TOOL; // NOMEIA app.activeDocument.selection.name= "Modelo";
It searches for it, if finds it, change to selection tool but just won't name the object. What am I doing wrong?
Here's some other script that i found that names the object by the same objects label:
var myDocItems = app.activeDocument.allPageItems; for(var i = 0; i < myDocItems.length; i++) if(!myDocItems[i].name) myDocItems[i].name = myDocItems[i].label;
And this one works, but this object that searching at my script doesn't have a label, so I can't use it.
Any tips?!
Thanks guys! Cya!
"Selection" is always an array, so you can't use
..selection.name = ..
you must use
..selection[0].name = ...
Second, "has no label" is not a problem :-) All textframes have a label (and usually it's empty). I don't know whether you should be using "name" or "label" in this case -- I believe the advantage of "name" in CS5.5 is that it will showin the Layers panel.
Third (!), there is 1. no need to "switch to selection tool" to set a selection, and neither to use app.select. Javascript allows instant access to everything, so you could simply set the name of any paragraph's outer frame using something like
oDoc.stories[i].paragraphs[n].parentTextFrames[0].name = ...
Note that a single paragraph may have more than a single "parent text frame" -- this paragraph maystart in one and end in another.
Outstanding Jongware! As always!
Here's how it got:
for(n=0; n< oDoc.stories.length;n++){ for(i=0;i<oDoc.stories[n].paragraphs.length;i++){ if (oDoc.stories[n].paragraphs[i].appliedParagraphStyle.name == "referencia") { oDoc.stories[n].paragraphs[i].select(); oDoc.stories[n].paragraphs[i].parentTextFrames[0].name = "Modelo"; } } }
So simple.
Thank you so much!