Tengo un problema que no puedo resolver.
Tengo una selección rectangular (no importa el tamaño) que necesito transformar a elíptica con un script.
Me gustaría que la selección elíptica tuviera el mismo tamaño y posición que la rectangular.
Logré armar este script:
(NAR = new ActionReference).putProperty (stringIDToTypeID ("channel"), stringIDToTypeID ("selection"));
(NAD = new ActionDescriptor).putReference (stringIDToTypeID ("null"), NAR);
(NAD2 = new ActionDescriptor).putUnitDouble (stringIDToTypeID ("top"), stringIDToTypeID ("distanceUnit"), app.activeDocument.selection.bounds[1]);
NAD2.putUnitDouble (stringIDToTypeID ("left"), stringIDToTypeID ("distanceUnit"), app.activeDocument.selection.bounds[0]);
NAD2.putUnitDouble (stringIDToTypeID ("bottom"), stringIDToTypeID ("distanceUnit"), app.activeDocument.selection.bounds[3]);
NAD2.putUnitDouble (stringIDToTypeID ("right"), stringIDToTypeID ("distanceUnit"), app.activeDocument.selection.bounds[2]);
NAD.putObject (stringIDToTypeID ("to"), stringIDToTypeID ("ellipse"), NAD2);
NAD.putBoolean (stringIDToTypeID ("antiAlias"), true);
executeAction (stringIDToTypeID ("set"), NAD, DialogModes.NO);
El script crea una selección elíptica con los mismos límites que la selección rectangular existente.
El problema es que la medida final es demasiado pequeña y se movió fuera de los bordes del documento.
Ya intenté convertir el documento a 72 DPI sin volver a muestrear, pero aún no me da el tamaño correcto.
Adjunto una imagen para mayor claridad.
¿Alguien tiene alguna idea?
Esto es demasiado largo y feo, pero cambiará su selección a una elipse:
// Switch off any dialog boxes
displayDialogs = DialogModes.ALL; // OFF
var sb = selection_bounds(); // LRBT
selectThis(sb[0], sb[1], sb[2], sb[3], "oval");
// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL
// function SELECT THIS(top, left, right, bottom, ellipse or rect [default], antialias [default] )
// --------------------------------------------------------
function selectThis(top, left, right, bottom, shape, aa)
{
// =======================================================
var id1 = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id3 = charIDToTypeID( "Chnl" );
var id4 = charIDToTypeID( "fsel" );
ref1.putProperty( id3, id4 );
desc1.putReference( id2, ref1 );
var id5 = charIDToTypeID( "T " );
var desc2 = new ActionDescriptor();
var id6 = charIDToTypeID( "Top " );
var id7 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id6, id7, top );
var id8 = charIDToTypeID( "Left" );
var id9 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id8, id9, left );
var id10 = charIDToTypeID( "Btom" );
var id11 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id10, id11, bottom );
var id12 = charIDToTypeID( "Rght" );
var id13 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id12, id13, right );
if (shape == "Elps" || shape == "oval")
{
var id14 = charIDToTypeID( "Elps" );
desc1.putObject( id5, id14, desc2 );
var id15 = charIDToTypeID( "AntA" );
if (aa == true || aa == undefined)
{
desc1.putBoolean( id15, true );
}
else
{
desc1.putBoolean( id15, false );
}
}
else
{
var id16 = charIDToTypeID( "Rctn" );
desc1.putObject( id5, id16, desc2 );
}
executeAction( id1, desc1, DialogModes.NO );
}
function selection_bounds()
{
try
{
var x = parseFloat(app.activeDocument.selection.bounds[0]);
var y = parseFloat(app.activeDocument.selection.bounds[1]);
var x1 = parseFloat(app.activeDocument.selection.bounds[2]);
var y1 = parseFloat(app.activeDocument.selection.bounds[3]);
// var selectionBounds = [x, x1, y, y1]; // LRBT
var selectionBounds = [y, x, x1, y1]; // TLBR
return selectionBounds;
}
catch(eek)
{
return undefined;
}
}
Intenté descomprimir tu código pero fue en vano. Sin embargo, noté que charIDToTypeID no eran cuatro letras. es decir, "la parte superior debería ser "Superior", "la parte inferior debería ser "Btom", pero es posible que Adobe haya cambiado eso.