Plaqued by 'Expression too long' error Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ralf_Reddings200244
Posts: 94
Joined: 11 Mar 2023, 14:16

Plaqued by 'Expression too long' error

Post by Ralf_Reddings200244 » 26 Mar 2024, 15:33

I am working on two functions, GetToolbar() and SetToolbar() to control Adobe Illustrator's toolbar panel in a much more efficient way and to implement features such as spring loaded tools, which illustrator still does not have.

I figured out everything I am just stuck on this error I that AutoHotkey is throwing at me:

Code: Select all

: ==> Expression too long
AutoHotkey closed for the following exit code: 2
The way both functions work, is that they associate a x and y (coordinates) value with each tool on the toolbar. Illustrator has about 90 tools, and I would like to declare all of them:

Code: Select all

setToolbar("Lasso")
setToolbar(toolName){
	toolIndex:=	{"Selection"				:	{x:17, y:47}
					,"directSelection"		:	{x:47, y:47}
					,"groupSelection"			:	{x:17, y:47}
					,"MagicWand"				: 	{x:47, y:71}
					,"Lasso"			 			:	{x:17, y:95}
					,"Artboard"			 		:	{x:47, y:95}
					,"FreeTransform"			: 	{x:17, y:119}
					,"Pen"			 			:	{x:47, y:119}
					,"AddAnchorPoint"			: 	{x:17, y:143}
					,"DeleteAnchorPoint"		:	{x:47, y:143}
					,"AnchorPoint"				:	{x:17, y:167}
					,"Curvature"		 		:	{x:47, y:167}
					,"LineSegment"				:	{x:17, y:191}
					,"Arc"			 			:	{x:47, y:191}
					,"RectangularGrid"		:	{x:17, y:215}
					,"PolarGrid"				:	{x:47, y:215}
					,"Spiral"			 		:	{x:17, y:239}
					,"Flare"			 			:	{x:47, y:239}
					,"Rectangle"				:	{x:17, y:263}
					,"RoundedRectangle"		:	{x:47, y:263}
					,"Ellipse"			 		:	{x:17, y:287}
					,"Star"			 			:	{x:47, y:287}
					,"Polygon"			 		:	{x:17, y:311}
					,"Type"			 			:	{x:47, y:311}
					,"VerticalType"			: 	{x:17, y:335}
					,"VerticalAreaType"		:	{x:47, y:335}
					,"TypeOnPath"				:	{x:17, y:359}
					,"TouchType"				:	{x:47, y:359}
					,"VerticalTypeOnPath"	:	{x:17, y:383}
					,"AreaType"			 		:	{x:47, y:383}
					,"Pencil"			 		:	{x:17, y:407}
					,"Paintbrush"				:	{x:47, y:407}
					,"PathEraser"				:	{x:17, y:431}
					,"BlobBrush"				:	{x:47, y:431}
					,"Smooth"			 		:	{x:17, y:455}
					,"Shaper"			 		:	{x:47, y:455}
					,"Join"			 			:	{x:17, y:479}
					,"SymbolSprayer"			: 	{x:47, y:479}
					,"SymbolShifter"			: 	{x:17, y:503}
					,"SymbolScruncher"		:	{x:47, y:503}
					,"SymbolSizer"				:	{x:17, y:527}
					,"SymbolSpinner"			: 	{x:47, y:527}
					,"SymbolStainer"			: 	{x:17, y:527}
					,"SymbolScreener"			: 	{x:47, y:527}
					,"SymbolStyler"			: 	{x:17, y:575}
					,"ColumnGraph"				:	{x:47, y:575}
					,"StackedColumnGraph"	:	{x:17, y:599}
					,"BarGraph"			 		:	{x:47, y:599}
					,"StackedBarGraph"		:	{x:17, y:623}
					,"LineGraph"				:	{x:47, y:623}
					,"AreaGraph"				:	{x:17, y:647}
					,"ScatterGraph"			: 	{x:47, y:647}
					,"PieGraph"			 		:	{x:17, y:671}
					,"RadarGraph"				:	{x:47, y:671}
					,"Slice"			 			:	{x:17, y:695}
					,"SliceSelection"			: 	{x:47, y:695}
					,"Rotate"			 		:	{x:17, y:719}
					,"PerspectiveGrid"		:	{x:47, y:719}
					,"PerspectiveSelection"	:	{x:17, y:743}
					,"LivePaintSelection"	:	{x:47, y:743}
					,"Width"			 			:	{x:17, y:767}
					,"Mesh"			 			:	{x:47, y:767}
					,"Gradient"			 		:	{x:17, y:791}
					,"Crystallize"				:	{x:47, y:791}
					,"ShapeBuilder"			: 	{x:17, y:815}
					,"LivePaintBucke"			: 	{x:47, y:815}
					,"PuppetWarp"				:	{x:17, y:839}
					,"Warp"			 			:	{x:17, y:839}
					,"Reshape"			 		:	{x:17, y:863}
					,"Twirl"			 			:	{x:17, y:863}
					,"Reflect"			 		:	{x:17, y:887}
					,"Scale"			 			:	{x:17, y:887}
					,"Pucker"			 		:	{x:17, y:911}
					,"Shear"			 			:	{x:17, y:911}
					,"Bloat"			 			:	{x:17, y:935}
					,"Scallop"			 		:	{x:17, y:935}
					,"Eraser"			 		:	{x:17, y:959}
					,"Eyedropper"				:	{x:17, y:959}
					,"Blend"			 			:	{x:17, y:983}
					,"Scissors"			 		:	{x:17, y:983}
					,"Knife"			 			:	{x:17, y:191}
					,"Measure"			 		:	{x:17, y:191}
					,"Wrinkle"			 		:	{x:17, y:1031}
					,"RotateView"				:	{x:17, y:1031}
					,"PrintTiling"		 		:	{x:17, y:935}
					,"Hand"			 			:	{x:17, y:935}
					,"Zoom"			 			:	{x:17, y:1079}}

	print(toolIndex[toolName].x, toolIndex[toolName].y)   ; --> 17, 95
}
Attempting to run the above fails with Error:

