Photoshop and merge layers – what wrong?

Hi peoples!

I have little problem with photoshop and merge layers.


tell application id "com.Adobe.Photoshop"		
	set docRef to the current document
	set docName to name of docRef
	
	tell docRef
		set layersCount to (count of layers)
		set visible of every layer to true
		set visible of layer layersCount to false
	end tell
	with timeout of 1800 seconds
		-- merge layer
		try
			merge visible layers docRef
		on error
			log "Can't merge"
			close current document saving no -- закрытие документа
			return
		end try
	end timeout
end tell

If the lower layer is hidden in a current document, the script does not work.

General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

  • The command “Merge Visible” is not currently available.

But if all layers of current document visible “ script work well.

What wrong?

Sorry,

I made a little mistake. Before merging layers i need to make active any visible layer.


tell application id "com.Adobe.Photoshop"        
   set docRef to the current document
   set docName to name of docRef
   
   tell docRef
					set layersCount to (count of layers)
					if (quick mask mode) then delete channel ¬
						"Quick Mask"
					try
						delete (every layer whose visibility is false)
					end try
					set visible of layer layersCount to false

--> Make active any visible layer <--
					try
						set current layer to layer (layersCount - 1)
					end try
					try
						merge visible layers
					on error the error_message number the error_number
						display dialog "Error in #1, can't set output file name: " & the error_number & ". " & the error_message ¬
							buttons {"OK"} default button 1 with icon stop with title myTitle
						return
					end try

--> Set all layers to visible <--
					set visible of every layer to true
				end tell
end tell