2017-02-20 4 views
1

以下のように編集、元のコピー: 半機能スクリプトを作成できました。私は、多くの不満を抱きながら、構文エラーがテキスト編集の印であることを認識しました。それはいくつかのファイルを再リンクし、通常はエラーで終了するという点で、半完成します。数回のループの後に "placedArtは存在しません"。私は、XMLがファイル内に存在するよりも多くの「stRef:filePath」を見つけるように感じています。例:2つのイメージを持つファイルは、それぞれ2回のファイルパスを検索します。任意のヒント?イラストレーターedit link filepath via javascript

var counter = 0; 
var doc = app.activeDocument; 
var x = new XML(doc.XMPString); 
var m = x.xpath('//stRef:filePath'); 
if (m !== '') { 
    for (var i=0, len=m.length(); i < len ; i++) { 
    var link_path = m[i]; 
    if (File(link_path).exists === false) { 
    link_path = link_path.split('/Projects').join('/Volumes/Projects') 
    link_path = link_path.split('O:').join('/Volumes/Projects'); 
    link_path = link_path.split('P:').join('/Volumes/Projects'); 
    link_path = link_path.split('\\SERVER').join('Volumes'); 
    link_path = link_path.split("\\").join("/"); 

    if (File(link_path).exists === true){ 
     placedArt = app.activeDocument.placedItems[i]; 
     placedArt.relink(new File (link_path));} 
    alert(File(link_path).fsName); 
    counter++; 
    } 

};} 

if (counter > 0) { 
    alert("Attempted to relink " + counter + " links");} 
else { 
    alert("No links replaced");} 



オーケーを投稿orginal、私は非常に経験の浅いXMLんだけど、私は、スクリプトを使用してAdobe Illustratorでリンクファイルパスの部分を編集しようとしています。以下は私がこれまで持っているものです:

var doc = app.activeDocument; 
var x = new XML(doc.XMPString); 
var m = x.xpath('//stRef:filePath'); 
if (m !== '') { 
    for (var i=0, len=m.length(); i < len ; i++) { 
    var link_path = m[i]; 
    if (File(link_path).exists === false) { 
     var link_path2 = String(link_path) 
     link_path2 = link_path2.replace(‘%5C’, ‘/‘) 
     alert(File(link_path2)); 
    } 
}; 
} 

これはエラーを返します:8構文エラー。 link_path2 = link_path2.replace( '%5C'、 '/')の行にあります。だから、このよう

link_path2 = 'cow'; 

として、link_path2を再定義しようとする試みを行います私は現在、XML typeofを返しlink_path varが再定義のための問題であるという事実を仮定すると、文字列に変換しlink_path2するlink_pathを変更していますまたは値を編集します。

最後の目標は、WindowsサーバパスからmacOSファイルパスにファイルパスを編集して、スクリプトが壊れたリンクを修正することです。私はこれを数時間探し、行き止まりを打ち続ける。

答えて

0

XML/XMPデータがこれを行うための最良の方法であるとは限りません。私たちは、あるサーバーから別のサーバーにリンクされたイメージを交換する際に、当社のリンクされたファイルに同様の問題がありました。各AIファイルが開き、配置されたアイテムが検索され、イメージが新しいパスに再リンクされます。私はこれをPC上でしか使用していないので、Macのパスがなくても動作するかどうかはわかりませんが、試してみることができます。

いつも同じ2つのファイルパスを使用していますか、そのたびに一意に選択しますか?

// Select the source folder. 
var destFolder, sourceFolder, files, fileType, doc, targetFile, pngExportOpts; 

if (app.documents.length == 0){ 
sourceFolder = Folder.selectDialog('Select the folder with Illustrator files you want to relink', '~'); 

    // If a valid folder is selected 
    if (sourceFolder != null){ 
     files = new Array(); 
     // Get all files matching the filetype 
     files = sourceFolder.getFiles("*.ai"); 

     if (files.length > 0) { 

      for (i = 0; i < files.length; i++){ 
       doc = app.open(files[i]); // returns the document object 
       changeExt(); 
       if (app.documents.length != 0){ 
        doc.save(); 
        doc.close(); 
       } 
      } 
     } 
    } 
} 
else{ 
    changeExt(); 
    } 



