Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Unable to encode sub folder path for dynamic actions

Community Beginner ,
Oct 28, 2018 Oct 28, 2018

I was wondering if anyone ran into this issue in the past and if anyone has ideas how to get this to work. I am trying to create a dynamic action but currently running into an issue where Illustrator is not recognizing the folder Path to convert using hex encoding.

I think the issue is due to the need for writing subfolders and the use of "\" within folder path. If I place the code $.write(folderPath) ===> C:UsersDesktopconvert1convert2convert3

Unfortunately, the action will only work if the folder path is encoded as so: "C:Users\Desktop\convert1\convert2\convert3" 

Any ideas?

#target illustrator

main(["C:Users\Desktop\convert1\convert2\convert3" , "794107-00101"]);

 

function main(argv) { 

  var folderPath = argv[0];

  var fileName = argv[1];

 

  var doc= app.activeDocument; 

 

        String.prototype.hexEncode = function(){

            var hex, i;

            var result = "";

            for (i=0; i<this.length; i++) {

                hex = this.charCodeAt(i).toString(16);

                result += (""+hex).slice(-4);

                }

            return result

            }

       

        hexcode =fileName.toString();   

        hexcode = fileName.hexEncode();

        exportPV(folderPath)

        //doc.close( SaveOptions.DONOTSAVECHANGES ); 

        }

   

/*================

Export PV Files

================*/

function exportPV(fileDest){ 

    String.prototype.hexEncode = function(){  

        //http://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex  

        var hex = '';  

        for(var i=0;i<this.length;i++) {  

            hex += ''+this.charCodeAt(i).toString(16);  

            }  

        return hex;  

        }; 

   

    function writeFile(fileDestStr, contents){  

        var newFile = File(fileDestStr);  

        newFile.open('w');  

        newFile.write(contents);

        newFile.close();  

        };  

var newFileDestination = fileDest

var actionString = [ 

'/version 3',

'/name [ 7',

'436f6e76657274', //Convert

']',

'/isOpen 1',

'/actionCount 1',

'/action-1 {',

'/name [ 9',

'4578706f7274205056', //Export PV

']',

'/keyIndex 0',

'/colorIndex 0',

'/isOpen 1',

'/eventCount 1',

'/event-1 {',

'/useRulersIn1stQuadrant 0',

'/internalName (adobe_exportDocument)',

'/localizedName [ 9',

'4578706f7274204173', //Export As

']',

'/isOpen 0',

'/isOn 1',

'/hasDialog 1',

'/showDialog 0',

'/parameterCount 6',

'/parameter-1 {',

'/key 1851878757',

'/showInPalette -1',

'/type (ustring)',

'/value [ charLength', 

'/placeFileDest', 

']',

'}',

'/parameter-2 {',

'/key 1718775156',

'/showInPalette -1',

'/type (ustring)',

'/value [ 14',

'50756c73652050562046696c6573', //Pulse PV Files

']',

'}',

'/parameter-3 {',

'/key 1702392942',

'/showInPalette -1',

'/type (ustring)',

'/value [ 2',

'5056',

']',

'}',

'/parameter-4 {',

'/key 1936548194',

'/showInPalette -1',

'/type (boolean)',

'/value 0',

'}',

'/parameter-5 {',

'/key 1935764588',

'/showInPalette -1',

'/type (boolean)',

'/value 1',

'}',

'/parameter-6 {',

'/key 1936875886',

'/showInPalette -1',

'/type (ustring)',

'/value [ 1',

'31',

']',

'}',

'}',

'}',

  

].join('\n');  

 

if(app.documents.length == 0){  

    return; 

    }

var actionFileDestStr = Folder.desktop + "/MyAction.aia"; 

writeFile(actionFileDestStr, actionString.replace("charLength", newFileDestination.length).replace("placeFileDest", newFileDestination.hexEncode()));  

var actionFile = File(actionFileDestStr);  

app.loadAction(actionFile);  

app.doScript("Export PV", "Convert"); 

if(app.activeDocument.selection != null && app.activeDocument.selection.length > 0){ 

    app.doScript("Export PV", "Convert"); 

    }

//clean up  

//actionFile.remove(); 

//app.unloadAction("Convert", ''); // thanks qwertyfly! 

}; 

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 31, 2018 Oct 31, 2018

Salut !

Je suis navré que tu n'aies pas pris au sérieux ma proposition car elle fonctionne correctement

même dans ton propre script.

Voici les dossiers traités :

"h:\\temp\\Images\\"

"c:\\Garmin\\"

"k:\\bm2005\\"  // clé USB

"k:\\Travail 01\\New Document Profiles\\"  // clé USB

"\\\\MAISON\\Users\\All Users\\GARMIN\\" // réseau

"e:\\convert1\\convert2\\convert3\\"

"E:\\convert1\\convert2\\convert3\\"

Ce dernier chemin n'a pas fonctionné, pas de message d'erreur mais le script pointe vers le répertoire cou

...
Translate
Adobe
Community Beginner ,
Oct 28, 2018 Oct 28, 2018

I am getting close but will need some advice on how to handle the next part. Since I am using a command line to retrieve folder paths, I am going to pass in the hex-encoded file path instead of text.

It seems Illustrator have no problem converting a hex back to a text. So I have created a function to convert a hex back to text so I can obtain the correct character length. Below is what I have now.

How can I successfully write in the var = charLength, and var = folderPath into the action successfully?

#target illustrator

main(["433a5c55736572735c6c616e67757965345c4465736b746f705c436f6e766572745c4e657720666f6c646572", "794107-00101"]);

 

function main(argv) { 

  var folderPath = argv[0];

  var fileName = argv[1];

 

 

function hexToString(hex) {

    var hex = hex.toString();//force conversion

    var str = '';

    for (var i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2)

        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));

    return str;

}

$.write(hexToString(folderPath)); // returns filePath

var charLength = hexToString(folderPath).length

$.write(charLength); // returns filePath

function writeFile(fileDest, contents){  

        var newFile = File(fileDest);  

        newFile.open('w');  

        newFile.write(contents);

        newFile.close();  

        };  

var actionString = [ 

'/version 3',

'/name [ 7',

'436f6e76657274', //Convert

']',

'/isOpen 1',

'/actionCount 1',

'/action-1 {',

'/name [ 9',

'4578706f7274205056', //Export PV

']',

'/keyIndex 0',

'/colorIndex 0',

'/isOpen 1',

'/eventCount 1',

'/event-1 {',

'/useRulersIn1stQuadrant 0',

'/internalName (adobe_exportDocument)',

'/localizedName [ 9',

'4578706f7274204173', //Export As

']',

'/isOpen 0',

'/isOn 1',

'/hasDialog 1',

'/showDialog 0',

'/parameterCount 6',

'/parameter-1 {',

'/key 1851878757',

'/showInPalette -1',

'/type (ustring)',

'/value [ ', + charLength + '/', + folderPath + ']',

'}',

'/parameter-2 {',

'/key 1718775156',

'/showInPalette -1',

'/type (ustring)',

'/value [ 14',

'50756c73652050562046696c6573', //Pulse PV Files

']',

'}',

'/parameter-3 {',

'/key 1702392942',

'/showInPalette -1',

'/type (ustring)',

'/value [ 2',

'5056',

']',

'}',

'/parameter-4 {',

'/key 1936548194',

'/showInPalette -1',

'/type (boolean)',

'/value 0',

'}',

'/parameter-5 {',

'/key 1935764588',

'/showInPalette -1',

'/type (boolean)',

'/value 1',

'}',

'/parameter-6 {',

'/key 1936875886',

'/showInPalette -1',

'/type (ustring)',

'/value [ 1',

'31',

']',

'}',

'}',

'}',

  

].join('\n');  

if(doc.length == 0){  

    return; 

    }

var actionFileDestStr = Folder.desktop + "/MyAction.aia"; 

writeFile(actionFileDestStr, actionString.charLength, actionString.folderPath);  

var actionFile = File(actionFileDestStr);  