Code: Select all

: ==> Expression too long
AutoHotkey closed for the following exit code: 2
I can run it if I shorten it to something like this:

Code: Select all

setToolbar("Lasso")
setToolbar(toolName){

	toolIndex:=	{"Selection"				:	{x:17, y:47}
					,"directSelection"		:	{x:47, y:47}
					,"groupSelection"			:	{x:17, y:47}
					,"MagicWand"				: 	{x:47, y:71}
					,"Lasso"			 			:	{x:17, y:95}
					,"Artboard"			 		:	{x:47, y:95}}

	print(toolIndex[toolName].x, toolIndex[toolName].y)
	}
It gets even worse in the case of getToolbar(), as I need to check what the active tools is and return a tool name, x, and y value back to the caller. But the expression runs over 50 lines long:

Code: Select all

getToolbar(){
	hwnd	:= winExist("Toolbar ahk_class OWL.Dock ahk_exe Illustrator.exe")
	pixel_getColor("ahk_id" hwnd, "BDBDBD",x, y)

	activeTool	:= (x = 17 && y = 47)	? {tool : "Selection",					x:17, y:47}
					:	(x = 47 && y = 47)	? {tool : "directSelection",			x:47, y:47}
					:	(x = 17 && y =	71)	? {tool : "groupSelection",			x:17, y:47}
					:	(x = 47 && y =	71)	? {tool : "MagicWand", 					x:47, y:71}
					:	(x = 17 && y =	95)	? {tool : "Lasso", 						x:17, y:95}
					....
					....
					:	(x = 17 && y =	1031)	? {tool : "RotateView", 				x:17, y:1031}
					:	(x = 17 && y =	935)	? {tool : "PrintTiling", 				x:17, y:935}
					:	(x = 17 && y =	935)	? {tool : "Hand", 						x:17, y:935}
					:	(x = 17 && y =	1079)	? {tool: "Zoom", 							x:17, y:1079}
					:""
	return activeTool
}
I solved it breaking the expression into parts using an if block but this is not desirable at all:

Code: Select all

