Skip to main content
Participant
April 18, 2022
Answered

Illustrator Script Help

  • April 18, 2022
  • 3 replies
  • 683 views

I'm getting an error at line 10 (see comment that says error). I'm not sure why this is happening. Someone please help.

 

if (!app.homeScreenVisible) {
	app.activeDocument.close(SaveOptions.SAVECHANGES);
}

var myDocument = app.documents.add();
myDocument.layers[0].name = 'BackgroundLayer';

for (var i = 0; i < 500; i++) {
	generateBackground(i);
	fileName = '~/Documents/tempFiles/test' + (i + 1); //error
	console.log(fileName);
	myDocument.exportFile(File(fileName), ExportType.PNG24);
}

function generateBackground(index) {
	var doc = app.activeDocument;
	var background = doc.pathItems.add();
	background.filled = true;

	var bgFillColour = new CMYKColor();
	var cyanNum = (index / (100 * 100 * 100)) | 0;
	var magentaNum = (index / (100 * 100)) | 0;
	var yellowNum = (index / 100) | 0;
	var blackNum = index % 100;

	bgFillColour.cyan = cyanNum;
	bgFillColour.magenta = magentaNum;
	bgFillCoulour.yellow = yellowNum;
	bgFillColour.black = blackNum;

	background.fillColor = bgFillColour;
	background.setEntirePath(
		[0, 0],
		[doc.width, 0],
		[doc.width, doc.height],
		[0, doc.height]
	);
}

 

This topic has been closed for replies.
Correct answer CarlosCanto

I didn't get an error on line 10, but "tempFiles" folder must exists, otherwise nothing happens when you export on Windows. Perhaps mac raises an error?

 

that being said, this line needs to be deleted or commented out

console.log(fileName);

 

there's a typo in the bgFillColour variable name (yellow)

	bgFillCoulour.yellow = yellowNum;
	bgFillColour.black = blackNum;

 

and setEntirePath needs an Array of Arrays, you have four separate arrays

	background.setEntirePath(
		[0, 0],
		[doc.width, 0],
		[doc.width, doc.height],
		[0, doc.height]
	);

 

3 replies

Participant
April 19, 2022

This is all true. My particular problem at line 10 happened to occur because I forgot to initialize fileName, doh. Thank you!

Kukurykus
Legend
April 19, 2022

Mark the correct answer 😉

Participant
April 19, 2022

I mean, technically I have given the correct answer to my particular question. Due to the misorganization of this thread (my fault), I don't think others will find this thread very useful. Is there any way I can have it taken down?

Participant
April 19, 2022

Hi all, your suspicions are confirmed. This script is intended for Illustrator. 🤦‍♂I wrote it for a buddy a lil while back and he's just now testing it. Could I get help with this script with that in mind, or would it be best that I take this post down and post in an illustrator board?

Kukurykus
Legend
April 19, 2022

Just wait one of moderators move it to Illustrator (with Scripting label)

Kukurykus
Legend
April 19, 2022

Are you sure it's Photoshop script? Where does it come from? I have no problem with line 10, but surely with .pathItems.add() you used without arguments. Additionally there's nothing like app.homeScreenVisible, new CMYKColor(), .setEntirePath() and console.log(). It seems some moderator moved it to wrong community.

c.pfaffenbichler
Community Expert
Community Expert
April 19, 2022

And is »filled« a property for Paths in Photoshop? 

Kukurykus
Legend
April 19, 2022

I missed this out 😉 So which Adobe application you think uses these commands?