function changeExt(){ 

var i; 
var doc = app.activeDocument; 

if (doc.placedItems.length != 0){ 
    for (i=0;i<doc.placedItems.length;i++) { 
     //gets the full path of the image 
    var imageName = doc.placedItems[i].file.fsName; 
    var imageURL = doc.placedItems[i].uRL; 
    var imagePath; 

    var newPath; 

    var i, in_file, out_file; 
     //if the scan is placed for the first time it uses the drive letter 
     //this swaps the drive letters to the server names so they can be replaced properly 
     if (imageName.match(/O:/)){ 
     imagePath = imageName.replace("O:", "\\\\Serv01\\Projects1") 
     imageName = imagePath; 

     } 
     else (imageName.match(/P:/)){ 
     imagePath = imageName.replace("P:", "\\\\Serv02\\Projects2") 
     imageName = imagePath; 
     } 

    if (imageName.match(/Serv02/)){ 
     imagePath = imageName.replace("Serv02", "Serv01") 
     activePath = imagePath.replace("Projects2", "Projects1"); 
     newPath = File(activePath); 
      if (newPath.exists){//copies scan over if it doesn't exist. 
       doc.placedItems[i].file = newPath; 
      } 
      else{ 
       in_file = doc.placedItems[i].file; 
       out_file = File(activePath); 
       in_file.copy(out_file); 
       doc.placedItems[i].file = out_file; 
      } 
     } 
    else{ 
     imagePath = imageName.replace("Serv01", "Serv02") 
     activePath = imagePath.replace("Projects1", "Projects2"); 
     newPath = File(activePath); 
     if (newPath.exists){//copies scan over if it doesn't exist. 
       doc.placedItems[i].file = newPath; 
      } 
      else{ 
       in_file = doc.placedItems[i].file; 
       out_file = File(activePath); 
       in_file.copy(out_file); 
       doc.placedItems[i].file = out_file; 
      } 
     } 

} 
} 
else{ 
    doc.close(SaveOptions.DONOTSAVECHANGES); 
    } 

} 
+0

これをさらに詳しく調べて、これを私のものと混ぜてみる必要があります。私は実際には、配置されたアイテムとXMLの組み合わせを使って半機能バージョンを持っていました。私は編集する.fsname、.url、または.file.nameを持たない壊れたリンクのplacesItemsの問題に直面していました(警告は[配置されたアイテム]または未知数を示しています)。多分これはプラットフォームの問題の変更ですが、私は開いているファイルを再リンクしていました。未開封のファイルを再リンクする必要があります。残念ながら、ここのサーバーはクラスタFであり、まれに同じ2つのパスを含みます。 いずれにしても、あなたは私にテスト/探索の新しいルートを与えてくれました、merçibeaucoup。 – KernelPan1c

0

その場合:あなたはあなただけ交換したい2つの設定サーバーパスをお持ちの場合は、(私はあなたが最初の場所とファイルの保存先を選ぶ同様のものを持っている)、このようなものを使用することができます開始点と終了点が異なる場合は、ある場所から別の場所へのリンクを含むファイルを転送するためにこのようなスクリプトを使用し、開始場所と目的地を選択することができます。もう一度、それがMac用にはうまくいくとは思わないが、おそらくこれがあなたを助けるかもしれない。私たちのセットアップでは、グラフィックスを1つのフォルダに保存して別のフォルダにスキャンするので、ファイルパスを1つのフォルダにまとめておく必要があります。そのため、ルートフォルダーがあり、そのフォルダー内に「グラフィックス」フォルダーと「スキャン」フォルダーがあります。

これはまた、ファイルのスキャンが行方不明になっているため、最後にエラーリストに表示されるので、どのファイルに画像がないかを知ることができます。

これはいくつか役立ちます。

// Select the source folder. 
sourceFolder = Folder.selectDialog('Select the GRAPHICS folder with Illustrator files you want to move', '~'); 

var export_folderSelect = Folder.selectDialog("Select the root folder (NOT GRAPHICS) to move the Illustrator files to"); 
var export_folder = export_folderSelect + "/Graphics"; 

