Stdlib.transformScale detect accept and cancel

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

SzopeN

Stdlib.transformScale detect accept and cancel

Post by SzopeN »

When in free transform mode no transformation is done and the user accepts this state, executeAction throws an exception "User cancelled". To distinguish no transformation from cancelation by user one can use the following code:
Code: Select all// include (or copy&paste) stdlib.js first
Stdlib.transformScaleEx = function(doc, layer, linked) {
  function _ftn() {
    var state = true;
        function preMove() {
            var desc = new ActionDescriptor();
            var lref = new ActionReference();
            lref.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt"));
            desc.putReference(cTID("null"), lref);
            desc.putEnumerated(cTID("FTcs"), cTID("QCSt"), cTID("Qcsa"));
                 var desc75 = new ActionDescriptor();
                 desc75.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 1.000000 );
                 desc75.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 1.000000 );
            desc.putObject( cTID('Ofst'), cTID('Ofst'), desc75 );
            executeAction(cTID("Trnf"), desc, DialogModes.NO);
        }
        function retPostMoveDesc() {
            var desc = new ActionDescriptor();
            var lref = new ActionReference();
            lref.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt"));
            desc.putReference(cTID("null"), lref);
            desc.putEnumerated(cTID("FTcs"), cTID("QCSt"), cTID("Qcsa"));
                 var desc75 = new ActionDescriptor();
                 desc75.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), -1.000000 );
                 desc75.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), -1.000000 );
            desc.putObject( cTID('Ofst'), cTID('Ofst'), desc75 );
            return desc;
        }
        preMove();

        var lvl = $.level;
        $.level = 0;
        try {
          executeAction(cTID("Trnf"), retPostMoveDesc(), DialogModes.ALL);
        } catch (e) {
          state = false;
          // $.writeln('' + new Date() + '-------> ' + $.level);
          if (e.number != 8007) { // if not "User cancelled"
            throw e;
          }
          executeAction(cTID("Trnf"), retPostMoveDesc(), DialogModes.NO);
        } finally {
          $.level = lvl;
        }
  }
  Stdlib.wrapLCLayer(doc, layer, _ftn);
  return state; // true = OK, false = Cancel
};
xbytor

Stdlib.transformScale detect accept and cancel

Post by xbytor »

A modified (and hopefully still functional) version of this will be in the next rev of stdlib.

-X