From 868c1cb141c1655f916323e2371390dbd3d355bc Mon Sep 17 00:00:00 2001 From: yorch Date: Thu, 9 Apr 2015 14:40:04 -0700 Subject: [PATCH] Cambiando bind between 2, incomplete --- yScripts/y_yBindBetween2.jsx | 295 ++++++++++++----------------------- 1 file changed, 104 insertions(+), 191 deletions(-) diff --git a/yScripts/y_yBindBetween2.jsx b/yScripts/y_yBindBetween2.jsx index 4d29609..94c4fef 100644 --- a/yScripts/y_yBindBetween2.jsx +++ b/yScripts/y_yBindBetween2.jsx @@ -1,197 +1,110 @@ -yEntreDeux_data = new Object(); - -yEntreDeux_data.scriptName = 'yBindBetween2'; -yEntreDeux_data.scriptDesc = 'Constraints a layer between two others, position and rotation-wise'; - -yEntreDeux_data.scriptVer = '0.12a'; -yEntreDeux_data.webLink = 'yorchnet.com'; - -//if yToolBox Exists add it to its tool list. -if (typeof(YTB)!=='undefined'){ - YTB.tools.push(yEntreDeux_data); - - //it should be called from toolbox. - /* yEntreDeux_data.buttonWidth=76; - yEntreDeux_data.buttonHeight=30; -*/ - yEntreDeux_data.btnLayout = "btn_"+yEntreDeux_data.scriptName+": Button { preferredSize: ['"+YTB.buttonWidth+"','"+ YTB.buttonHeight+"'], text:'"+yEntreDeux_data.scriptName+"', helpTip:'"+yEntreDeux_data.scriptDesc+"' }"; - - } - - //--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//--------//-------- - // MAIN SCRIPT GOES HERE. - - function build_yEntreDeux_data_UI(){ - //script info - yEntreDeux_data = new Object(); - yEntreDeux_data.scriptName = 'yEntreDeux'; - yEntreDeux_data.scriptVer = '0.1a'; - yEntreDeux_data.webLink = 'yorchnet.com'; +#include "../yScripts/y_JSExtensions.jsx"; +function YGenericTool() +{ + this.info = + { + name : "yBindBetween2", + version : 0.13, + stage : "development", + description : "Constraints a layer between two others, position and rotation-wise", + 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 + "'\ + }"; - - // GUI - - //chk_stretch: Checkbox { text:'Stretch', alignment:['fill','center'] , helpTip:'Stretch between parents'},\ - - yEntreDeux_data.res= "window { \ - type:'palette' , text:'"+yEntreDeux_data.scriptName+' '+yEntreDeux_data.scriptVer+"',margins:[10,10,10,10],spacing:[5,5,5,5]\ - \ - lst_layer: DropDownList {title:'layer to constrain',preferredSize:[150,35],textSelection:'Escoge',helpTip:'Select the layer you wish to constrain'}\ - lst_pa: DropDownList {title:'parent a',preferredSize:[150,35],textSelection:'Escoge',helpTip:'Select the first parent'}\ - lst_pb: DropDownList {title:'parent b',preferredSize:[150,35],textSelection:'Escoge',helpTip:'Select the second parent'}\ - exec_btn: Button {text:'do It',preferredSize:[150,35],helpTip:'do it'}\ - \ - info: Group { \ - alignment:['center','bottom'], \ - icon: Image {preferredSize: [15, 18]},\ - website: StaticText { text:'"+yEntreDeux_data.webLink+"', alignment:['fill','center'] },\ - }\ + this. res = + "window { \ + type:'palette' ,\ + text:'" + this.info.name + ' ' + this.info.version + "',\ + margins:[10,10,10,10],\ + spacing:[5,5,5,5]\ \ - }"; - - - yEntreDeux_data.window = new Window (yEntreDeux_data.res); - //never got around of assigning the icon any other way, but it works. - yEntreDeux_data.window.info.icon.image = YTB.icon; - - refresh(); // reloads the possible layers in the gui. - - yEntreDeux_data.window.exec_btn.onClick = run; - - - yEntreDeux_data.window.show(); - } - -function run(){ - app.beginUndoGroup('Bind Between Two'); - - selectedLayerName=String(yEntreDeux_data.window.lst_layer.selection); - parentALayerName=String(yEntreDeux_data.window.lst_pa.selection); - parentBLayerName=String(yEntreDeux_data.window.lst_pb.selection); - layerN = selectedLayerName.substr(0, selectedLayerName.indexOf('.')); - paN = parentALayerName.substr(0, parentALayerName.indexOf('.')); - pbN = parentBLayerName.substr(0, parentBLayerName.indexOf('.')); - layer = app.project.activeItem.layers[layerN]; - pa = app.project.activeItem.layers[paN]; - pb = app.project.activeItem.layers[pbN]; - layer("Effects").addProperty("Layer Control"); - layer("Effects")("Layer Control").name = 'ctrl01'; - layer("Effects")("ctrl01")("Layer").setValue(pa.index); - layer("Effects").addProperty("Layer Control"); - layer("Effects")("Layer Control").name = 'ctrl02'; - layer("Effects")("ctrl02")("Layer").setValue(pb.index); - layer("Effects").addProperty("Angle Control"); - layer("Effects")("Angle Control").name = 'offset'; - layer("Effects")("offset")("Angle").setValue(0); - layer("Effects").addProperty("Slider Control"); - layer("Effects")("Slider Control").name = 'weight'; - layer("Effects")("weight")(1).setValue(50); - layer("Effects").addProperty("Checkbox Control"); - layer("Effects")("Checkbox Control").name = 'stretch'; - posExp = - 'a = effect("ctrl01")("Layer");\ - b = effect("ctrl02")("Layer");\ - aPos = a.toComp(a.anchorPoint);\ - bPos = b.toComp(b.anchorPoint);\ - w= effect("weight")(1)/100;\ - (aPos*(1-w)+bPos*(w))' - rotExp = - 'a =effect("ctrl01")("Layer");\ - b = effect("ctrl02")("Layer");\ - aPos = a.toComp(a.anchorPoint);\ - bPos = b.toComp(b.anchorPoint);\ - rx = lookAt(aPos,bPos)[0];\ - ry = lookAt(aPos,bPos)[1];\ - offset = effect("offset")("Angle");\ - if (aPos[1] > bPos[1])\ - {\ - (ry) -90 + offset\ - }\ - else\ - {\ - 90 - (ry) + offset\ - }' - scaleExp = - 'a = effect("ctrl01")("Layer");\ - b = effect("ctrl02")("Layer");\ - aPos = a.toComp(a.anchorPoint);\ - bPos = b.toComp(b.anchorPoint);\ - d = Math.sqrt(Math.pow((aPos[0]-bPos[0]),2)+Math.pow((aPos[1]-bPos[1]),2));\ - x = transform.scale[0];\ - y = transform.scale[1];\ - sx = ((d*100)/this.width)/100;\ - stretch = effect("stretch")("Checkbox");\ - if(stretch==true)\ - {\ - [x*sx,y]\ - }\ - else\ - {\ - [x,y]\ - }' - - layer.transform.position.expression = posExp; - layer.transform.rotation.expression= rotExp; - layer.transform.scale.expression= scaleExp; - - app.endUndoGroup(); + lst_layer: DropDownList\ + {\ + title:'layer to constrain',\ + preferredSize:[150,35],\ + textSelection:'Escoge',\ + helpTip:'Select the layer you wish to constrain'\ + }\ + lst_pa: DropDownList\ + {\ + title:'parent a',\ + preferredSize:[150,35],\ + textSelection:'Escoge',\ + helpTip:'Select the first parent'\ + }\ + lst_pb: DropDownList\ + {\ + title:'parent b',\ + preferredSize:[150,35],\ + textSelection:'Escoge',\ + helpTip:'Select the second parent'\ + }\ + exec_btn: Button\ + {\ + text:'do It',\ + preferredSize:[150,35],\ + helpTip:'do it'\ + }\ + info: Group\ + {\ + alignment:['center','bottom'], \ + icon: Image {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() + { + this.createUI(); + } + this.activate = function activate() + { + this.yTool.yMainFunction(); } - -function refresh(){ - //alert('going'); - lists=[yEntreDeux_data.window.lst_pa,yEntreDeux_data.window.lst_layer,yEntreDeux_data.window.lst_pb]//they should be in this order for the assignment of the selection index works right/ - for(i=0;i