Copy link to clipboard
Copied
This is my code. I want to change the Circle 1 object (its a grouped anchor object in a cell) to an unicode \x{2460} by find all the textFrame has "1" as content.
GREP is okay. it was able to select all the group anchor object which has red stroke color.
The code run without error and script was able to select all the Circle 1 object but...
When i tried to use myFound2.words[0].changeGrep(); it's change all the number in a same line.
When i tried to use myFound2.characters[0].changeGrep(); it's won't change anything.
So what's wrong with my code? Any help please?
Copy link to clipboard
Copied
Hello,
Please paste your code as text so that someone can atleast try it, looking at such a big code that too in an image is very time consuming. Paste your code here and use the advanced editor, then select the code and click on the >> button in the bottom row top right and select javascript.
I see that your query is specific to your document, it would be helpful if you can also send a sample document to test your code. For that upload your document to a cloud service like Dropbox and paste the public url here.
-Manan
Copy link to clipboard
Copied
Sorry. my bad. Thanks for helping me.
Here's my Data. OOO Folder - Google Drive
Here's my code.
var myDoc = app.activeDocument;
var mySel = app.selection[0];
var allframes = app.activeDocument.allPageItems;
var myFound2,myFoundPI2 = [];
function rename(){
for(var i = 0 ; i < allframes.length; i++){
if(allframes instanceof Group)
allframes.name = "Group";
}
}
function main(){
rename();
if (app.layoutWindows.length == 0) return;
if (app.selection.length != 1 || !app.selection[0].hasOwnProperty('changeGrep')) {
alert('chọn cho mình đi');
return;
}
if (mySel.hasOwnProperty('characters') && mySel.characters.length == 0) return;
var style;
var scriptVersion = app.scriptPreferences.version;
app.scriptPreferences.version = 7.5;
var options = app.findChangeGrepOptions.properties;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
//cuc ngay
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"~a{1}[\l\u]*?(?=[\\x{322A},\\x{322B},\\x{322C},\\x{322D},\\x{322A},\\x{322B},\\x{322C},\\x{322E},\\x{322F},\\x{3230},\\x{3237},\\x{30FB}])"});
var myFound2= mySel.findGrep(true);
for(var a=0;a<myFound2.length;a++){
alert(myFound2.length);
for(var b=0;b<myFound2.allPageItems.length;b++){
//alert(myFound2.allPageItems.length);
myFoundPI2=myFound2.allPageItems;
if(myFoundPI2 instanceof TextFrame){
switch(true){
case(myFoundPI2.parentStory.properties.contents=="1") : {
app.select(myFound2);
app.changeGrepPreferences.properties = ({changeTo:"\\x{2460}",appliedFont:"A-OTF UD Shin Go Pro", fontStyle:"M",fillColor:"C=100 M=0 Y=0 K=0"});
myFound2.words[0].changeGrep();
break;}
}
}
}
}
} catch (e) {alert(e + ' at line ' + e.line)}
}
main();
function getStyleByString(docOrGroup, string, property) {
if (string == '[No character style]') return docOrGroup[property][0];
if (string == '[No paragraph style]') return docOrGroup[property][0];
if (string == 'NormalParagraphStyle') return docOrGroup[property][1];
stringResult = string.match (/^(.*?[^\\]):(.*)$/);
var styleName = (stringResult) ? stringResult[1] : string;
styleName = styleName.replace (/\\:/g, ':');
remainingString = (stringResult) ? stringResult[2] : '';
var newProperty = (stringResult) ? property.replace(/s$/, '') + 'Groups' : property;
var styleOrGroup = docOrGroup[newProperty].itemByName(styleName);
if (remainingString.length > 0 && styleOrGroup.isValid) styleOrGroup = getStyleByString (styleOrGroup, remainingString, property);
return styleOrGroup;
};
Copy link to clipboard
Copied
Manan Joshi can you help me with this one?
Copy link to clipboard
Copied
Hi,
The problem is because when you use word[0] in the last line of the first cell, the whole content of the line is considered as the word and since both the anchored objects in this line meet the find grep condition both of them are replaced. In all the other occurrences there is a single anchored object in the word and hence it works correctly. In order to solve it, i don't see the need of changegrep, since you already have the instance of the anchored character you can just replace its content. Replace the content of your case statement with the following and it should work
myFound2.contents = "\u2460";
myFound2.appliedFont = "A-OTF UD Shin Go Pro";
myFound2.fontStyle = "M";
myFound2.fillColor = "C=100 M=0 Y=0 K=0;
break;
-Manan
Copy link to clipboard
Copied
Thanks you. Its works.