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

Photoshop script cut by guides for CS6 wont work in cc2020

Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

I have one ps cs6 script that cut image by guides and make layers...but this wont work in cc2020..maybe someone can help and make it work in cc2020?

 

//flaten layers
app.activeDocument.flatten()

//--------------------------------------------------------------------------------------------------

//select move tool
var idslct = charIDToTypeID( "slct" );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idmoveTool = stringIDToTypeID( "moveTool" );
ref1.putClass( idmoveTool );
desc4.putReference( idnull, ref1 );
var iddontRecord = stringIDToTypeID( "dontRecord" );
desc4.putBoolean( iddontRecord, true );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc4.putBoolean( idforceNotify, true );
executeAction( idslct, desc4, DialogModes.NO );

//--------------------------------------------------------------------------------------------------

//reze sliku prema guide-ovima
// split image to layers according to guides;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var myResolution = myDocument.resolution;
var theLayer = myDocument.activeLayer;
var layerID = getLayerId(theLayer);
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// check guides;
var theVer = new Array;
var theHor = new Array;
var theNumber = myDocument.guides.length;
for (var m = 0; m < theNumber; m++) {
if (myDocument.guides[m].direction == Direction.HORIZONTAL) {theHor.push(myDocument.guides[m].coordinate)};
if (myDocument.guides[m].direction == Direction.VERTICAL) {theVer.push(myDocument.guides[m].coordinate)};
};
// sort and add beginning and end;
theHor = treatGuideArray (theHor, app.activeDocument.height);
theVer = treatGuideArray (theVer, app.activeDocument.width);
$.writeln(theHor.join("\n")+"\n\n\n"+theVer.join("\n"));
// create selections;
for (var y = 0; y < theHor.length - 1; y++) {
var Y1 = theHor[y];
var Y2 = theHor[y+1];
for (var x = 0; x < theVer.length - 1; x++) {
try {
var X1 = theVer[x];
var X2 = theVer[x+1];
rectangularSelection([Y1, X1, Y2, X2], false);
// layer via copy;
var id14 = charIDToTypeID( "CpTL" );
executeAction( id14, undefined, DialogModes.NO );
// add mask;
intersectedLayerMask (layerID)
} catch (e) {};
// reselct layer;
myDocument.activeLayer = theLayer;
};
};
// reset the ruler units;
app.preferences.rulerUnits = originalRulerUnits
};
////////////////// the functions //////////////////
////// treat array //////
function treatGuideArray (theArray, theExtreme) {
theArray.sort(function(a,b){return a - b});
if (Number (theArray[theArray.length - 1]) != theExtreme) {theArray.push(theExtreme)};
if (Number (theArray[0]) != 0) {theArray.unshift(new UnitValue(0, "pt"))};
theArray.sort(function(a,b){return a - b});
return theArray;
};
////// rectangular selection //////
function rectangularSelection (theBounds, add) {
// =======================================================
if (add == false || add == undefined) {var idsetd = charIDToTypeID( "setd" )}
else {var idsetd = charIDToTypeID( "AddT" )};
var desc55 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref11 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref11.putProperty( idChnl, idfsel );
desc55.putReference( idnull, ref11 );
var idT = charIDToTypeID( "T " );
var desc56 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idRlt = charIDToTypeID( "#Rlt" );
desc56.putUnitDouble( idTop, idRlt, theBounds[0] );
var idLeft = charIDToTypeID( "Left" );
var idRlt = charIDToTypeID( "#Rlt" );
desc56.putUnitDouble( idLeft, idRlt, theBounds[1] );
var idBtom = charIDToTypeID( "Btom" );
var idRlt = charIDToTypeID( "#Rlt" );
desc56.putUnitDouble( idBtom, idRlt, theBounds[2] );
var idRght = charIDToTypeID( "Rght" );
var idRlt = charIDToTypeID( "#Rlt" );
desc56.putUnitDouble( idRght, idRlt, theBounds[3] );
var idRctn = charIDToTypeID( "Rctn" );
desc55.putObject( idT, idRctn, desc56 );
executeAction( idsetd, desc55, DialogModes.NO );
};
function getLayerId(theLayer){
// http://forums.adobe.com/message/1944754#1944754
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
return d.getInteger(charIDToTypeID('LyrI'));
};

//--------------------------------------------------------------------------------------------------

// rename layers + dimension
var doc = app.activeDocument;
var docName = doc.name;

