Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScripting for Warp

New Here ,
Aug 04, 2015 Aug 04, 2015

Hello,

This will be my first time using JavaScript. I'm trying to make a movie made up of several frames in photoshop, and then using timeline to view them. I would like to write a script to make hundreds of small distortions using the Transform, Warp. I would want the final to look like an animation as if I was dragging several of the pins in warp around at once.

How would I go about writing a script for that?

TOPICS
Actions and scripting
592
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 04, 2015 Aug 04, 2015

This will be my first time using JavaScript.

Then I think you might be "trying to run before you have learned to walk".

Warp can be Scripted but needs Action Manager (AM) code and for beginners it might be easier to start with Document Object Model (DOM) code as that is in some ways more easily readable.

The warping code can be wrapped in a function that takes 16 points (defined as an Array of horizontal and vertical positions) as arguments, but Scripting the animation aspects may also be a bit involved for a first project.

I would like to write a script to make hundreds of small distortions using the Transform, Warp.

How do you want to define those transformation values anyway?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2015 Aug 05, 2015

Here is an example of code that warps the active Layer thusly (naturally the active Layer should be a Smart Object):

warpExample.jpg

// 2015, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

// set to pixels;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// warp;

warpThis ([[0,0], [33.3333333,50], [66.6666667,0], [100,0], [0,33.3333333], [33.3333333,33.3333333], [66.6666667,33.3333333], [100,33.3333333], [0,66.6666667], [33.3333333,66.6666667], [66.6666667,66.6666667], [100,66.6666667], [0,100], [33.3333333,100], [66.6666667,100], [100,100]], [0,0]);

// reset;

app.preferences.rulerUnits = originalRulerUnits;

};

////// warp //////