app.loadAction(actionFile);  

app.doScript("Export PV", "Convert"); 

if(app.activeDocument.selection != null && app.activeDocument.selection.length > 0){ 

    app.doScript("Export PV", "Convert"); 

    }

//clean up  

actionFile.remove(); 

app.unloadAction("Convert", '');

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 28, 2018 Oct 28, 2018

Salut !

Je pense à :

main(["C:Users\\Desktop\\convert1\\convert2\\convert3" , "794107-00101"]);

hexa.PNG

de LR

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 28, 2018 Oct 28, 2018

Did you encode this with javascript using ExtendScript Toolkit? If so can you provide a sample code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 28, 2018 Oct 28, 2018

Looks like I figured it out. Had to review some of Silly-V code examples but finally got it to work. Below is the code in case anyone runs into the same issue.

#target illustrator

main(["433a5c55736572735c6c616e67757965345c4465736b746f705c436f6e766572745c4e657720666f6c646572", "794107-00101"]);

 

function main(argv) {

    var folderPath = argv[0];

    var fileName = argv[1];

   

    function hexToString(hex) {

        var hex = hex.toString();//force conversion

        var stringChar = '';

       

        for (var i = 0; (i < hex.length && hex.substr(i, 2) !== '00'); i += 2)

        stringChar += String.fromCharCode(parseInt(hex.substr(i, 2), 16));

       

        return stringChar;

        }

      

    $.write(hexToString(folderPath)); // returns filePath

    var hexLength = hexToString(folderPath).length

    $.write(hexLength); // returns filePath

   

    exportPV(hexLength, folderPath)

    }

