Illustrator-在文本路径脚本中批量插入文件名会导致Illustrator崩溃
Illustrator - batch insert filename in textpath script crashes Illustrator
首先:我不是程序员。只是摆弄代码,并试图让它为特定任务工作:
这是我制作的一个脚本,目的是在600多个pdf文件中插入一个带有文件名的文本。假设这适用于选定文件夹中的所有文件。
问题是:Illustrator崩溃了。
第一个测试代码,在几个编辑过的文件Illustrator崩溃后,所以我试图在每次保存后引入延迟,以减缓批处理过程。
$.setTimeout(函数(){sourceDoc.close(SaveOptions.SAVECHANGE)},1000);
不知道下一步该做什么。如果我删除以下行,代码就会工作:sourceDoc.close(SaveOptions.SAVECHANGE);
以下是完整的脚本:
var destFolder, sourceFolder, files, fileType, sourceDoc, layers, writeText, finLabel;
// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );
// If a valid folder is selected
if ( sourceFolder != null )
{
files = new Array();
fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', '*.pdf' );
// Get all files matching the pattern
files = sourceFolder.getFiles( fileType );
if ( files.length > 0 )
for ( i = 0; i < files.length; i++ )
{
sourceDoc = app.open(files[i]); // returns the document object
layers = unlock();
writeText = getFilename();
finLabel = remText();
sourceDoc.close(SaveOptions.SAVECHANGES); //if save command line is deleted the code works WTF???
$.setTimeout(function () {sourceDoc.close(SaveOptions.SAVECHANGES)}, 1000); // still crashes using delay ...
}
//alert( 'Files are saved as PNG in ' + destFolder );
else
{
alert( 'No matching files found' );
}
}
function unlock()
{
//get the total number of layers in the active document
doc = app.activeDocument;
var totalLayers = doc.layers.length;
//looping on layers to create one artboard per layer
for ( var i = 0 ; i < totalLayers ; i++){
var currentLayer = doc.layers[i];
//We don't want to deal with hidden layers
if(currentLayer.visible == false) continue;
//Unlock the layer if needed
currentLayer.locked = false;
}
}
function getFilename()
{
// Write text
var pointTextRef = app.activeDocument.textFrames.add();
pointTextRef.contents = app.activeDocument.name + "'n" + "YBS";
pointTextRef.top = 0;
pointTextRef.left = 0;
app.activeDocument.textFrames[0].textRange.characterAttributes.textFont=app.textFonts[31];
}
function remText()
{
// This works for search and replace :))))))
var active_doc = app.activeDocument;
var search_string = /_Template.pdf/gi; // g for global search, remove i to make a case sensitive search
var replace_string = '';
var text_frames = active_doc.textFrames;
if (text_frames.length > 0)
{
for (var i = 0 ; i < text_frames.length; i++)
{
var this_text_frame = text_frames[i];
var new_string = this_text_frame.contents.replace(search_string, replace_string);
if (new_string != this_text_frame.contents)
{
this_text_frame.contents = new_string;
}
}
}
}
关于Illustrator崩溃的原因有什么想法吗?
注意:打开第一个文件后,应用程序崩溃。
谢谢你的帮助!
删除此行后:
$.setTimeout(function () {sourceDoc.close(SaveOptions.SAVECHANGES)}, 1000);
代码在一批中处理了499个文件:)
原来Illustrator在试图保存损坏的pdf时崩溃了。
@fabiantheblind谢谢你的帮助!
有些事情你应该改变并尝试:
- 扩展脚本中没有
$.setTimeout
- 检查文件过滤器是否真的有效(
getFiles(FileType)
) - 函数
unlock()
、getFilename()
和remText()
没有返回值,因此不需要将它们的结果传递到变量中 - 试试你的pdf文件的一个子集,而不是全部600个
- 将
var
添加到for循环for(var i = 0; i < ...)
- 尝试从文件列表
for (var i = files.length; i >= 0; i-- ){}
的末尾执行for
循环
相关文章:
- TableExport jquery插件:文件名和扩展名问题
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- 通过javascript下载文件时设置文件名
- location.reload(true)崩溃浏览器选项卡
- 引导程序崩溃一次只能看到一个
- Grunt构建导致Angular应用程序在dist上崩溃
- jquery扩展了崩溃效率
- JS-使用Ajax获取文件名
- 根据HTML文件名授予web服务器写入权限
- AngularJS-如何列出给定文件夹中的文件名
- 为什么这个For循环会使浏览器实验室崩溃
- PHP 包括 Javascript 生成的文件名
- 在csv文件名中使用西班牙语字符
- 引导崩溃具有快照抖动
- 试图在Photoshop JSX脚本中将画布大小导出为文件名
- 如何设置浏览器打开的文件对话框的文件名(一些默认值)
- 如何将动态文件名传递给ng-include
- 引导程序导航栏崩溃问题
- jQuery Mobile点击数据崩溃
- Illustrator-在文本路径脚本中批量插入文件名会导致Illustrator崩溃