getToolbar(){
	hwnd	:= winExist("Toolbar ahk_class OWL.Dock ahk_exe Illustrator.exe")
	pixel_getColor("ahk_id" hwnd, "BDBDBD",x, y)

	activeTool	:= (x = 17 && y = 47)	? {tool : "Selection",					x:17, y:47}
							:	(x = 47 && y = 47)	? {tool : "directSelection",			x:47, y:47}
							:	(x = 17 && y =	71)	? {tool : "groupSelection",			x:17, y:47}
							...
							:	(x = 17 && y =	239)	? {tool : "Spiral", 						x:17, y:239}
							:	(x = 47 && y =	239)	? {tool : "Flare", 						x:47, y:239}
		if (!activeTool){
			activeTool	:= (x = 17 && y =	263)	? {tool : "Rectangle", 					x:17, y:263}
							:	(x = 47 && y =	263)	? {tool : "RoundedRectangle", 		x:47, y:263}
							...
							:	(x = 17 && y =	455)	? {tool : "Smooth", 						x:17, y:455}
							:	(x = 47 && y =	455)	? {tool : "Shaper", 						x:47, y:455}
		}if (!activeTool){
			activeTool	:=	(x = 17 && y =	479)	? {tool : "Join", 						x:17, y:479}
							:	(x = 47 && y =	479)	? {tool : "SymbolSprayer", 			x:47, y:479}
							...
							:	(x = 17 && y =	671)	? {tool : "PieGraph", 					x:17, y:671}
							:	(x = 47 && y =	671)	? {tool : "RadarGraph", 				x:47, y:671}
		}if (!activeTool){
			activeTool	:=	(x = 17 && y =	695)	? {tool : "Slice", 						x:17, y:695}
							:	(x = 47 && y =	695)	? {tool : "SliceSelection", 			x:47, y:695}
							...
							:	(x = 17 && y =	887)	? {tool : "Reflect", 					x:17, y:887}
							:	(x = 17 && y =	887)	? {tool : "Scale", 						x:17, y:887}
		}if (!activeTool){
			activeTool	:=	(x = 17 && y =	911)	? {tool : "Pucker", 						x:17, y:911}
							:	(x = 17 && y =	911)	? {tool : "Shear", 						x:17, y:911}
							....
							:	(x = 17 && y =	1031)	? {tool : "RotateView", 				x:17, y:1031}
							:	(x = 17 && y =	1079)	? {tool: "Zoom", 							x:17, y:1079}
							:""
							}
	return activeTool
	}

I searched quite a bit and have not turned up with anything. Is there a way forward here?

Thanks for any help.

ShatterCoder
Posts: 77
Joined: 06 Oct 2016, 15:57

Re: Plaqued by 'Expression too long' error  Topic is solved

Post by ShatterCoder » 26 Mar 2024, 16:01

the issue you have here is not the size of the object, but the size of the argument you are trying to pass to the initial array assignment. There is a max string length that you can pass to the array in one go. An easy way around that is to do the opposite:

Code: Select all