function exportPV(NOTE_VALUE1, NOTE_VALUE2){

   

    String.prototype.hexEncode = function() {  

        //http://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex  

        var hex = '';  

        for(var i=0;i<this.length;i++) { 

            hex += ''+this.charCodeAt(i).toString(16);  

            }

        return hex;  

        }

   

    function writeFile(fileDestStr, contents){  

        var newFile = File(fileDestStr);  

        newFile.open('w');  

        newFile.write(contents);  

        newFile.close();  

        }

 

var actionString = [

'/version 3',

'/name [ 7',

'436f6e76657274', //Convert

']',

'/isOpen 1',

'/actionCount 1',

'/action-1 {',

'/name [ 9',

'4578706f7274205056', //Export PV

']',

'/keyIndex 0',

'/colorIndex 0',

'/isOpen 1',

'/eventCount 1',

'/event-1 {',

'/useRulersIn1stQuadrant 0',

'/internalName (adobe_exportDocument)',

'/localizedName [ 9',

'4578706f7274204173', //Export As

']',

'/isOpen 0',

'/isOn 1',

'/hasDialog 1',

'/showDialog 0',

'/parameterCount 6',

'/parameter-1 {',

'/key 1851878757',

'/showInPalette -1',

'/type (ustring)',

'/value [ PUT_NOTE_VALUE_CHAR_LENGTH_HERE',

'/PUT_HEX_NOTE_VALUE_HERE',

' ]',

'}',

'/parameter-2 {',

'/key 1718775156',

'/showInPalette -1',

'/type (ustring)',

'/value [ 14',

'50756c73652050562046696c6573', //Pulse PV Files

']',

'}',

'/parameter-3 {',

'/key 1702392942',

'/showInPalette -1',

'/type (ustring)',

'/value [ 2',

'5056',

']',

'}',

'/parameter-4 {',

'/key 1936548194',

'/showInPalette -1',

'/type (boolean)',

'/value 0',

'}',

'/parameter-5 {',

'/key 1935764588',

'/showInPalette -1',

'/type (boolean)',

'/value 1',

'}',

'/parameter-6 {',

'/key 1936875886',

'/showInPalette -1',

'/type (ustring)',

'/value [ 1',

'31',

']',

'}',

'}',

'}',

  

].join('\n');  

if(app.documents.length == 0){  

    return;  

    }

var actionFileDestStr = Folder.desktop + "/MyAction.aia"; 

writeFile(actionFileDestStr, actionString.replace("PUT_NOTE_VALUE_CHAR_LENGTH_HERE", NOTE_VALUE1).replace("PUT_HEX_NOTE_VALUE_HERE", NOTE_VALUE2));  

var actionFile = File(actionFileDestStr);  

app.loadAction(actionFile);  

app.doScript("Export PV", "Convert"); 

//clean up  

actionFile.remove(); 

app.unloadAction("Test", ''); // thanks qwertyfly! 

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 28, 2018 Oct 28, 2018

I was going to suggest, try the forward-slashes instead of the Windows-style backward ones.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 28, 2018 Oct 28, 2018

I thought of using the forward-slashes in the beginning. But then I would receive this error. This was when I noticed the file path for the Export As command within the actionscript was using the Windows-style backward one. I figured it was another strange anomaly of Illustrator I happen to stumble on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2018 Oct 31, 2018

Salut !

Je suis navré que tu n'aies pas pris au sérieux ma proposition car elle fonctionne correctement

même dans ton propre script.

Voici les dossiers traités :

"h:\\temp\\Images\\"

"c:\\Garmin\\"

"k:\\bm2005\\"  // clé USB

"k:\\Travail 01\\New Document Profiles\\"  // clé USB

"\\\\MAISON\\Users\\All Users\\GARMIN\\" // réseau

"e:\\convert1\\convert2\\convert3\\"

"E:\\convert1\\convert2\\convert3\\"

Ce dernier chemin n'a pas fonctionné, pas de message d'erreur mais le script pointe vers le répertoire courant :

"c:\\Users\\René\\Desktop\\convert1\\convert2\\convert3\\"

la raison est le caractère é de René (codage à creuser ?)

De LR elleere

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 31, 2018 Oct 31, 2018

Okay, I see what you have done now. Thank you for explaining this. It appears to work for me as well. Much quicker than inputting a hex-encoded file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 06, 2018 Nov 06, 2018
LATEST

Additional Information.
J’aimerais savoir quelle est la finalité de ton script, ce que tu veux faire exactement ?
J’ai indiqué dans le message précédent que le chemin "c:\\Users\\René\\Desktop\\convert1\\convert2\\convert3\\" n’était pas pris en compte par ton script, la raison est la présence du caractère «é» de code ASCII 233 qui donne en hex E9 mais ne convient pas car il faut utiliser pour l’encodage la norme UTF8.

La fonction hexEncode de ton script n’est pas adaptée, elle ne converti correctement que les code ASCII de 32 à 126.
Autre exemple : Le caractère « € » (euro) dont le code est ASCII 8364, converti en hexadécimal 20AC ne convient pas ?
Pour éditer ce caractère on utilise ALT+0128 et 128 en hexadécimal vaut 80 ne convient pas ?
Pour finir « € » (euro) caractère UNICODE s’encode  sur 3 octets : 226, 130, et 172  en décimal est  E282AC en hexadécimal.
Sachant que pour un nom de dossier (Windows) seuls les caractères \/:*?<>| sont interdits, il convient de modifier cette fonction.
Pour un résultat correct, se reporter aux deux exemples cités plus bas.

newFileDestination placeFileDest                                                          charLength   newfiledestHex

h:\€                         683a5ce282ac (3octets)                                         6 au lieu de 4 pour newFileDestination
C:\Users\René       433a5c55736572735c52656ec3a9 (2 octets)      14 au lieu de 13

Ce qui implique pour "charLength" de déterminer la valeur à partir du la longueur du code hexadecimal/2 (nombre d’octets) et ainsi éviter le message d’erreur que tu as cité (29oct).

var newfiledestHex = hexEncode(newFileDestination);
writeFile(actionFileDestStr, actionString.replace("charLength", newfiledestHex.length/2). replace("placeFileDest", newfiledestHex));


Si tu veux un script qui fonctionne avec liste prédéfinie de chemins et une ligne de saisie pour un nouveau chemin ou ??? Me contacter par mail

De LR elleere

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines