Skip to main content
Participant
October 16, 2024
Question

Script works on one device but not another (Error -54)

  • October 16, 2024
  • 2 replies
  • 383 views

Hi, I have a script which works fine on my device, but not on the device of the person I made the script for, both devices are windows and using the same Illustrator version. The script fails on the file opening section. Here is the error message they get:

Error 1200: an Illustrator error occured: -54 (ÿÿÿÊ)

The code for the script is below.

Any help would be appreciated, thanks.

 

 

var input = 'G:/Shared drives/Creative Drive/Test Input';
var output = 'G:/Shared drives/Creative Drive/Test Output';
var inputFolder = Folder(input);
var outputFolder = Folder(output);
var theFiles = inputFolder.getFiles();
var thePath = outputFolder.path;
main();
function main(){
	if (theFiles) {
		for (var m = 0; m < theFiles.length; m++) { 
			var filename = theFiles[m].name.toString();
			if (filename.indexOf(".ai") > 0){
				var splits = filename.split("_");
				var fileRef = new File( input+'/'+filename );
				var doc_a = app.open(fileRef);
				var illustratorDoc = app.activeDocument;

				// Select everything in the Illustrator document
				illustratorDoc.selectObjectsOnActiveArtboard();

				// Copy selected objects
				app.copy();
				// Launch Photoshop
				var psApp = null;

				try {
					// Try to get a reference to Photoshop
					psApp = BridgeTalk.getSpecifier("photoshop");
			
					// If Photoshop isn't running, launch it
					if (!psApp) {
						var photoshopApp = new File(app.path + "/../Adobe Photoshop/Photoshop.exe");
						photoshopApp.execute();
						$.sleep(3000); // Wait for Photoshop to launch
					}
				} catch (e) {
					alert("Error: Unable to communicate with Photoshop.");
				}
				if (splits[1].toUpperCase() == "A6"){
					var psWidth = "2719";
					var psHeight = "1987"; 
				}
				else if (splits[1].toUpperCase() == "7X5"){
					var psWidth = "3275";
					var psHeight = "2375"; 
				}
				else if (splits[1].toUpperCase() == "SQ"){
					var psWidth = "4404";
					var psHeight = "2340"; 
				}

				// Create a new Photoshop document
				var bt = new BridgeTalk();
				bt.target = "photoshop";
				var nam = filename.replace(".ai","")
				bt.body = "app.documents.add("+psWidth+", "+psHeight+", 300, '"+nam+"');"; // Adjust dimensions/resolution as needed
				bt.send(5);

				// Now paste the Illustrator contents into Photoshop
				bt.body = "app.activeDocument.paste();";
				bt.send(5);

				// Specify the path to the Photoshop script file
				var scriptFilePath = 'G:/Shared drives/Creative Drive/PS Script.jsx';
				// Read the contents of the script file
				var scriptFile = new File(scriptFilePath);
				scriptFile.open('r');
				var scriptContents = scriptFile.read();
				scriptFile.close();

				// Execute the Photoshop script
				bt.body = scriptContents;
				bt.send(300);
			}
		}
	}
}

 

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
October 16, 2024

Hi @Ohh Deer, great script. Unfortunately I have no idea why it is throwing the error. I had a search around and there was another case where app.paste() was giving error 1200.

 

Can I just double-check: is there a reason why you can't script this in Photoshop as normal place linked (or embedded) images? That would seem to avoid the complexities of BridgeTalk.

 

If that doesn't work in your case, a more robust approach might be to export the .ai document's artboard(s) either as .ai (or maybe as .psd?) and then Photoshop does the place linked command. I'm only exploring this because I always avoid app.copy/paste if I can help it, especially if I am handing the script off to someone else.

- Mark

Ohh DeerAuthor
Participant
October 16, 2024

Unfortunetly I've not found a way around not using bridge script yet, I need to preserve the layers and layer names from the illustrator file which so far the only way I've got working is copying and pasting from illustrator to photoshop.  Exporting as a PSD with write layers and maximum editability doesnt seem to preserve the layers

m1b
Community Expert
Community Expert
October 16, 2024

Interesting! When I run your script, it sometimes fails on the first try saying something about [Paste] menu is not available. It works on second and subsequent times, but it doesn't preserve layers—I get a single layer with Illustrator content combined always called "Layer 1", even with basic appearances. I'm on MacOS though, so maybe the copy/paste works differently.

 

Exporting as a PSD with write layers and maximum editability doesnt seem to preserve the layers

 

It depends on your artwork. It will flatten anything that it thinks it needs to flatten to preserve the appearance. Certain things (sorry I can't remember what they are) *always* cause the flattening and avoiding them in your artwork will prevent the flattening. Still, no help if you must have those things.

- Mark

Doug A Roberts
Community Expert
Community Expert
October 16, 2024

Do both machines have the same mapping for G drive?

Ohh DeerAuthor
Participant
October 16, 2024

Yes they do