mirror of
https://github.com/jorgevasquezp/AFX_yTools.git
synced 2026-08-16 15:30:59 +00:00
Converted the CornerPinOffset tool to the new model
This commit is contained in:
@@ -1 +1 @@
|
|||||||
var scriptUIPanel = this;␍YTB =␍{ ␍ info :␍ {␍ name : "yToolBox",␍ ver : 0.5,␍ status : "alpha",␍ url : "yorchnet.com",␍ description : "My mixed bag of tools"␍ },␍ resources :␍ {␍ icon : new File('../yScripts/yNet.png'),␍ header : new File('../yScripts/header.png')␍ },␍ appearence :␍ {␍ buttonHeight : 30,␍ buttonWidth : 126 ␍ },␍ tools : [],␍ createUI : function createUI()␍ {␍ var res ="group\␍ {\␍ orientation:'column',\␍ alignment:['fill','fill'],\␍ margins:[0,0,0,0]\␍ header: Group\␍ {\␍ orientation:'column',\␍ alignment:['center','top'],\␍ margins:[0,0,0,0]\␍ title: Image\␍ {\␍ icon:'" + this.resources.header.path + '/' + this.resources.header.name + "',\␍ preferredSize: [175, 35]},\␍ ver: StaticText\␍ {\␍ text:'" + this.info.ver + "',\␍ alignment:['center','center']\␍ }\␍ desc: StaticText\␍ {\␍ text:'" + this.info.description + "',\␍ alignment:['center','center']\␍ },\␍ },\␍ main: Group\␍ {\␍ orientation:'column',\␍ alignment:['fill','fill'],\␍ alignChildren:['center','center'],\␍ },\␍ footer: Group\␍ {\␍ alignment:['center','bottom'], \␍ icn_app: Image {icon:'" + this.resources.icon.path + '/' + this.resources.icon.name + "',preferredSize: [15, 18]},\␍ txt_info: StaticText { text:'"+ this.info.url + "', alignment:['fill','center'] },\␍ }, \␍ }";␍ this.window.grp = this.window.add( res );␍ ␍ this.window.layout.layout(true);␍ this.customizeUI();␍ ␍ //EventHandlerAssignment␍ this.window.onResize = this.resize;␍ this.window.onClose = this.close;␍ this.window.onDraw = this.autoLayout;␍ },␍ customizeUI : function customizeUI()␍ {␍ var g = this.window.graphics; ␍ var orange = g.newBrush(g.BrushType.SOLID_COLOR, [1, .45, 0, 1]); ␍ this.window.grp.main.graphics.backgroundColor = orange;␍ },␍ addTool : function addTool( aTool )␍ {␍ /**** TO DO ****/␍ // Check that the tool object is unique.␍ // Call for a window resize so it refreshes propperly.␍ ␍ this.tools.push( aTool );␍␍ var btn = this.window.grp.main.add( aTool.btnLauyout );␍ ␍ btn.onClick = aTool.activate;␍ btn.yTool = aTool; // add a reference to the tool so I can access info on it later...␍ ␍ //alert(btn.onClick);␍␍ this.window.layout.layout(true);␍ ␍ },␍ //EVENT HANDLERS␍ resize : function resize()␍ {␍ this.layout.resize();␍ },␍ close : function close()␍ {␍ YTB = null;␍ delete this;␍ },␍ init : function init()␍ {␍ this.window = ( scriptUIPanel instanceof Panel ) ? scriptUIPanel: new Window( "palette" , this.info.name , undefined, { resizeable : true } );␍ this.createUI();␍ }␍ ␍};␍␍YTB.init();␍␍#include "../yScripts/y_setStructure.jsx";␍#include "../yScripts/y_colorProbe.jsx";␍#include "../yScripts/y_BindBetween2.jsx";␍#include "../yScripts/y_GenericNewScript.jsx";␍
|
var scriptUIPanel = this;␍YTB =␍{ ␍ info :␍ {␍ name : "yToolBox",␍ ver : 0.5,␍ status : "alpha",␍ url : "yorchnet.com",␍ description : "My mixed bag of tools"␍ },␍ resources :␍ {␍ icon : new File('../yScripts/yNet.png'),␍ header : new File('../yScripts/header.png')␍ },␍ appearence :␍ {␍ buttonHeight : 30,␍ buttonWidth : 126 ␍ },␍ tools : [],␍ createUI : function createUI()␍ {␍ var res ="group\␍ {\␍ orientation:'column',\␍ alignment:['fill','fill'],\␍ margins:[0,0,0,0]\␍ header: Group\␍ {\␍ orientation:'column',\␍ alignment:['center','top'],\␍ margins:[0,0,0,0]\␍ title: Image\␍ {\␍ icon:'" + this.resources.header.path + '/' + this.resources.header.name + "',\␍ preferredSize: [175, 35]},\␍ ver: StaticText\␍ {\␍ text:'" + this.info.ver + "',\␍ alignment:['center','center']\␍ }\␍ desc: StaticText\␍ {\␍ text:'" + this.info.description + "',\␍ alignment:['center','center']\␍ },\␍ },\␍ main: Group\␍ {\␍ orientation:'column',\␍ alignment:['fill','fill'],\␍ alignChildren:['center','center'],\␍ },\␍ footer: Group\␍ {\␍ alignment:['center','bottom'], \␍ icn_app: Image {icon:'" + this.resources.icon.path + '/' + this.resources.icon.name + "',preferredSize: [15, 18]},\␍ txt_info: StaticText { text:'"+ this.info.url + "', alignment:['fill','center'] },\␍ }, \␍ }";␍ this.window.grp = this.window.add( res );␍ ␍ this.window.layout.layout(true);␍ this.customizeUI();␍ ␍ //EventHandlerAssignment␍ this.window.onResize = this.resize;␍ this.window.onClose = this.close;␍ this.window.onDraw = this.autoLayout;␍ },␍ customizeUI : function customizeUI()␍ {␍ var g = this.window.graphics; ␍ var orange = g.newBrush(g.BrushType.SOLID_COLOR, [1, .45, 0, 1]); ␍ this.window.grp.main.graphics.backgroundColor = orange;␍ },␍ addTool : function addTool( aTool )␍ {␍ /**** TO DO ****/␍ // Check that the tool object is unique.␍ // Call for a window resize so it refreshes propperly.␍ ␍ this.tools.push( aTool );␍␍ var btn = this.window.grp.main.add( aTool.btnLauyout );␍ ␍ btn.onClick = aTool.activate;␍ btn.yTool = aTool; // add a reference to the tool so I can access info on it later...␍ ␍ //alert(btn.onClick);␍␍ this.window.layout.layout(true);␍ ␍ },␍ //EVENT HANDLERS␍ resize : function resize()␍ {␍ this.layout.resize();␍ },␍ close : function close()␍ {␍ YTB = null;␍ delete this;␍ },␍ init : function init()␍ {␍ this.window = ( scriptUIPanel instanceof Panel ) ? scriptUIPanel: new Window( "palette" , this.info.name , undefined, { resizeable : true } );␍ this.createUI();␍ }␍ ␍};␍␍YTB.init();␍␍#include "../yScripts/y_setStructure.jsx";␍#include "../yScripts/y_colorProbe.jsx";␍#include "../yScripts/y_BindBetween2.jsx";␍#include "../yScripts/y_CPOffset.jsx";␍#include "../yScripts/y_GenericNewScript.jsx";␍
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
#include "../yScripts/y_JSExtensions.jsx";
|
||||||
|
function YCPOffset()
|
||||||
|
{
|
||||||
|
this.info =
|
||||||
|
{
|
||||||
|
name : "YCornerPinOffset",
|
||||||
|
version : 0.12,
|
||||||
|
stage : "development",
|
||||||
|
description : "Offsets each corner of a CornerPin Effect.",
|
||||||
|
url : "yorchnet.com"
|
||||||
|
};
|
||||||
|
this.appearence =
|
||||||
|
{
|
||||||
|
buttonHeight : 30,
|
||||||
|
buttonWidth : 126
|
||||||
|
};
|
||||||
|
this.resources =
|
||||||
|
{
|
||||||
|
icon : new File('yNet.png'),
|
||||||
|
};
|
||||||
|
this.init = function init()
|
||||||
|
{
|
||||||
|
|
||||||
|
this.btnLauyout =
|
||||||
|
"button\
|
||||||
|
{\
|
||||||
|
preferredSize: ['" + this.appearence.buttonWidth + "','" + this.appearence.buttonHeight + "'],\
|
||||||
|
text:'" + this.info.name + "',\
|
||||||
|
helpTip:'" + this.info.description + "'\
|
||||||
|
}";
|
||||||
|
|
||||||
|
this. res =
|
||||||
|
"window\
|
||||||
|
{\
|
||||||
|
type:'palette',\
|
||||||
|
text:'" + this.info.name + ' ' + this.info.ver + ' ' + this.info.stage + "',\
|
||||||
|
info: Group \
|
||||||
|
{\
|
||||||
|
alignment:['center','bottom'],\
|
||||||
|
icon: Image \
|
||||||
|
{\
|
||||||
|
icon:'" + this.resources.icon.path + '/' + this.resources.icon.name + "',\
|
||||||
|
preferredSize: [15, 18]\
|
||||||
|
},\
|
||||||
|
website: StaticText\
|
||||||
|
{\
|
||||||
|
text:'" + this.info.url + "',\
|
||||||
|
alignment:['fill','center']\
|
||||||
|
},\
|
||||||
|
}\
|
||||||
|
}";
|
||||||
|
}
|
||||||
|
this.createUI = function createUI()
|
||||||
|
{
|
||||||
|
res =
|
||||||
|
"window {\
|
||||||
|
resizeable : true\
|
||||||
|
closeButton : true\
|
||||||
|
text:'wtf'\
|
||||||
|
}"
|
||||||
|
|
||||||
|
this.window = new Window( res );
|
||||||
|
this.window.layout.layout(true);
|
||||||
|
this.window.center();
|
||||||
|
this.window.show();
|
||||||
|
}
|
||||||
|
this.yMainFunction = function yMainFunction()
|
||||||
|
{
|
||||||
|
alert(this);
|
||||||
|
|
||||||
|
//if called from the button as opposed as from the script.
|
||||||
|
if ( String(this) == "[object Button]" )
|
||||||
|
{
|
||||||
|
this.yTool.processCornerPins();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.processCornerPins();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
this.getSelectedCornerPins = function getSelectedCornerPins()
|
||||||
|
{
|
||||||
|
/* Function that returns a list of effect objects
|
||||||
|
that match any of the names
|
||||||
|
specified in validCornerPinNames. */
|
||||||
|
validCornerPinNames = ["ADBE Corner Pin","CC Power Pin"];
|
||||||
|
|
||||||
|
selectedLayers = app.project.activeItem.selectedLayers;
|
||||||
|
cornerPins = [];
|
||||||
|
for (layer=0;layer<selectedLayers.length;layer++)
|
||||||
|
{
|
||||||
|
myLayer = selectedLayers[layer];
|
||||||
|
myEffects = myLayer.property("ADBE Effect Parade");
|
||||||
|
for(effect=1;effect<=myEffects.numProperties;effect++)
|
||||||
|
{
|
||||||
|
for(validCornerPinName=0;validCornerPinName<validCornerPinNames.length;validCornerPinName++)
|
||||||
|
{
|
||||||
|
if ( myEffects.property(effect).matchName == validCornerPinNames[validCornerPinName] )
|
||||||
|
{
|
||||||
|
cornerPins.push(myEffects.property(effect));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cornerPins;
|
||||||
|
}
|
||||||
|
this.getLayer = function getLayer(effect)
|
||||||
|
{
|
||||||
|
/* If given a layer's effect object
|
||||||
|
this function returns the layer object */
|
||||||
|
layer = effect.parentProperty.parentProperty;
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
this.addEffect = function addEffect(layer,effect_string,effect_name)
|
||||||
|
{
|
||||||
|
new_effect = layer.property("ADBE Effect Parade").addProperty(effect_string);
|
||||||
|
new_effect.name = effect_name;
|
||||||
|
return new_effect;
|
||||||
|
}
|
||||||
|
this.addPointControls = function addPointControls(effect)
|
||||||
|
{
|
||||||
|
/*calling the getLayer(effect) is resetting my effect object to null, and not allowing me to do everything in a single sitting. I think it has to do with variable scopes.*/
|
||||||
|
local = {};
|
||||||
|
local.effect = effect;
|
||||||
|
base_name = local.effect.name;
|
||||||
|
names = ["Upper Left","Upper Right","Lower Left","Lower Right"];
|
||||||
|
|
||||||
|
for (i=1;i<=4;i++)
|
||||||
|
{
|
||||||
|
expression = '\
|
||||||
|
try\
|
||||||
|
{\
|
||||||
|
effect("'+base_name+'")('+(i)+')+effect("'+base_name+'_'+names[i-1]+'_'+'Offset'+'")("Point")\
|
||||||
|
}\
|
||||||
|
catch(err)\
|
||||||
|
{\
|
||||||
|
[0,0]\
|
||||||
|
}'
|
||||||
|
local.effect.property(i).expression = expression;
|
||||||
|
}
|
||||||
|
layer = this.getLayer(effect);
|
||||||
|
for(i=0;i<=3;i++)
|
||||||
|
{
|
||||||
|
new_effect = this.addEffect(layer,"Point Control",base_name+"_"+names[i]+"_"+"Offset");
|
||||||
|
new_effect.property("Point").setValue([0,0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.processCornerPins = function processCornerPins(){
|
||||||
|
|
||||||
|
app.beginUndoGroup('ySetProject');
|
||||||
|
pins = this.getSelectedCornerPins();
|
||||||
|
|
||||||
|
for(pin=0;pin<pins.length;pin++)
|
||||||
|
{
|
||||||
|
this.addPointControls(pins[pin])
|
||||||
|
}
|
||||||
|
app.endUndoGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.activate = this.yMainFunction;
|
||||||
|
this.init();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECKS that the toolbox exists, and if it doesn´t it runs the script on its own.
|
||||||
|
if (typeof(YTB)=='undefined')
|
||||||
|
{
|
||||||
|
yCPOffset = new YCPOffset();
|
||||||
|
yCPOffset.activate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
YTB.addTool(new YCPOffset());
|
||||||
|
}
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
#include "../yScripts/y_JSExtensions.jsx";
|
|
||||||
|
|
||||||
yOffsetCornerPin_data = new Object();
|
|
||||||
|
|
||||||
yOffsetCornerPin_data.scriptName = 'YCornerPinOffset';
|
|
||||||
yOffsetCornerPin_data.scriptDesc = 'Offsets each corner of a CornerPin Effect';
|
|
||||||
yOffsetCornerPin_data.scriptVer = '0.1a';
|
|
||||||
yOffsetCornerPin_data.webLink = 'yorchnet.com';
|
|
||||||
|
|
||||||
//if yToolBox Exists add it to its tool list.
|
|
||||||
if (typeof(YTB)!=='undefined'){
|
|
||||||
YTB.tools.push(yOffsetCornerPin_data);
|
|
||||||
|
|
||||||
//it should be called from toolbox.
|
|
||||||
/*
|
|
||||||
yOffsetCornerPin_data.buttonWidth=76;
|
|
||||||
yOffsetCornerPin_data.buttonHeight=30;
|
|
||||||
*/
|
|
||||||
yOffsetCornerPin_data.btnLayout = "btn_"+ yOffsetCornerPin_data.scriptName+": Button { preferredSize: ['"+ YTB.buttonWidth+"','"+ YTB.buttonHeight+"'], text:'"+yOffsetCornerPin_data.scriptName+"', helpTip:'"+yOffsetCornerPin_data.scriptDesc+"' }";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
yOffsetCornerPin_data.res = "window { \
|
|
||||||
type:'palette' , text:'"+yOffsetCornerPin_data.scriptName+' '+yOffsetCornerPin_data.scriptVer+"',\
|
|
||||||
\
|
|
||||||
\
|
|
||||||
info: Group { \
|
|
||||||
alignment:['center','bottom'], \
|
|
||||||
icon: Image {preferredSize: [15, 18]},\
|
|
||||||
website: StaticText { text:'"+yOffsetCornerPin_data.webLink+"', alignment:['fill','center'] },\
|
|
||||||
}\
|
|
||||||
\
|
|
||||||
}";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------
|
|
||||||
function getSelectedCornerPins() {
|
|
||||||
/* Function that returns a list of effect objects
|
|
||||||
that match any of the names
|
|
||||||
specified in validCornerPinNames. */
|
|
||||||
validCornerPinNames = ["ADBE Corner Pin","CC Power Pin"]
|
|
||||||
selectedLayers = app.project.activeItem.selectedLayers
|
|
||||||
cornerPins = []
|
|
||||||
for (layer=0;layer<selectedLayers.length;layer++){
|
|
||||||
myLayer = selectedLayers[layer];
|
|
||||||
myEffects = myLayer.property("ADBE Effect Parade");
|
|
||||||
for(effect=1;effect<=myEffects.numProperties;effect++){
|
|
||||||
for(validCornerPinName=0;validCornerPinName<validCornerPinNames.length;validCornerPinName++){
|
|
||||||
if ( myEffects.property(effect).matchName == validCornerPinNames[validCornerPinName] && myEffects.property(effect).selected == true){
|
|
||||||
cornerPins.push(myEffects.property(effect))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cornerPins
|
|
||||||
}
|
|
||||||
function getLayer(effect){
|
|
||||||
/* If given a layer's effect object
|
|
||||||
this function returns the layer object */
|
|
||||||
layer = effect.parentProperty.parentProperty
|
|
||||||
return layer
|
|
||||||
}
|
|
||||||
function addEffect(layer,effect_string,effect_name){
|
|
||||||
new_effect = layer.property("ADBE Effect Parade").addProperty(effect_string);
|
|
||||||
new_effect.name = effect_name;
|
|
||||||
return new_effect
|
|
||||||
}
|
|
||||||
function addPointControls(effect){
|
|
||||||
/*calling the getLayer(effect) is resetting my effect object to null, and not allowing me to do everything in a single sitting. I think it has to do with variable scopes.*/
|
|
||||||
local = {};
|
|
||||||
local.effect = effect;
|
|
||||||
base_name = local.effect.name;
|
|
||||||
names = ["Upper Left","Upper Right","Lower Left","Lower Right"];
|
|
||||||
|
|
||||||
for (i=1;i<=4;i++){
|
|
||||||
expression = 'try{\
|
|
||||||
effect("'+base_name+'")('+(i)+')+effect("'+base_name+'_'+names[i-1]+'_'+'Offset'+'")("Point")\
|
|
||||||
}catch(err){\
|
|
||||||
[0,0]\
|
|
||||||
}'
|
|
||||||
local.effect.property(i).expression = expression;
|
|
||||||
}
|
|
||||||
layer = getLayer(effect);
|
|
||||||
for(i=0;i<=3;i++){
|
|
||||||
new_effect = addEffect(layer,"Point Control",base_name+"_"+names[i]+"_"+"Offset");
|
|
||||||
new_effect.property("Point").setValue([0,0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function processCornerPins(){
|
|
||||||
app.beginUndoGroup('ySetProject');
|
|
||||||
pins = getSelectedCornerPins();
|
|
||||||
for(pin=0;pin<pins.length;pin++){
|
|
||||||
addPointControls(pins[pin])
|
|
||||||
}
|
|
||||||
app.endUndoGroup();
|
|
||||||
}
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
function build_yOffsetCornerPin_data_UI(){
|
|
||||||
yOffsetCornerPin_data.window = new Window ( yOffsetCornerPin_data.res);
|
|
||||||
yOffsetCornerPin_data.window.show();
|
|
||||||
}
|
|
||||||
yOffsetCornerPin_data.activate =processCornerPins ;
|
|
||||||
|
|
||||||
//CHECKS that the toolbox exists, and if it doesn´t it runs the script on its own.
|
|
||||||
if (typeof(YTB)=='undefined'){
|
|
||||||
yOffsetCornerPin_data.activate();
|
|
||||||
}else{
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user