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

scripting a rectangle

Guest
Dec 06, 2009 Dec 06, 2009

Hello.

   Bascially I want to create a new layer in a document similar to what I would have when I create / add a rectangle manually.  Does anyone have a simple example they can share with this functionality ?  I can get close by making a selction on the background layer -- then adding a layer and filling it with color but its not exaclty the same as when I add a shape manually in PS

Cheers

Eric

TOPICS
Actions and scripting
913
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
Mentor ,
Dec 06, 2009 Dec 06, 2009

If you are talking about creating a shape layer or solid-fill layer here is an example.

// create a document reference to work with
var doc = app.activeDocument;
//define the path
var lineArray = new Array();
lineArray[0] = new PathPointInfo;
lineArray[0].kind = PointKind.CORNERPOINT;
lineArray[0].anchor = Array(100, 100);//top left
lineArray[0].leftDirection = lineArray[0].anchor;
lineArray[0].rightDirection = lineArray[0].anchor;
lineArray[1] = new PathPointInfo;
lineArray[1].kind = PointKind.CORNERPOINT;
lineArray[1].anchor = Array(200, 100);//top right
lineArray[1].leftDirection = lineArray[1].anchor;
lineArray[1].rightDirection = lineArray[1].anchor;
lineArray[2] = new PathPointInfo;
lineArray[2].kind = PointKind.CORNERPOINT;
lineArray[2].anchor = Array(200, 900);//bottom right
lineArray[2].leftDirection = lineArray[2].anchor;
lineArray[2].rightDirection = lineArray[2].anchor;
lineArray[3] = new PathPointInfo;
lineArray[3].kind = PointKind.CORNERPOINT;
lineArray[3].anchor = Array(100, 900);//bottom left
lineArray[3].leftDirection = lineArray[3].anchor;
lineArray[3].rightDirection = lineArray[3].anchor;
var lineSubPathArray = new Array();
lineSubPathArray[0] = new SubPathInfo();
lineSubPathArray[0].operation = ShapeOperation.SHAPEADD;
lineSubPathArray[0].closed = true;
lineSubPathArray[0].entireSubPath = lineArray;
// now make the path
var myPathItem = doc.pathItems.add("myPath", lineSubPathArray);
// make the layer using scriptlistner
//because is seems the guide is wrong you can only set
//the layerkind to text or normal
//if the path is active as it is now, photoshop uses it as a mask
    var desc88 = new ActionDescriptor();
        var ref60 = new ActionReference();
        ref60.putClass( stringIDToTypeID( "contentLayer" ) );
    desc88.putReference( charIDToTypeID( "null" ), ref60 );
        var desc89 = new ActionDescriptor();
            var desc90 = new ActionDescriptor();
                var desc91 = new ActionDescriptor();
                desc91.putDouble( charIDToTypeID( "Rd  " ), 239.000000 );//change these to change color
                desc91.putDouble( charIDToTypeID( "Grn " ), 12.000000 );
                desc91.putDouble( charIDToTypeID( "Bl  " ), 12.000000 );
            var id481 = charIDToTypeID( "RGBC" );
            desc90.putObject( charIDToTypeID( "Clr " ), id481, desc91 );
        desc89.putObject( charIDToTypeID( "Type" ), stringIDToTypeID( "solidColorLayer" ), desc90 );
    desc88.putObject( charIDToTypeID( "Usng" ), stringIDToTypeID( "contentLayer" ), desc89 );
executeAction( charIDToTypeID( "Mk  " ), desc88, DialogModes.NO );
//remove the path
myPathItem.remove();

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
Guest
Dec 07, 2009 Dec 07, 2009

michael,

     Thanks -- surprised that you need to resort to the scriptlistener.  I guesss this challenges a fundamental  assumption of mine -- which is that you can (or should) be able to recreate all work in PS via the scripting interface

Cheers

Eric

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
Mentor ,
Dec 07, 2009 Dec 07, 2009
LATEST

It would be nice if scriptlistner wasn't needed, but as the comments in my example state you need scriptlistner to create most layer types except normal and text

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