Copy link to clipboard
Copied
Hello everyone,
I have to remove some anchored text block and copy the content back to the texet in a paragraph before.
When the ante is at the beginning no problem BUT when it is in the texe, the move is done at the beginning.
Do you have an idea ? thank you
Bonjour à tous,
Je dois supprimer des bloc texte ancré et recopié le contenu dans le texet dans un paragraphe avant.
Quand l'ance est au début pas de problème MAIS quand elle se trouve dans le texe, le move ce fait au début.
Avez-vous une idée ? merci
main();
function main(){
var lesStyle = ['Titre 6','Titre 7'];
var leDoc, fs, i, y, f, p, ip;
leDoc = app.activeDocument; // le document
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y =0; y < lesStyle.length; y++) {
with (app.findGrepPreferences){
findWhat = "\\r$"; // la commande de la recheche
appliedParagraphStyle = lesStyle[y];
} // fin
var _tmp = leDoc.changeGrep();
}
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y =0; y < lesStyle.length; y++) {
with (app.findGrepPreferences){
findWhat = ""; // la commande de la recheche
appliedParagraphStyle = lesStyle[y];
} // fin
fs = leDoc.findGrep(true); // recheche ce qui est dans la fenêtre Find/replace
for (i = 0; i < fs.length; i++){ // passe sur chaque object trouvé
f = fs[i];
if ((p = f.parentTextFrames[0].parent) instanceof Character){
p.paragraphs[0].insertionPoints[0].contents = '\r';
ip = p.paragraphs[0].insertionPoints[0];
f.parent.texts.everyItem().move(LocationOptions.before, ip);
p.contents = ""; // supretion de l'ancre
}
}
}
}
Exemple en image :
Copy link to clipboard
Copied
Try this code snippet:
This will put the content at exact position of anchored.
main();
function main(){
var lesStyle = ['Titre 6','Titre 7'];
var leDoc, fs, i, y, f, p, ip;
leDoc = app.activeDocument; // le document
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y =0; y < lesStyle.length; y++) {
with (app.findGrepPreferences){
findWhat = "\\r$"; // la commande de la recheche
appliedParagraphStyle = lesStyle[y];
}
var _tmp = leDoc.changeGrep();
}
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y =0; y < lesStyle.length; y++) {
with (app.findGrepPreferences){
findWhat = ""; // la commande de la recheche
appliedParagraphStyle = lesStyle[y];
} // fin
fs = leDoc.findGrep(true); // recheche ce qui est dans la fenêtre Find/replace
for (i = 0; i < fs.length; i++){ // passe sur chaque object trouvé
f = fs[i];
if ((p = f.parentTextFrames[0].parent) instanceof Character){
//=========================================
// Below these two lines are reason for putting it to beginning of paragraph
//~ p.paragraphs[0].insertionPoints[0].contents = '\r';
//~ ip = p.paragraphs[0].insertionPoints[0];
//=========================================
f.parentTextFrames[0].parent.insertionPoints[0].contents = '\r';
ip = f.parentTextFrames[0].parent.insertionPoints[0];
//=========================================
f.parent.texts.everyItem().move(LocationOptions.before, ip);
p.contents = ""; // supretion de l'ancre
}
}
}
}
Best
Sunil
Copy link to clipboard
Copied
Merci Sunil Yadav,
voici le resulta
this command works fine to put the paragraph:
cette commande fonction très bien pour mettre le paragraphe :
p.paragraphs[0].insertionPoints[0].contents = '\r';
But how to get this new position to insert the text
Mais comment récupérer cette nouveau position pour y insérer le texte
Copy link to clipboard
Copied
I have one question for you.
What is your expected output, that you are looking for?
Then I can better help you.
Sunil
Copy link to clipboard
Copied
Bonjour Sunil, voici ce que je recheche au final :
Copy link to clipboard
Copied
Use this code snippet & check & see:
main();
function main(){
var lesStyle = ['Blue'];
var leDoc, fs, i, y, f, p, ip;
leDoc = app.activeDocument;
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y =0; y < lesStyle.length; y++) {
app.findGrepPreferences.findWhat = "\\r$";
app.findGrepPreferences.appliedParagraphStyle = lesStyle[y];
var _tmp = leDoc.changeGrep();
}
app.changeGrepPreferences = app.findGrepPreferences = NothingEnum.nothing;
for (y = 0; y < lesStyle.length; y++) {
app.findGrepPreferences.findWhat = "";
app.findGrepPreferences.appliedParagraphStyle = lesStyle[y];
fs = leDoc.findGrep(true);
for (i = 0; i < fs.length; i++){
f = fs[i];
if ((p = f.parentTextFrames[0].parent) instanceof Character){
var index = p.index;
p.insertionPoints[0].contents = '\r';
if(p.parent.characters[index].paragraphs[0].characters.length > 1){
p.insertionPoints[0].contents = '\r';
f.parent.texts.everyItem().move(LocationOptions.AFTER, p.parent.characters[index].paragraphs[0].insertionPoints[0]);
}
else{
f.parent.texts.everyItem().move(LocationOptions.AFTER, p.parent.characters[index].paragraphs[0].insertionPoints[0]);
}
ip = f.parentTextFrames[0].parent.insertionPoints[0];
p.parent.characters[index].paragraphs[0].appliedParagraphStyle = lesStyle[y];
p.contents = "";
}
}
}
}
Best
Sunil