illustrator javascript导出jpg空格,替换为破折号

illustrator javascript导出jpg空格,替换为破折号,javascript,export,jpeg,adobe-illustrator,Javascript,Export,Jpeg,Adobe Illustrator,我编写了一个脚本将文件导出为jpeg格式。但是,导出时,如果文件名包含空格,则这些空格将替换为短划线。为什么?如果在手册中从Illustrator导出,则文件名将正确显示。如果使用fileJpg.saveDlg;,Dialgue窗口正确显示文件名,但不断用破折号替换空格 function ExportJpgFunction(){ var exportOptions = new ExportOptionsJPEG(); var type = ExportType.JPEG;

我编写了一个脚本将文件导出为jpeg格式。但是,导出时,如果文件名包含空格,则这些空格将替换为短划线。为什么?如果在手册中从Illustrator导出,则文件名将正确显示。如果使用fileJpg.saveDlg;,Dialgue窗口正确显示文件名,但不断用破折号替换空格

function ExportJpgFunction(){
    var exportOptions = new ExportOptionsJPEG();
    var type = ExportType.JPEG;
    var fileJpg = new File('D:\\for Jpg and Eps/' + myWindow.fnamePanel.fileNameText.text + '.jpg');
    fileJpg.saveDlg('');     
    exportOptions.antiAliasing = true;
    exportOptions.qualitySetting = 100;
    exportOptions.verticalScale = 420;
    exportOptions.horizontalScale = 420;
    app.activeDocument.exportFile( fileJpg, type, exportOptions );

您可以使用简单的解决方法,只需使用破折号重命名文件,在代码末尾添加以下行:

var fileJpg1 = new File("c:\\tmp\\for-Jpg-and-Eps.jpg");//path to file with dashes
fileJpg1.rename('for Jpg and Eps.jpg');

这是Illustrator脚本中的错误。要删除它,您必须手动替换。

正如其他人所指出的,这是Adobe Illustrator的一个错误/怪癖

在Adobe Illustrator创建文件名后,我通过删除文件名中的破折号解决了同样的问题

重命名文件“D:\\for Jpg和Eps/'+replaceSwithDashEsmyWindow.fnamePanel.fileNameText.text+'.Jpg',myWindow.fnamePanel.fileNameText.text+'.Jpg'; 函数replaceSwithDashs stringToDash{ //模拟未删除的原始文件中的虚线文件 var dashedString=stringToDash.replace/\s+/g,-; 返回dashedString; } 函数重命名文件fileFromPath,newName{ var b=新的filefrompath; b、 重命名名称;
}恰恰相反。我写的文件名没有破折号,illustrator在导出时添加破折号。我添加了一个清晰的图像。您误解了我的意思,我建议您在illustrator使用重命名功能将文件保存为数据库名称后重命名该文件。