Glitch in Illustrator?

I’ve run across a glitch and was wondering if anyone could help out. If I were to draw a box in Illustrator and fill it with a gradient swatch, when my script (see below) runs, the box turns black and the class is changed from “Gradient Color Info” to “Grayscale Color Info”. If I were to manually delete the swatch through Illustrator, there’s no problems and the box retains it’s gradient. It seems that using the “Delete Swatch” command through applescript changes the class. Has anyone else encountered this, or maybe know how to get around it? Any help would be appreciated!

Here is the code:

tell application "Adobe Illustrator"
	activate
	set docRef to document 1
	
	tell docRef
		set swatchCount to get count of swatches
		set deleteList to {}
		
		repeat with i from 1 to swatchCount
			set colorType to color of swatch i
			set colorClass to class of colorType
			set colorName to name of swatch i
			
			--finds 4-CP
			if colorClass is CMYK color info then
				set end of deleteList to colorName
			end if
			
			--finds gradients
			if colorClass is gradient color info then
				set end of deleteList to colorName
			end if
			
			--finds patterns
			if colorClass is pattern color info then
				set end of deleteList to colorName
			end if
			
			--excludes spot colors
			if colorClass is spot color info then
			end if
			
			--excludes "none"
			if colorClass is no color info then
			end if
		end repeat
		
		set deleteCount to count of items in deleteList
		--return deleteList
		
		repeat with x from 1 to deleteCount
			set deleteThisSwatch to item x of deleteList
			delete swatch deleteThisSwatch
		end repeat
		
		
		
	end tell
end tell

Hi,

try to put the swatches directly into the list, not just the names


tell application "Adobe Illustrator"
	activate
	tell document 1
		set swatchCount to get count of swatches
		set deleteList to {}
		repeat with i from 1 to swatchCount
			set colorClass to class of color of swatch i
			
			if colorClass is CMYK color info or colorClass is gradient color info or colorClass is pattern color info then
				set end of deleteList to swatch i
			end if
		end repeat
		
		repeat with x from 1 to (count deleteList)
			delete item x of deleteList
		end repeat
	end tell
end tell


Edit: just for fun, this code should do the same thing (but I haven’t tested it)


tell application "Adobe Illustrator"
	tell document 1 to delete (get swatches whose class of color is CMYK color info or class of color is gradient color info or class of color is pattern color info)
end tell

Hi. Deleting swatches breaks the link to the associated gradient index, and Illustrator fills the item with the default black. The same will likely be true of pattern swatches. I believe a workaround would be to either recreate the color from its attributes or relink to another swatch.