2017-08-21 4 views
0

Je tente de créer un script Adobe InDesign qui sélectionne le texte, modifie le texte sélectionné en majuscules, puis copie le même texte. Je suis coincé.Modification du script Adobe Indesign en majuscules et copie du texte dans le presse-papiers

#target "InDesign" 
 

 
var myDoc = app.activeDocument; 
 

 

 
if(app.documents.length != 0){ 
 
    if(app.selection.length == 1){ 
 
     try{   
 
      //var text = app.selection[0]. 
 
      var frame1 = page.textFrames[0]; 
 
      //var frame2 = page.textFrames[1]; 
 

 
      frame1.texts.everyItem().select(); 
 
      //frame1. 
 
      app.copy(); 
 
     } 
 
     catch(e){ 
 
      alert ("Please select text", "Selection"); 
 
     } 
 
    } 
 
else{ 
 
    alert ("Please select text", "Selection"); 
 
    } 
 
} 
 
else{ 
 
\t alert("Something wrong"); 
 
}

+0

obtenir une prise de l'erreur 'catch (e) { alert ("Exception happened:" + e, "Exception"); 'pour vous aider à dépanner ce qui se passe. Je reçois "page est indéfini" dans 'var frame1 = page.textFrames [0];' –

Répondre

3
var myDoc = app.activeDocument; 

if(app.documents.length != 0){ 
    if(app.selection.length == 1){ 
     try{   
      //var text = app.selection[0]. 
      //var frame1 = app.selection[0].textBoxes[0].contents; 
      var frame1 = app.documents[0].pages[0].textFrames[0]; 
      frame1.contents = frame1.contents.toUpperCase(); 
     } 
     catch(e){ 
      alert ("Exception : " + e, "Exception"); 
     } 
    } 
else{ 
    alert ("Please select text", "Selection"); 
    } 
} 
else{ 
    alert("Something wrong"); 
} 

Ici il utilise l'objet sélectionné:

var myDoc = app.activeDocument; 

if(app.documents.length != 0){ 
    if(app.selection.length == 1){ 
     try{   
      var frame1 = app.selection[0]; 
      frame1.contents = frame1.contents.toUpperCase(); 
     } 
     catch(e){ 
      alert ("Exception : " + e, "Exception"); 
     } 
    } 
else{ 
    alert ("Please select text", "Selection"); 
    } 
} 
else{ 
    alert("Something wrong"); 
} 

Copie à clipbaord:

var myDoc = app.activeDocument; 

if(app.documents.length != 0){ 
    if(app.selection.length == 1){ 
     try{   
      var selectedStuff = app.selection[0]; 

      //upperCase the selection right away. 
      //If a textFrame is selected, everything in the TextFrame gets upperCased. 
      //If only part of the text is selected, then only part of the text is upperCased. 
      selectedStuff.contents = selectedStuff.contents.toUpperCase(); 
      /////////////// 

      //app.copy(copies the selected Item, not only Text) so find out what's is selected before you shove it onto the clipboard. 
      if(selectedStuff instanceof TextFrame){ 
       //The selected item was a textFrame, a TextFrame can't be pasted into Notepad, so lets select all the text in that frame instead. 
       app.selection = selectedStuff.texts; 
       } 
      //Now copy the selection. At this point, only TEXT should be selected, so pasting should always work. 
      app.copy(); 
     } 
     catch(e){ 
      alert ("Exception : " + e, "Exception"); 
     } 
    } 
else{ 
    alert ("Please select text", "Selection"); 
    } 
} 
else{ 
    alert("Something wrong"); 
} 
+0

ok, cela vous dérangerait-il d'ajouter des codes pour copier le contenu dans le presse-papiers? – Kamotho

+1

'app.copy()' copiera l'élément ** sélectionné ** dans le presse-papiers. Si le ** item ** est un textframe, alors le textFrame est copié dans le presse-papier (ce ** type d'élément ** est seulement connu par Indesign, donc il ne peut être collé que dans inDesign). Si l'élément ** sélectionné ** est du texte dans le textFrame, le texte est copié dans le presse-papiers. Comme une chaîne de texte est juste une chaîne de texte, le ** type d'élément ** est connu de presque tous les programmes qui s'exécutent, par conséquent, votre élément sélectionné/copié peut être collé dans pratiquement tout. Je vais ajouter du code sous peu. –

+0

@KamosKamotho, Ajout de la fonctionnalité clipBoard –