// you have to check if the following layers really exists !!!
doc.activeLayer = doc.artLayers.getByName("Layer 1");
app.activeDocument.activeLayer.name = docName + "_Zadnjica_" + getSize ();
doc.activeLayer = doc.artLayers.getByName("Layer 2");
app.activeDocument.activeLayer.name = docName + "_Hrbat_" + getSize ();
doc.activeLayer = doc.artLayers.getByName("Layer 3");
app.activeDocument.activeLayer.name = docName + "_Prednjica_" + getSize ();

// dimension
app.preferences.rulerUnits = Units.CM;
function getSize () {
var actLayBds = doc.activeLayer.bounds;
var actLayW = actLayBds[2] - actLayBds[0];
var actLayH = actLayBds[3] - actLayBds[1];
var cmW = new UnitValue (actLayW.as('cm').toFixed(1),'cm');
var cmH = new UnitValue (actLayH.as('cm').toFixed(1),'cm');
laySize = cmW + " x " + cmH;
return laySize;
}

//--------------------------------------------------------------------------------------------------

// delete Background if exist!!!
var doc = app.activeDocument;
doc.activeLayer = doc.artLayers.getByName("Background");
doc.activeLayer.remove();

//--------------------------------------------------------------------------------------------------

TOPICS
Actions and scripting , Windows

Views

574

Translate

Translate

Report

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

correct answers 1 Correct answer

People's Champ , Aug 24, 2020 Aug 24, 2020
This script works in both CS6 and CC 2020 (21.2.2).
What are your problems?

By the way, there are still errors.
If you replace "catch (e) {};" to "catch (e) { alert (e);};" you will see it. But this does not affect the operation of the script as a whole.
 

Votes

Translate

Translate
Adobe
People's Champ ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

This script will not work in CS6.
There are at least two errorrs
Instead of "T " you should write "T   " (3 spaces).
The intersectedLayerMask() function is not defined;

What exactly do you want to do?
 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

this script work ok in photoshop cs6, but dont work in photoshop cc2020...

Votes

Translate

Translate

Report

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
People's Champ ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

I just have CS6.
Either you haven't tested it as it works on CS6, or you run another script and put another one here.
 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

make new image or open existing, create two guides and run script...you will get 3 layers with size in layer names

Votes

Translate

Translate

Report

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
People's Champ ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

Upload the script file. What you copy-pasted here does not work. There is a lot of unnecessary code, mistakes in writing, some of the code is missing.
 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

//flaten layers
app.activeDocument.flatten()

//--------------------------------------------------------------------------------------------------

//select move tool
var idslct = charIDToTypeID( "slct" );
    var desc4 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idmoveTool = stringIDToTypeID( "moveTool" );
        ref1.putClass( idmoveTool );
    desc4.putReference( idnull, ref1 );
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc4.putBoolean( iddontRecord, true );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc4.putBoolean( idforceNotify, true );
executeAction( idslct, desc4, DialogModes.NO );

//--------------------------------------------------------------------------------------------------

//reze sliku prema guide-ovima
// split image to layers according to guides;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var myResolution = myDocument.resolution;
var theLayer = myDocument.activeLayer;
var layerID = getLayerId(theLayer);
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// check guides;
var theVer = new Array;
var theHor = new Array;
var theNumber = myDocument.guides.length;
for (var m = 0; m < theNumber; m++) {
if (myDocument.guides[m].direction == Direction.HORIZONTAL) {theHor.push(myDocument.guides[m].coordinate)};
if (myDocument.guides[m].direction == Direction.VERTICAL) {theVer.push(myDocument.guides[m].coordinate)};
};
// sort and add beginning and end;
theHor = treatGuideArray (theHor, app.activeDocument.height);
theVer = treatGuideArray (theVer, app.activeDocument.width);
//$.writeln(theHor.join("\n")+"\n\n\n"+theVer.join("\n"));
// create selections;
for (var y = 0; y < theHor.length - 1; y++) {
  var Y1 = theHor[y];
  var Y2 = theHor[y+1];
  for (var x = 0; x < theVer.length - 1; x++) {
  try {
  var X1 = theVer[x];
  var X2 = theVer[x+1];
  rectangularSelection([Y1, X1, Y2, X2], false);
// layer via copy;
  var id14 = charIDToTypeID( "CpTL" );
  executeAction( id14, undefined, DialogModes.NO );
// add mask;
  intersectedLayerMask (layerID)
  } catch (e) {};
// reselct layer;
  myDocument.activeLayer = theLayer;
  };
  };