var errorList = []; 

var destFolder, sourceFolder, files, fileType, doc, targetFile, pngExportOpts; 

var save_options = new IllustratorSaveOptions(); 
save_options.embedICCProfile = true; 
save_options.pdfCompatible = true; 

// If a valid folder is selected 
if (sourceFolder != null && export_folderSelect != null){ 
files = new Array(); 

// Get all files matching the pattern 
files = sourceFolder.getFiles("*.ai"); 

if (files.length > 0){ 
// Get the destination to save the files 
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; 
    for (i = 0; i < files.length; i++){ 
     //try to open the file and move it over, otherwise note it in the error list. 
     var docOpened = true; 
     try{ 
      doc = app.open(files[i]); // returns the document object 
      } 
     catch(e){ 
      errorList.push(files[i].name + " !!!CORRUPT - NOT COPIED!!!"); 
      docOpened = false; 
      } 
     try{ 
      moveFile(); 
      } 
     catch(e){ 
       if (docOpened == true){ 
       doc.close(); 
       } 
     } 
    } 
} 

if (errorList.length > 0){ 
    alert("COPY THIS LIST TO WORD: " + errorList); 
    } 
else{ 
    alert("Woo hoo! No errors!"); 
    } 
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS; 
} 

function moveFile(){ 

const FILE_SUFFIX = ""; 

const ASSET_SUFFIX = ""; 

var doc = app.activeDocument; 

if (!doc.saved) doc.save(); 

var original_file = doc.fullName; 
var extension = ""; 

var arr = doc.name.split("."); 
if (arr.length>1) extension = "." + arr.pop(); 

var filename = arr.join("."); 

var assets_folder = new Folder(export_folderSelect + "/Scans"); 

if (assets_folder.exists || assets_folder.create()) { 

      var f, in_file, out_file; 

      for (f=0;f<doc.placedItems.length;f++) { 

        try{ 
         in_file = doc.placedItems[f].file; 

         out_file = File(assets_folder+"/"+in_file.name); 

         in_file.copy(out_file); 

         doc.placedItems[f].file = out_file; 
        } 
        catch(e){ 
          errorList.push(files[i].name + " SCAN MISSING"); 
         } 


      } 

      for (g=0;g<doc.rasterItems.length;g++) { 

        if (doc.rasterItems[g].embedded == false) { 

          try{ 
          in_file = doc.rasterItems[g].file; 

          out_file = File(assets_folder+"/"+in_file.name); 

          in_file.copy(out_file); 

          doc.rasterItems[g].file = out_file; 
          } 
         catch(e){ 
          errorList.push(files[i].name + " SCAN MISSING"); 
          } 
         } 

      } 
      // save as new file 

      packaged_file = File(export_folder + "/" + filename + FILE_SUFFIX + extension); 


      doc.saveAs(packaged_file, save_options); 

      doc.close(); 



      // re-open the original file 

      //app.open(File(original_file)); 



} else { 
      alert("Unable to create the assets folder."); 
} 
} 
0

これはあなたの質問に直接答えませんが、あなたの問題を解決するか、他の人に役立つかもしれません。

全く異なる解決策があります。

Illustratorでは、文書と同じフォルダ内の「リンク」フォルダ内にアートワークが見つからない場合があります。

定期的にプロジェクトを移動する必要がある場合は、Artファイルを「リンク」フォルダに保存して、リンクを破損することなくAIファイルを開くことができます。

0

なぜこれにXMPデータを使用していますか?ドキュメント内に配置されたすべての配置アイテムを取得し、リンクが存在するかどうかをチェックし、存在しない場合は新しいファイルにリンクし直すことができます。ここには小さなスクリプトがあります

var activeDocument = app.activeDocument; 
var links = activeDocument.placedItems; 
for (var i = 0; i < links.length; i++) { 
    try { 
     var file = links[i].file; 
     if (file && file.exists) { 
      // Do anything as oer your requirement if link exists. 
     } 
    } catch (e) { 
     // if link missing relink with new_File 
     links[i].relink(File(new_File)); 
    } 
} 

リンクが見つからない場合にリンクを再リンクすると、ドキュメントXMPで自動的に更新されます。