【问题标题】:illustrator javascript export jpg spaces replaced by a dashillustrator javascript 导出 jpg 空格替换为破折号
【发布时间】:2021-01-04 01:53:07
【问题描述】:

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

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 );

enter image description here

【问题讨论】:

    标签: javascript export jpeg adobe-illustrator


    【解决方案1】:

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

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

    【讨论】:

    • 相反。我写的文件名不带破折号,而插图画家在导出时会添加破折号。我添加了一张清晰的图片。
    • 你误会了,我建议你在插画师使用重命名功能保存文件后重命名文件。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      正如其他人所指出的,这是 Adob​​e Illustrator 的错误/怪癖。

      我通过在 Adob​​e Illustrator 创建文件名后从文件名中删除破折号解决了同样的问题。

      renameFile ('D:\\for Jpg and Eps/' + replaceSpacesWithDashes(myWindow.fnamePanel.fileNameText.text) + '.jpg', myWindow.fnamePanel.fileNameText.text + '.jpg');
        
      function replaceSpacesWithDashes (stringToDash) {
          
          //Simulate dashed up files from undashed original 
          var dashedString = stringToDash.replace(/\s+/g, "-");
      
          return dashedString;
      
      }
        
      function renameFile (fileFromPath, newName) {   
      
            var b = new File(fileFromPath);
            b.rename(newName);
            
      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-25
        • 1970-01-01
        • 1970-01-01
        • 2013-01-14
        • 1970-01-01
        • 1970-01-01
        • 2013-12-11
        相关资源
        最近更新 更多