// reset the ruler units;
app.preferences.rulerUnits = originalRulerUnits
};
////////////////// the functions //////////////////
////// treat array //////
function treatGuideArray (theArray, theExtreme) {
theArray.sort(function(a,b){return a - b});
if (Number (theArray[theArray.length - 1]) != theExtreme) {theArray.push(theExtreme)};
if (Number (theArray[0]) != 0) {theArray.unshift(new UnitValue(0, "pt"))};
theArray.sort(function(a,b){return a - b});
return theArray;
};
////// rectangular selection //////
function rectangularSelection (theBounds, add) {
// =======================================================
if (add == false ||  add == undefined) {var idsetd = charIDToTypeID( "setd" )}
else {var idsetd = charIDToTypeID( "AddT" )};
    var desc55 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref11 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref11.putProperty( idChnl, idfsel );
    desc55.putReference( idnull, ref11 );
    var idT = charIDToTypeID( "T   " );
        var desc56 = new ActionDescriptor();
        var idTop = charIDToTypeID( "Top " );
        var idRlt = charIDToTypeID( "#Rlt" );
        desc56.putUnitDouble( idTop, idRlt, theBounds[0] );
        var idLeft = charIDToTypeID( "Left" );
        var idRlt = charIDToTypeID( "#Rlt" );
        desc56.putUnitDouble( idLeft, idRlt, theBounds[1] );
        var idBtom = charIDToTypeID( "Btom" );
        var idRlt = charIDToTypeID( "#Rlt" );
        desc56.putUnitDouble( idBtom, idRlt, theBounds[2] );
        var idRght = charIDToTypeID( "Rght" );
        var idRlt = charIDToTypeID( "#Rlt" );
        desc56.putUnitDouble( idRght, idRlt, theBounds[3] );
    var idRctn = charIDToTypeID( "Rctn" );
    desc55.putObject( idT, idRctn, desc56 );
executeAction( idsetd, desc55, DialogModes.NO );
};
function getLayerId(theLayer){
// http://forums.adobe.com/message/1944754#1944754
app.activeDocument.activeLayer = theLayer;
//Assumes activeDocument and activeLayer
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    d = executeActionGet(ref);
return d.getInteger(charIDToTypeID('LyrI'));
};

//--------------------------------------------------------------------------------------------------

// rename layers + dimension
var doc = app.activeDocument;  
var docName = doc.name;  
  
// you have to check if the following layers really exists !!!  
doc.activeLayer = doc.artLayers.getByName("Layer 1");  
app.activeDocument.activeLayer.name = docName + "_Zadnjica_" + getSize ();  
doc.activeLayer = doc.artLayers.getByName("Layer 2");  
app.activeDocument.activeLayer.name = docName + "_Hrbat_" + getSize ();  
doc.activeLayer = doc.artLayers.getByName("Layer 3");  
app.activeDocument.activeLayer.name = docName + "_Prednjica_" + getSize ();  
  
// dimension  
app.preferences.rulerUnits = Units.CM;  
function getSize () {  
var actLayBds = doc.activeLayer.bounds;  
var actLayW = actLayBds[2] - actLayBds[0];  
var actLayH = actLayBds[3] - actLayBds[1];  
var cmW = new UnitValue (actLayW.as('cm').toFixed(1),'cm');  
var cmH = new UnitValue (actLayH.as('cm').toFixed(1),'cm');  
laySize = cmW + " x " + cmH;  
return laySize;  
}  

//--------------------------------------------------------------------------------------------------

// delete Background if exist!!!
var doc = app.activeDocument;
doc.activeLayer = doc.artLayers.getByName("Background");
doc.activeLayer.remove();

//--------------------------------------------------------------------------------------------------

Votes

Translate

Translate

Report

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
People's Champ ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

This script works in both CS6 and CC 2020 (21.2.2).
What are your problems?

By the way, there are still errors.
If you replace "catch (e) {};" to "catch (e) { alert (e);};" you will see it. But this does not affect the operation of the script as a whole.
 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

LATEST

yes, work, sorry...

 

Votes

Translate

Translate

Report

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
People's Champ ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

Do you have an English version of Photoshop?
The script only works if the layer name is "Layer 1" and so on.
 

Votes

Translate

Translate

Report

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