This is a long shot, but is there a possible way to store a JavaScript (or any sort of executable code) within an Adobe Illustrator file?
The reason I'm asking this is because I'm currently trying to automate the process of importing render results from Autodesk Maya. The concept is that as soon Maya is done rendering all frames/layers, a MEL script could generate a file that Illustrator could open and run commands found in it, directing illustrator to the render results and start importing them.
The original idea was to give a system command via MEL script to launch Illustrator straight away after rendering completion and somehow start the process. But since this automation is for not-so-tech-savvy people, an application calling for the launch of another one would be rather frustrating and maybe confusing.
Having Maya generate a file that can complete the task when the user opens it is a much preferred solution. Give more control to the user and does not overload a system that is already busy with more application calls.
Think of it like a .mel file, where upon opening, it launches the needed application (Maya) and when the application is ready, carries out the commands included (MEL). Is there a way to do that with Adobe applications, Illustrator in particular, where a file automatically is recognized as an Illustrator file (eg. .ai), launches application and then runs code contained in it (eg. JS)?
ANY help is welcomed, but I would like to avoid applescripts/VBS as they are platform specific and can be difficult to manage between Mac/Windows.
Thanks.
This is a relatively broad question as there can be many ways to achieve this.
I'll try to give you one possible solution here, it clearly might not be the best.
Your needs:
Create a "file" or something that imports all the Maya's rendered images in an illustrator scene.
Can be executed whenever you want (No post render process that opens illustrator)
Non-tech people like my mom have to be able to use it.
Cross-platform (Win/Osx)
Solution:
Create a post-render script (mel or python) for Maya
Concerning this script (.mel or .py):
Is run once all frames have been rendered
Copies an existing JavaScript (.jsx) file in the folder where the frames have been rendered
Creates two executable files (.bat and .command, both for Windows and OSX)
Concerning the .jsx file:
Creates a new .ai file
Imports the rendered frames one by one and adds them in a new artboard
Saves the .ai file in the current folder
Concerning the .bat and .command executables:
Run Illustrator
Execute the .jsx script on startup
To sum up, once the frames will have been rendered, all three files (.jsx, .bat, .command) will be created in the same folder as the frames.
When your artists will want to create their Illustrator scene, they'll just have to double click on the .bat or .command file to automatically run Illustrator and import the rendered frames and save the file.
The command to run a script on Illustrator (CS 5.1) on Windows is and this will be the content of the .bat file:
"C:\Program Files (x86)\Adobe\Adobe Illustrator CS5.1\SupportFiles\Contents\Windows\Illustrator.exe" C:\Path\To\Script.jsx
You can easily make an equivalent for the .command file.
Script.jsx can be something like this:
// Get the fullpath of the script
var script_fullpath = $.fileName
// Only get the folder path
var script_folder = Folder(script_fullpath).path
// Get renderred frames
var rendered_frames = Folder(script_folder).getFiles("*.exr");
if(rendered_frames.length == 0){
alert("No images to import");
}else{
// Loop through all the images
// Create a new artbook
// Import Fram
// Then save the file here: script_folder + "/" + "illustratorFile"
}
Related
I am using VUE and JavaScript to develop an educational 2D game engine for the purpose of teaching kids game design. The breakdown of how I plan on it working is as follows:
VUE based editor is used to create game content
The actual engine is written in pure JS
When the "play," button is clicked in the editor, a function from the engine run_debug(inputGameData) is called which returns specific errors to the editor process for it to handle if they appear IE: Display error message and highlight location in editor that the error occurred.
When the "export," button is clicked in the editor, the game data and engine are packaged together in a single HTML file to be run as a stand-alone application.
The editor is almost completed, which means I'm now thinking more about the engine side of things. What I'm really scratching my head about is how I should distribute the two on the server without having multiple duplicates of the engine; one version that is generated with the HTML wrapper template, and one that is imported into the VUE application to be run-able from the editor.
I see a few solutions to this off the top of my head, but all have drawbacks:
Distribute all separate versions on the server. This will cause a longer page load and hurts my insides as a programmer due to how inefficient this feels
Dynamically build the engine from source at export/run time in whichever version is needed. This would cause problems as one of my goals for accessibility is having the editor able to run locally on a machine, and browsers currently don't handle local file reading too well without having to mess about with permissions.
Import the HTML5 wrapped version into the VUE app on build, and somehow both call it from the engine (in an Iframe or similar) and be able to read it as text so I can insert the game data on export and download it to the user's machine. I have absolutely no clue how to do this using VUE.
It's a weird niche problem so I'm having some difficulty finding resources on the topic. If anyone has experience in this subject matter I appreciate any help/direction you can give or point me to
Here's the solution I ended up coming up with (basically option #3 from above, just slightly modified):
Create build system for the engine that generates a engine.js file where the contents of the file is stored in the format of:
let engineCode = 'engineCodeHere';
let sharedCode = 'code shared between engine and editor goes here';
import the engine.js file into the vue editor and on initial load, put the code into <script> tags
const engineTag = document.createElement('script');
const sharedTag = document.createElement('script');
engineTag.id = 'engineCode';
sharedTag.id = 'sharedCode';
engineTag.innerHTML = engineCode;
sharedTag.innerHTML = sharedCode;
document.body.appendChild(engineTag);
document.body.appendChild(sharedTag);
engineCode = null;
sharedCode = null;
once they are imported as script tags the original variables are cleared so we're not story duplicate data in memory.
Now, not only do I have access to the runnable js code as if I had imported it normally, but I also have the added benefit of being able to get that code as text so I can use it when packaging the final game "executable."
let engineText = document.getElementById('engineCode').innerHTML;
let sharedText = document.getElementById('sharedCode').innerHTML;
This will allow me to pack the engine just a single time, instead of once as JS and once as text. For added efficiency I can even hold off creating the engine tag until the game is run in the editor to save on resources.
I'm working on a file management system built with node.js and electron.
The file management displays a list of files in a folder and allows the user to run custom commands to batch process the files, such as renaming, custom grouping ect...
However I want to implement a feature that if the user clicks on a file it will open with the text editor of their choice.
I can't get the sublime text editor (or any for that matter) to open with node.js code.
I have looked into other questions here on SO such as "Launch an external application from node.js" and "Is it possible to execute an external program from within node.js?" but none of the answers successfully work for me.
Most of the answers open the file with the "default" program of the operating system which is not what I want. I want to be able to choose the program that opens the file.
I found this code below that calls on global path variables to open external software from node:
const exec = require("child_process").exec
exec('yourApp').unref()
But of course it doesn't work if you replace 'yourApp' with a file path pointing to sublime_text.exe like so:
var exec = require('child_process').exec;
exec('C:/Program Files/Sublime Text 3/sublime_text.exe').unref()
Any help would be very very much appreciated. Thank you
You need to use this as your path:
C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
I figured it out. It turns out it takes a little bit more code than I first posted to open an external file. The full code looks like this:
// Create a child process
var spawn = require('child_process').spawn;
var child = spawn('Path_To_.exe', ['parameters', 'Path_To_File']);
Also just in case anyone is wondering it was not necessary to escape sequence the spaces within the file name.
Thank you for everyone who offered to help!
When I try to load a very large file using the appropriate loaders provided with the library, the tab my website runs in crashes. I have tried implementing the Worker class, but it doesnt seem to work. Heres what happens:
In the main javascript file I have:
var worker = new Worker('loader.js');
When user selects one of available models I check for the extension and pass the file URL/path to the worker: (in this instance a pcd file)
worker.postMessage({fileType: "pcd", file: file});
Now the loader.js has the appropriate includes that are necessary to make it work:
importScripts('js/libs/three.js/three.js');
importScripts('js/libs/three.js/PCDLoader.js');
and in its onmessage method, it uses the apropriate loader depending on file extension.
var loader = new THREE.PCDLoader();
loader.load(file, function (mesh) {
postMessage({points: mesh.geometry.attributes.position.array, colors: mesh.geometry.attributes.color.array});
});
The data is passed back successfully to the main javascript which adds it to the scene. At least for small files - large ones, like I said, take too long and the browser decides there was an error. Now I thought the worker class was supposed to work asynchronously, so whats the deal here?
Currently Three.js's loaders rely on strings and arrays of strings to parse data from a file. They dont split files into pieces, which leads to excessive memory usage which browsers immediately interrupt. Loading a 64 MB file spikes to over 1 GB memory used during load (which then results in an error).
I want do save a mirror of www.youtube.com/tv. I obviously do not want to save the videos. I want the code running the website in a local copy, everything else can stay remote. The code I want is mainly contained in 2 files: live.js and app-prod.js.
I tried using httrack. I have issue parsing the javascript to load anything past the first file: live.js. The %P parameter does not help.
httrack www.youtube.com/tv +* -r6 --mirror -%P -j
It doesn't go further than live.js because some javascript needs to be executed to load the next file.
I know I can do this manually with any browser. I want to automate the process.
Is httrack able to do this by itself?
If yes, how?
Short version: can you help me fill in this code?
var conkeror_settings_dir = ".conkeror.mozdev.org/settings";
function load_all_js_files_in_dir (dir) {
var full_path = get_home_directory().appendRelativePath(dir);
// YOUR CODE HERE
}
load_all_js_files_in_dir(conkeror_settings_dir);
Background
I'm trying out Conkeror for web browsing. It's an emacs-like browser running on Mozilla's rendering engine, using javascript as configuration language (filling the role that elisp plays for emacs). In my emacs config, I have split my customizations into a series of files, where each file is a single unit of related options (for example, all my perl-related settings might be in perl-settings.el. All these settings files are loaded automatically by a function in my .emacs that simply loads every elisp file under my "settings" directory.
I am looking to structure my Conkeror config in the same way, with my main conkeror-rc file basically being a stub that loads all the js files under a certain directory relative to my home directory. Unfortunately, I am much less literate in javascript than I am in elisp, so I don't even know how to "source" a file.
I found a suitable answer, though it isn't really what I was looking for. If you set your conkerorrc file to a directory, then all the js files in that dir will be loaded.