setToolbar("Lasso")
return
setToolbar(toolName){
	toolIndex:=	{ }
                    toolIndex["Selection"]				:=	{x:17, y:47}
					toolIndex["directSelection"]		:=	{x:47, y:47}
					toolIndex["groupSelection"]			:=	{x:17, y:47}
					toolIndex["MagicWand"]				:=	{x:47, y:71}
					toolIndex["Lasso"]			 			:=	{x:17, y:95}
					toolIndex["Artboard"]			 		:=	{x:47, y:95}
					toolIndex["FreeTransform"]			:= 	{x:17, y:119}
					toolIndex["Pen"]			 			:=	{x:47, y:119}
					toolIndex["AddAnchorPoint"]			:= 	{x:17, y:143}
					toolIndex["DeleteAnchorPoint"]		:=	{x:47, y:143}
					toolIndex["AnchorPoint"]				:=	{x:17, y:167}
					toolIndex["Curvature"]		 		:=	{x:47, y:167}
					toolIndex["LineSegment"]				:=	{x:17, y:191}
					toolIndex["Arc"]			 			:=	{x:47, y:191}
					toolIndex["RectangularGrid"]		:=	{x:17, y:215}
					toolIndex["PolarGrid"]				:=	{x:47, y:215}
					toolIndex["Spiral"]			 		:=	{x:17, y:239}
					toolIndex["Flare"]			 			:=	{x:47, y:239}
					toolIndex["Rectangle"]				:=	{x:17, y:263}
					toolIndex["RoundedRectangle"]		:=	{x:47, y:263}
					toolIndex["Ellipse"]			 		:=	{x:17, y:287}
					toolIndex["Star"]			 			:=	{x:47, y:287}
					toolIndex["Polygon"]			 		:=	{x:17, y:311}
					toolIndex["Type"]			 			:=	{x:47, y:311}
					toolIndex["VerticalType"]			:= 	{x:17, y:335}
					toolIndex["VerticalAreaType"]		:=	{x:47, y:335}
					toolIndex["TypeOnPath"]				:=	{x:17, y:359}
					toolIndex["TouchType"]				:=	{x:47, y:359}
					toolIndex["VerticalTypeOnPath"]	:=	{x:17, y:383}
					toolIndex["AreaType"]			 		:=	{x:47, y:383}
					toolIndex["Pencil"]			 		:=	{x:17, y:407}
					toolIndex["Paintbrush"]				:=	{x:47, y:407}
					toolIndex["PathEraser"]				:=	{x:17, y:431}
					toolIndex["BlobBrush"]				:=	{x:47, y:431}
					toolIndex["Smooth"]			 		:=	{x:17, y:455}
					toolIndex["Shaper"]			 		:=	{x:47, y:455}
					toolIndex["Join"]			 			:=	{x:17, y:479}
					toolIndex["SymbolSprayer"] := 	{x:47, y:479}
					toolIndex["SymbolShifter"]			:= 	{x:17, y:503}
					toolIndex["SymbolScruncher"]		:=	{x:47, y:503}
					toolIndex["SymbolSizer"]				:=	{x:17, y:527}
					toolIndex["SymbolSpinner"]			:= 	{x:47, y:527}
					toolIndex["SymbolStainer"]			:= 	{x:17, y:527}
					toolIndex["SymbolScreener"]			:= 	{x:47, y:527}
					toolIndex["SymbolStyler"]			:=	{x:17, y:575}
					toolIndex["ColumnGraph"]				:=	{x:47, y:575}
					toolIndex["StackedColumnGraph"]	:=	{x:17, y:599}
					toolIndex["BarGraph"]			 		:=	{x:47, y:599}
					toolIndex["StackedBarGraph"]		:=	{x:17, y:623}
					toolIndex["LineGraph"]				:=	{x:47, y:623}
					toolIndex["AreaGraph"]				:=	{x:17, y:647}
					toolIndex["ScatterGraph"]			:= 	{x:47, y:647}
					toolIndex["PieGraph"]			 		:=	{x:17, y:671}
					toolIndex["RadarGraph"]				:=	{x:47, y:671}
					toolIndex["Slice"]		 			:=	{x:17, y:695}
					toolIndex["SliceSelection"]			:= 	{x:47, y:695}
					toolIndex["Rotate"]			 		:=	{x:17, y:719}
					toolIndex["PerspectiveGrid"]		:=	{x:47, y:719}
					toolIndex["PerspectiveSelection"]	:=	{x:17, y:743}
					toolIndex["LivePaintSelection"]	:=	{x:47, y:743}
					toolIndex["Width"]			 			:=	{x:17, y:767}
					toolIndex["Mesh"]			 			:=	{x:47, y:767}
					toolIndex["Gradient"]			 		:=	{x:17, y:791}
					toolIndex["Crystallize"]				:=	{x:47, y:791}
					toolIndex["ShapeBuilder"]			:= 	{x:17, y:815}
					toolIndex["LivePaintBucke"]			:= 	{x:47, y:815}
					toolIndex["PuppetWarp"]				:=	{x:17, y:839}
					toolIndex["Warp"]			 			:=	{x:17, y:839}
					toolIndex["Reshape"]			 		:=	{x:17, y:863}
					toolIndex["Twirl"]			 			:=	{x:17, y:863}
					toolIndex["Reflect"]			 		:=	{x:17, y:887}
					toolIndex["Scale"]			 			:=	{x:17, y:887}
					toolIndex["Pucker"]			 		:=	{x:17, y:911}
					toolIndex["Shear"]			 			:=	{x:17, y:911}
					toolIndex["Bloat"]			 			:=	{x:17, y:935}
					toolIndex["Scallop"]			 		:=	{x:17, y:935}
					toolIndex["Eraser"]			 		:=	{x:17, y:959}
					toolIndex["Eyedropper"]				:=	{x:17, y:959}
					toolIndex["Blend"]			 			:=	{x:17, y:983}
					toolIndex["Scissors"]			 		:=	{x:17, y:983}
					toolIndex["Knife"]			 			:=	{x:17, y:191}
					toolIndex["Measure"]		 		:=	{x:17, y:191}
					toolIndex["Wrinkle"]		 		:=	{x:17, y:1031}
					toolIndex["RotateView"]				:=	{x:17, y:1031}
					toolIndex["PrintTiling"]		 		:=	{x:17, y:935}
					toolIndex["Hand"]			 			:=	{x:17, y:935}
					toolIndex["Zoom"]			 			:=	{x:17, y:1079}

	print(toolIndex[toolName].x " " toolIndex[toolName].y)  ; --> 17, 95
}

Ralf_Reddings200244
Posts: 94
Joined: 11 Mar 2023, 14:16

Re: Plaqued by 'Expression too long' error

Post by Ralf_Reddings200244 » 27 Mar 2024, 12:49

@ShatterCoder

Thank you for this, it works as expected now!

Post Reply

Return to “Ask for Help (v1)”