function warpThis (theArray, theOffset) {

////////////////////////////////////

var idHrzn = charIDToTypeID( "Hrzn" );

var idVrtc = charIDToTypeID( "Vrtc" );

var idPxl = charIDToTypeID( "#Pxl" );

// =======================================================

var idTrnf = charIDToTypeID( "Trnf" );

    var desc4 = new ActionDescriptor();

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc5 = new ActionDescriptor();

        desc5.putUnitDouble( idHrzn, idPxl, theOffset[0] );

        desc5.putUnitDouble( idVrtc, idPxl, theOffset[1] );

    var idOfst = charIDToTypeID( "Ofst" );

    desc4.putObject( idOfst, idOfst, desc5 );

    var idwarp = stringIDToTypeID( "warp" );

        var desc6 = new ActionDescriptor();

        var idwarpStyle = stringIDToTypeID( "warpStyle" );

        var idwarpStyle = stringIDToTypeID( "warpStyle" );

        var idwarpCustom = stringIDToTypeID( "warpCustom" );

        desc6.putEnumerated( idwarpStyle, idwarpStyle, idwarpCustom );

        var idwarpValue = stringIDToTypeID( "warpValue" );

        desc6.putDouble( idwarpValue, 0.000000 );

        var idwarpPerspective = stringIDToTypeID( "warpPerspective" );

        desc6.putDouble( idwarpPerspective, 0.000000 );

        var idwarpPerspectiveOther = stringIDToTypeID( "warpPerspectiveOther" );

        desc6.putDouble( idwarpPerspectiveOther, 0.000000 );

        var idwarpRotate = stringIDToTypeID( "warpRotate" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idHrzn = charIDToTypeID( "Hrzn" );

        desc6.putEnumerated( idwarpRotate, idOrnt, idHrzn );

        var idbounds = stringIDToTypeID( "bounds" );

            var desc7 = new ActionDescriptor();

            var idTop = charIDToTypeID( "Top " );

            desc7.putUnitDouble( idTop, idPxl, 0.000000 );

            var idLeft = charIDToTypeID( "Left" );

            desc7.putUnitDouble( idLeft, idPxl, 0.000000 );

            var idBtom = charIDToTypeID( "Btom" );

            desc7.putUnitDouble( idBtom, idPxl, 100.0000000 );

            var idRght = charIDToTypeID( "Rght" );

            desc7.putUnitDouble( idRght, idPxl, 100.0000000 );

        var idRctn = charIDToTypeID( "Rctn" );

        desc6.putObject( idbounds, idRctn, desc7 );

        var iduOrder = stringIDToTypeID( "uOrder" );

        desc6.putInteger( iduOrder, 4 );

        var idvOrder = stringIDToTypeID( "vOrder" );

        desc6.putInteger( idvOrder, 4 );

        var idcustomEnvelopeWarp = stringIDToTypeID( "customEnvelopeWarp" );

            var desc8 = new ActionDescriptor();

            var idmeshPoints = stringIDToTypeID( "meshPoints" );

                var list1 = new ActionList();

////////////////////////////////////

// top left;

                    var desc9 = new ActionDescriptor();

                    desc9.putUnitDouble( idHrzn, idPxl, theArray[0][0] );

                    desc9.putUnitDouble( idVrtc, idPxl, theArray[0][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc9 );

////////////////////////////////////

// top left horizontal;

                    var desc10 = new ActionDescriptor();

                    desc10.putUnitDouble( idHrzn, idPxl, theArray[1][0] );

                    desc10.putUnitDouble( idVrtc, idPxl, theArray[1][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc10 );

// top right horizontal;

                    var desc11 = new ActionDescriptor();

                    desc11.putUnitDouble( idHrzn, idPxl, theArray[2][0] );

                    desc11.putUnitDouble( idVrtc, idPxl, theArray[2][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc11 );

////////////////////////////////////

// top right;

                    var desc12 = new ActionDescriptor();

                    desc12.putUnitDouble( idHrzn, idPxl, theArray[3][0] );

                    desc12.putUnitDouble( idVrtc, idPxl, theArray[3][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc12 );

////////////////////////////////////

// top left vertical ;

                    var desc13 = new ActionDescriptor();

                    desc13.putUnitDouble( idHrzn, idPxl, theArray[4][0] );

                    desc13.putUnitDouble( idVrtc, idPxl, theArray[4][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc13 );

// vertical 1 1;

                    var desc14 = new ActionDescriptor();

                    desc14.putUnitDouble( idHrzn, idPxl, theArray[5][0] );

                    desc14.putUnitDouble( idVrtc, idPxl, theArray[5][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc14 );

// vertical 2 1;

                    var desc15 = new ActionDescriptor();

                    desc15.putUnitDouble( idHrzn, idPxl, theArray[6][0] );

                    desc15.putUnitDouble( idVrtc, idPxl, theArray[6][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc15 );

// top right vertical ;

                    var desc16 = new ActionDescriptor();

                    desc16.putUnitDouble( idHrzn, idPxl, theArray[7][0] );

                    desc16.putUnitDouble( idVrtc, idPxl, theArray[7][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc16 );

// bottom left vertical;

                    var desc17 = new ActionDescriptor();

                    desc17.putUnitDouble( idHrzn, idPxl, theArray[8][0] );

                    desc17.putUnitDouble( idVrtc, idPxl, theArray[8][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc17 );

                    var desc18 = new ActionDescriptor();

// vertical 1 2;

                    desc18.putUnitDouble( idHrzn, idPxl, theArray[9][0] );

                    desc18.putUnitDouble( idVrtc, idPxl, theArray[9][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc18 );

                    var desc19 = new ActionDescriptor();

// vertical 2 2;

                    desc19.putUnitDouble( idHrzn, idPxl, theArray[10][0] );

                    desc19.putUnitDouble( idVrtc, idPxl, theArray[10][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc19 );

// bottom right vertical;

                    var desc20 = new ActionDescriptor();

                    desc20.putUnitDouble( idHrzn, idPxl, theArray[11][0] );

                    desc20.putUnitDouble( idVrtc, idPxl, theArray[11][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc20 );

////////////////////////////////////

// bottom left;

                    var desc21 = new ActionDescriptor();

                    desc21.putUnitDouble( idHrzn, idPxl, theArray[12][0] );

                    desc21.putUnitDouble( idVrtc, idPxl, theArray[12][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc21 );

////////////////////////////////////

// bottom left horizontal;

                    var desc22 = new ActionDescriptor();

                    desc22.putUnitDouble( idHrzn, idPxl, theArray[13][0] );

                    desc22.putUnitDouble( idVrtc, idPxl, theArray[13][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc22 );

// bottom right horizontal;

                    var desc23 = new ActionDescriptor();

                    desc23.putUnitDouble( idHrzn, idPxl, theArray[14][0] );

                    desc23.putUnitDouble( idVrtc, idPxl, theArray[14][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc23 );

////////////////////////////////////

// bottom right;

                    var desc24 = new ActionDescriptor();

                    desc24.putUnitDouble( idHrzn, idPxl, theArray[15][0] );

                    desc24.putUnitDouble( idVrtc, idPxl, theArray[15][1] );

                var idrationalPoint = stringIDToTypeID( "rationalPoint" );

                list1.putObject( idrationalPoint, desc24 );

////////////////////////////////////

            desc8.putList( idmeshPoints, list1 );

        var idcustomEnvelopeWarp = stringIDToTypeID( "customEnvelopeWarp" );

        desc6.putObject( idcustomEnvelopeWarp, idcustomEnvelopeWarp, desc8 );

    var idwarp = stringIDToTypeID( "warp" );

    desc4.putObject( idwarp, idwarp, desc6 );

executeAction( idTrnf, desc4, DialogModes.NO );

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2015 Aug 13, 2015
LATEST

So have you been able to make any progress on the issue?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines