2016-04-01 17 views
1

私はinDesignのスクリプトを開発しました。これはinDesignファイルを1ページずつ1ページずつループし、テキストフレームをスキャンし、テキスト内の特定のコードを見つけ出し、コードごとにチェックしますリスト内にある場合は、スクリプトは次のテキストフレームに渡されない場合、コードの後ろに小さなイメージを挿入します。InDesign Script - テーブルフッターと挿入ポイント

例では、大きな話ことが良好であるため、ここでの例である:コードの後

enter image description here

が挿入この小さな灰色/黒色の画像を有しています。最後のテーブル行のコードを除いて、すべてのコードに対して完全に機能します。

-Scriptはコードを正しく検出しています(スクリプトを使用してテキストを編集することもできます)。 - テーブルのセルには、画像を挿入するのに十分なスペースがあります(さらに高さを高くすることもできます)。 - イメージのサイズを変更しようとしましたが、サイズを小さくしました。 -Theスクリプト

が今ここに

 app.findTextPreferences.findWhat = currentREF; 
     var myFoundItems = app.activeDocument.findText(); 

     for (var bh = 0; bh < myFoundItems.length; bh++) { 


     myLastIns = myFoundItems[bh].insertionPoints.length; 
     myInsPointOk = myFoundItems[bh].insertionPoints[myLastIns - 1]; 

     if (bh == 0) { 
      myTf = myInsPointOk.parentTextFrames[0]; 
     } 

     try { 
      //Insert/place the logo 
      var myImgPath = logoImage; 
      var myBlockImg = myInsPointOk.rectangles.add({strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 1, 1 ]}); 
      myBlockImg.contentType = ContentType.graphicType; 
      myBlockImg.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION; 
      myBlockImg.anchoredObjectSettings.anchorXoffset = 0; 
      myBlockImg.anchoredObjectSettings.anchorYoffset = 0; 
      myBlockImg.place(File(myImgPath)); 
      myBlockImg.fit(FitOptions.FRAME_TO_CONTENT); 
     } catch (e) { 

      //Warning, the code has been find but the script didn't success to insert it 
      $.writeln("La référence " + normalFormatRef + " à été trouvée dans le fichier " + app.activeDocument.name + " mais le script n'à pas réussit à insérer le picto."); 
      arrError.push("La référence " + normalFormatRef + " à été trouvée dans le fichier " + app.activeDocument.name + " mais le script n'à pas réussit à insérer le picto."); 

     } 
     } 
に失敗し、スクリプトの一部である...私は最後のものの後に空行を追加した場合、正しく画像を追加...それは本当に最後の行の問題です

最後の行のテーブルの中に挿入ポイントが見つかりませんでしたが、なぜですか? それとも私が最後で...正しく

を推測していない、ライン上のスクリプトの停止、それは最後の行に画像を追加しようとするたびに...

 var myBlockImg = myInsPointOk.rectangles.add({strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 1, 1 ]}); 

理由です私はそれが失敗する挿入ポイントだと思います。

+0

'..findText(true)'を使うと、見つかった項目のリストを逆順に取得できますか?もしそうなら、私は理由を説明することができます:) – usr2564301

+0

しかし、それは動作しませんでした:( –

答えて

1

あなたの答えのために最初にありがとう! は、その後、私は最終的に解決策を見つけ、私は以下の投稿:

if (myFoundItems[bh].parent.constructor.name == "Cell") { 
 
     //Only for text include in cells, temporary increase the height of the parent's row 
 
     var previousRowHeight = myFoundItems[bh].parent.minimumHeight; 
 
     myFoundItems[bh].parent.minimumHeight = "15mm"; 
 
     myFoundItems[bh].parent.parent.parent.fit(FitOptions.FRAME_TO_CONTENT); 
 
} 
 

 
     var myBlockImg = myFoundItems[bh].parent.insertionPoints[-1].rectangles.add({strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 0.1, 0.1 ]}); 
 
     myBlockImg.contentType = ContentType.graphicType; 
 
     myBlockImg.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION; 
 
     myBlockImg.anchoredObjectSettings.anchorXoffset = 0; 
 
     myBlockImg.anchoredObjectSettings.anchorYoffset = 0; 
 
     myBlockImg.place(File(myImgPath)); 
 
     myBlockImg.fit(FitOptions.FRAME_TO_CONTENT); 
 

 
if (myFoundItems[bh].parent.constructor.name == "Cell") { 
 
     //Only for text include in cells, reset the height of the parent's row 
 
     myFoundItems[bh].parent.minimumHeight = previousRowHeight; 
 
     myFoundItems[bh].parent.parent.parent.fit(FitOptions.FRAME_TO_CONTENT); 
 
}

はしばらくを説明するために、私が見つけたことは、行の高さが十分ではなかったの増加だった、それはまた合うために必要な親のテキストブロック。

0

明らかなことはありません。私はこのアプローチを提案しましょう。私は一般に、スクリプト内のオブジェクトプロパティを編集するのではなく、オブジェクトスタイルを選択します。これにより、スクリプトが実行された後、オブジェクトの外観や位置をユーザが簡単に編集できるようになります。また、フィット・コールを回避します。

var main = function(){ 
 
\t var doc, fgp, cgp, found = [], n = 0, text, parent, rect, os, 
 
\t osProps = { 
 
\t \t \t name:"picto", 
 
\t }, 
 
\t picto = File (Folder.desktop+"/picto.ai"), 
 
\t uip = app.scriptPreferences.properties; 
 
\t 
 
\t if (!app.properties.activeDocument) return; 
 
\t 
 
\t if (!picto.exists) { 
 
\t \t alert("The picto file could't be found!"); 
 
\t \t return; 
 
\t } 
 

 
\t doc = app.activeDocument; 
 
\t fgp = app.findGrepPreferences.properties; 
 
\t cgp = app.changeGrepPreferences.properties; 
 
\t 
 
\t app.findGrepPreferences = app.changeGrepPreferences = null; 
 
\t 
 
\t app.findGrepPreferences.findWhat = "(\\d{2}\\.){4}\\d{2}"; 
 
\t 
 
\t found = doc.findGrep(); 
 
\t n = found.length; 
 
\t 
 
\t if (!n) return; 
 
\t 
 
\t app.scriptPreferences.enableRedraw = false; 
 
\t app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 
 
\t 
 
\t os = doc.objectStyles.item ("picto"); 
 
\t !os.isValid && os = doc.objectStyles.add(osProps); 
 
\t 
 
\t while (n--) { 
 
\t \t text = found[n]; 
 
\t \t parent = text.parent; 
 
\t \t if (parent instanceof Cell 
 
\t \t && parent.parentRow.cells[-1]==parent) { 
 
\t \t \t rect = text.insertionPoints[-1].rectangles.add({geometricBounds: [ 0, 0, 1, 1 ]}); 
 
\t \t \t rect.appliedObjectStyle = os; 
 
\t \t \t rect.place (picto); 
 
\t \t } 
 
\t } 
 
\t 
 
\t app.findGrepPreferences.properties = fgp; 
 
\t app.changeGrepPreferences.properties = cgp; 
 
\t app.scriptPreferences.properties = uip; 
 
} 
 

 
var u; 
 
app.doScript (main, u, u, UndoModes.ENTIRE_SCRIPT, "Add picto");

それはREFをループを回避することができるようまた、私は、テキスト検索のためのテキストの上Grepのを選びました。しかし、refが可変パターンを持っていれば良い一致ではないかもしれません。

The result…

関連する問題