I wonder why that code doesn't work for you. Maybe it's because you use PS CC while I still CS. Anyway fisrt part (that both codes have ie. with background moving and CAM creating) is identical.
It seems something brokes the code in their second part. We can investigate it some easy way. Those 2 additional lines:
Code: Select all
if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) nme = btm.name, btm.isBackgroundLayer = 0
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
worked fine as separate code (that before a little change I made to connect it to a part background code and now CAM's uses). This code originally looked so:
Code: Select all
if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) nme = btm.name, btm.isBackgroundLayer = 0
btm.move(lyr[0], ElementPlacement.PLACEATEND); (bGl = (bGn = lyr[0].layers)[bGn.length - 1]).name = nme, bGl.allLocked =1
then I added next part in front of these 2 lines while in sole 2 lines I did 2 changes, I changed a rank of nme = btm.name, btm.isBackgroundLayer = 0 for btm.isBackgroundLayer = 0; nme = btm.name adding semicolon between. Second change was changing lyr[0] in 2 spots for aD, where additionally I bound aD to eval(aD):
Code: Select all
if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0; nme = btm.name
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
1) Now when we know this all please let's see where exactly error happens in last line (that became orange for you):
open PS, ctrl-n (new document, where only background for test is sufficient), open ESTK, set PS mode, paste a code you did before that alerted error and replace last 2 lines for these ones:
Code: Select all
if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0; nme = btm.name
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);
(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
2) When you do it please tell me did last or one before last line line get orange highlighted, also when you do this test, do another one but with 2 alerts:
Code: Select all
alert(aD)
if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0; nme = btm.name
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);
alert(aD)
alert(eval(aD))
(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
I know it's not necessary for you now, but it may help me and maybe later you to understand what happens when you will write something similar...
(ah, and just for clarity. Like CAM layer had to be created in (sub)set which (layer) was activated / selected), this code has to move last layer (changed from background if needed) to (sub)set which (layer) was activated / selected. In this (ctrl-n etc) example only background changed to layer and locked again).
3) History States Deletion:
Code: Select all
function cTT(v) {return charIDToTypeID(v)}; function sTT(v) {return stringIDToTypeID(v)}}
function HstS(v) {// UNDOING HISTORY STATES:
(ref = new ActionReference()).putOffset(cTT('HstS'), 1 - v);
(dsc = new ActionDescriptor()).putReference(cTT('null'), ref)
executeAction(cTT('slct'), dsc, DialogModes.NO);
}
function HSD() {// DELETION OF CURRENT AND FOLLOWING HISTORY STATES:
(ref = new ActionReference()).putProperty(cTT('HstS'), cTT('CrnH'));
(dsc = new ActionDescriptor()).putReference(cTT('null'), ref)
executeAction(cTT('Dlt '), dsc, DialogModes.NO)
}
HstS(5), HSD()