Skip to main content
Participant
August 2, 2021
Question

Illustrator Scripting - Exporting As Wmf Or Calling Plugin

  • August 2, 2021
  • 2 replies
  • 705 views

Hello. I've been trying to utilize the Illustrator CC scripting (ExtendScript) to automate some things; namely user input color revisions. I'm presented with two main problems:

 

1. To truly automate this I'd like to be able to pass information from my database queue to the JSX script. I'd fiddled with VBScript but the passed arguments always come in as undefined when attempting to read. Is there a better way? Preferrably to pass from a .NET console application to the script.

 

2. The main issue: I cannot export my altered AI file as a WMF. The documentation shows that this isn't one of the exposed export types, but I'd really like to see if this is available? (outside of the plugin sdk)

 

3. The last issue is really a possible alternative to #2. I have a plugin that helps export as a wmf. Can I use a script to call that existing plugin?

 

I appreciate any feedback you can offer.

This topic has been closed for replies.

2 replies

Charu Rajput
Community Expert
Community Expert
August 2, 2021

Hi,

I am not sure about your point no. 1. It seems it is possible but unfortunately currently out of my scope. But for your second point, you can use action to export in the format WMF. Here is the below snippet where I have used action string to export in WMF format.

 

var dest = Folder(Folder.desktop);

function main() {

    String.prototype.hexEncode = function () {
        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 actionStr = [
        "/version 3",
        "/name [ 5",
        "	5365742031",
        "]",
        "/isOpen 1",
        "/actionCount 1",
        "/action-1 {",
        "	/name [ 8",
        "		416374696f6e2031",
        "	]",
        "	/keyIndex 0",
        "	/colorIndex 0",
        "	/isOpen 1",
        "	/eventCount 1",
        "	/event-1 {",
        "		/useRulersIn1stQuadrant 0",
        "		/internalName (adobe_exportDocument)",
        "		/localizedName [ 9",
        "			4578706f7274204173",
        "		]",
        "		/isOpen 1",
        "		/isOn 1",
        "		/hasDialog 1",
        "		/showDialog 0",
        "		/parameterCount 7",
        "		/parameter-1 {",
        "			/key 1885434477",
        "			/showInPalette 0",
        "			/type (raw)",
        "			/value < 4",
        "				00000000",
        "			>",
        "			/size 4",
        "		}",
        "		/parameter-2 {",
        "			/key 1851878757",
        "			/showInPalette 4294967295",
        "			/type (ustring)",
        "			/value [ PUT_FOLDERPATH_CHAR_LENGTH_HERE",
        "				PUT_HEX_FOLDERPATH_HERE",
        "			]",
        "		}",
        "		/parameter-3 {",
        "			/key 1718775156",
        "			/showInPalette 4294967295",
        "			/type (ustring)",
        "			/value [ 16",
        "				57696e646f7773204d65746166696c65",
        "			]",
        "		}",
        "		/parameter-4 {",
        "			/key 1702392942",
        "			/showInPalette 4294967295",
        "			/type (ustring)",
        "			/value [ 3",
        "				776d66",
        "			]",
        "		}",
        "		/parameter-5 {",
        "			/key 1936548194",
        "			/showInPalette 4294967295",
        "			/type (boolean)",
        "			/value 0",
        "		}",
        "		/parameter-6 {",
        "			/key 1935764588",
        "			/showInPalette 4294967295",
        "			/type (boolean)",
        "			/value 1",
        "		}",
        "		/parameter-7 {",
        "			/key 1936875886",
        "			/showInPalette 4294967295",
        "			/type (ustring)",
        "			/value [ 0",
        "			]",
        "		}",
        "	}",
        "}",
    ].join("\n");

    if (app.documents.length == 0) {
        return;
    }


    var destStr = decodeURI(dest.fsName);
    var actionFileDestStr = Folder.desktop + "/MyAction.aia";
    writeFile(actionFileDestStr, actionStr.replace("PUT_FOLDERPATH_CHAR_LENGTH_HERE", destStr.length).replace("PUT_HEX_FOLDERPATH_HERE", destStr.hexEncode()));
    var actionFile = File(actionFileDestStr);
    app.loadAction(actionFile);
    app.doScript("Action 1", "Set 1");


    //clean up 
    actionFile.remove();
    app.unloadAction("Set 1", '');
};

main();

 

 

Best regards
Participant
August 2, 2021

Thank you! I was able to get an exported wmf using this verbatim. Depending on the AI file in question the output WMF can't be opened though. The errored output was created in Document Color Mode: CMYK, while the other was in RGB color mode. Switching to RGB Color Mode and exporting again doesn't work. This is likely a little too specific to me to request any more info from you though, but I thought I'd just bring it up. Thanks again.

Charu Rajput
Community Expert
Community Expert
August 9, 2021

@defaultcx9zzp3fvwu1 

It may be because I have recorded the action for CMYK mode document. I am not 100% sure,

Could you please attach you ai file, so that we can update the actions as required.

Best regards
Mylenium
Legend
August 2, 2021

Without exactly telling people what plug-in you use and what code bits nobody can tell you much. The handover failures may simply be formatting issues that could be fixed easily and the plug-in may simply need some specific API hooks to work. There are people around here who could help with both (not me), but you really have to be much more specific and actually give them something they can jump on and point out what may be wrong.

 

Mylenium

Participant
August 2, 2021

 

Dim appRef
Dim javaScriptFile
Dim argsArr()

Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
Dim jsxFile : Set jsxFile = fsObj.OpenTextFile("pathtojsxfilehere", 1, False)
Dim fileContents : fileContents = jsxFile.ReadAll
jsxFile.Close
Set jsxFile = Nothing
Set fsObj = Nothing

javascriptFile = fileContents & "main(arguments);"

Set appRef = CreateObject( "Illustrator.Application" )

ReDim argsArr(Wscript.Arguments.length-1)

For i = 0 To Wscript.Arguments.length-1
    argsArr(i) = Wscript.Arguments(i)
Next

Wscript.Echo appRef.DoJavaScript(javascriptFile, argsArr, 1)

Above is a sample of my efforts to pass information from vbscript to the jsx file.

One of the first lines of the extendscript is:

alert(arguments[0]);

 for the sake of simply showing the contents of the first argument I'd pass, but the script only returns undefined. Is that helpful?