Copy link to clipboard
Copied
Hello, i just start a script to change some AnchorObj to a Glyph. Some how my code dont work?
this is my code.
var myDoc = app.activeDocument;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
var allframes = app.activeDocument.allPageItems;
function main(){
if (app.layoutWindows.length == 0) return;
if (app.selection.length != 1 || !app.selection[0].hasOwnProperty('changeGrep')) {
alert('Please select only one textframe or text range!');
return;
}
var changeObject = app.selection[0];
if (changeObject.hasOwnProperty('characters') && changeObject.characters.length == 0) return;
var doc = app.documents[0];
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;
for(var i = 0 ; i < allframes.length; i++){
if(allframes instanceof Group){
allframes.name = "Group";
}
}
try {
app.findChangeGrepOptions.properties = ({includeFootnotes:true, kanaSensitive:true, widthSensitive:true});
app.findGrepPreferences.properties = ({findWhat:"~a{1}"});
var myFoundGrep = myDoc.findGrep(true);
myfoundGrep = app.selection[0];
var myfoundGrepPItems = myfoundGrep.allPageItems;
alert(myfoundGrepPItems.length);
for(var j=0; j<myfoundGrepPItems.length; j++){
if(myfoundGrepPItems
instanceof Group&&myfoundGrepPItems[j+2].fillColor.name=="九州7月 C=10 M=40 Y=100"){ app.changeGrepPreferences.properties = ({changeto:"[someglyph]"});
myfoundGrep.changeGrep();
myfoundGrepPItems
.remove(); }
}
} catch (e) {alert(e + ' at line ' + e.line)}
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
alert ('Thay xong roi do may');
}
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;
};
Hi Trevor,
hm, OfficialNeaven is already using findGrep( true ) .
where reverse order is enabled.
What I'd do is to store the id value of all found items in an array, loop that result array and access the items with document.pageItems.itemByID() in a second step.
Regards,
Uwe
Copy link to clipboard
Copied
Hi OfficialNeaven ,
sorry, but how should one test this?
What's the Unicode code point of the glyph?
What's the font that supports the glyph?
Does the group has a name?
Or any other unique specific properties so that you can identify it?
( I see that you try this with the assigned fill color, but is this enough? )
The recipe for this would be:
The anchored group's parent is a character.
You'd assign this character a new content.
FWIW: I think that a GREP Find/Change will only complicate all this.
Regards,
Uwe
Copy link to clipboard
Copied
Hello, Laubender
i'm sorry for giving short info. Thing is, Glyph and font is not a problem.
I just want to change the Orange Grouped Anchor Object to that glyph. But some how it give error that the object is not there anymore and change all of it to that glyph (include A B C D).
Copy link to clipboard
Copied
This should be everything. The first table is the original. The second table is the result after execute the script
i just want the first orange grouped anchor object to change that glyph.
I tests it by doing remove() to see if remove() correct object; it's correct.
But when i'm using changeGrep(); it's catch error that the object is no longer there. Error at line 34.
Copy link to clipboard
Copied
Try going backwards (Just wrote this answer for someone else)
Instead of
for(var j=0; j<myfoundGrepPItems.length; j++){
Use
var j = myfoundGrepPItems.length - 1;
while(j--){
Copy link to clipboard
Copied
Hi Trevor,
hm, OfficialNeaven is already using findGrep( true ) .
where reverse order is enabled.
What I'd do is to store the id value of all found items in an array, loop that result array and access the items with document.pageItems.itemByID() in a second step.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
How true, I should have looked a his code more carefully.
Regards
Trevor
Copy link to clipboard
Copied
hello, i found the solution, that's because my grep is not correct enough.
Here's my new grep : ^~a{1}.*?(?=~a{1})