passing string to Illustrator for parameters

Hi Folks-

I’m trying to speed up an illustrator script by passing it an entire set of plotting coordinates at once, by putting them into a string:


set xList to "{100,100},{100,0},{100,100},{104.736842105263,100},{104.736842105263,0},{104.736842105263,100},{109.473684210526,100},{109.473684210526,0},{109.473684210526,100}" (etc..)


however, when I ask illustrator:


	tell application "Adobe Illustrator"
		tell document 1
			make new path item at layer "Layer 1" with properties {entire path:xList, stroke width:3.5, name:"newPoint", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true} --	
		end tell
	end tell

it adds in the quotation marks and yields:


make new path item at layer "Layer 1" of document 1 with properties {entire path:"{100,100},{100,0},{100,100},{104.736842105263,100},{104.736842105263,0},{104.736842105263,100},{109.473684210526,100},{109.473684210526,0},{109.473684210526,100},

…and the leading quotation mark appears to be giving me an error. Does anyone know how to strip out the initial and ending quotation marks? (illustrator CS2, btw)

thanks!

Ralph

I’m thinking that your error may not be coming from the quotation marks”which shouldn’t actually exist without a backslash in front of them”but from the fact that lists of lists are passed in brackets.

set xList to {{100, 100}, {100, 0}, {100, 100}, {104.736842105263, 100}, {104.736842105263, 0}, {104.736842105263, 100}, {109.473684210526, 100}, {109.473684210526, 0}, {109.473684210526, 100}}

Thanks for the reply Marc!

the working syntax really is:

tell application "Adobe Illustrator"
	make new document with properties {color space:CMYK}
	tell document 1
		make new path item at layer "Layer 1" with properties {entire path:{{100, 100}, {100, 200}}, stroke width:3.5, name:"newPoint", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true} --	
	end tell
end tell

this syntax works with CS2/3

-Ralph

I’m striking out on the coercion front. My latest attempt is to embed a shell script into the illustrator call that will strip out the leading and trailing quotation marks:

set xList to "{100, 100}, {100, 150}, {100, 100}, {150, 100}, {150, 150}, {150, 100}, {200, 100}, {200, 150}"

do shell script "echo " & xList & " |/usr/bin/grep -o '^{}$'"

however, this isn’t returning anything. Does anyone know what the proper syntax of the grep expression is?

thanks,

Ralph

Ralph:

This works in CS.

set xList to {{100, 100}, {100, 150}, {100, 100}, {150, 100}, {150, 150}, {150, 100}, {200, 100}, {200, 150}}
tell application "Illustrator CS"
	make new document with properties {color space:CMYK}
	tell document 1
		make new path item at layer "Layer 1" with properties {entire path:xList, stroke width:3.5, name:"newPoint", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true} --	
	end tell
end tell

Jim Neumann
BLUEFROG

that’s it. brilliant. I had been building it as a STRING, and I need to be building it as a LIST of LISTS! Each one of the pairs is a mini-list.

thanks so much!!!

:smiley:

-Ralph

No problem, Ralph. I’ve actually never seen it done the way you’re doing it. I’ve always built my paths as {entire path:{class:path point info, anchor:{100,200},left direction:{100,200}, right direction:{110,210}, point type:smooth},.} You end up with a lot of braces but you can also control curves this way.

Have fun!
Jim

In case anyone’s curious, here’s the working result.

Again, I needed to take a list of values, and plot them as a histogram, and passing each pair line segment to Illustrator was taking several seconds per graph, which was too slow with the number of graphs we were processing.

Taking a list in the form of:

		"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,0,

where the first item is an identifier, I perform the following:

	(* creates explicit ticklist*)
	set xList to {}
	set xposition to 100
	set x to 1
	repeat (count of newList) times
		set pairlist to {}
		set end of pairlist to xposition
		set end of pairlist to (((item x of newList) * 8) + 100)
		set end of xList to pairlist
		set pairlist to {}
		set end of pairlist to xposition
		set end of pairlist to 100
		set end of xList to pairlist
		set pairlist to {}
		set end of pairlist to xposition + theScale
		set end of pairlist to 100
		set end of xList to pairlist
		set x to x + 1
		set xposition to xposition + theScale
	end repeat
	(*creates explicit ticklist*)

which gets passed to Illustrator:

		make new path item at layer "Layer 1" with properties {entire path:xList, stroke width:3.5, name:"newPoint", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true} --	plots data

and yields:

	make new path item at layer "Layer 1" of document 1 with properties {entire path:{{100, 100}, {100, 100}, {104.761904761905, 100}, {104.761904761905, 100}, {104.761904761905, 100}, {109.52380952381, 100}, {109.52380952381, 100}, {109.52380952381, 100}, {114.285714285714, 100}, {114.285714285714, 100}, {114.285714285714, 100}, {119.047619047619, 100}, {119.047619047619, 100},{1000.000000000005, 100}}, stroke width:3.5, name:"newPoint", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
		path item 1 of layer 1 of document 1

so, instead of plotting a lot of hash marks, it writes one “rake” of data, where the the x-axis connects the individual data points.

thanks again for helping me figure this out, Bluefrog and Marc!

-Ralph