Copiar link para a área de transferência
Copiado
Hello everyone! Continuing my project "Insert logo to document" in this step now I needed to make adjustments involving the layer move in the document and for that, I created two buttons to do the right or left shift, I used the ScriptingListener to get the value of the displacement of + 0.5cm and -0.5cm then assign the values to the buttons. This process I was able to make work perfectly, my objective now is to display these values in an edittext.
Example: Whenever I clicked the button, I added 0.5cm in edittext.
It would be a calculation with the multiple of 0.5cm 0cm + 0.5cm = 0.5cm /// 0.5cm + 0.5 cm = 1 cm // 1cm + 0,5cm = 1,5cm .
Here is the Project Script:
https://pastebin.com/raw/8ttsh5yn
Sample:
Thank you in advance!
Hi,
try this one – I've kept the xOff (and yOff, which I assume you'll be using as well) as a separate var, which the onClick handler increases/decreases.
...function c2t(c) {
return app.charIDToTypeID(c);
};
function s2t(s) {
return app.stringIDToTypeID(s);
};
var pngB1 ="/* YOUR LONG PNG STRING */";
var pngB2 ="/* YOUR LONG PNG STRING */";
var xOff = 0;
var yOff = 0;
win = new Window("dialog", "OffSet Image", [0, 0, 290, 115], { resizeable: true,});
Pnl_logo = win.add("panel", [9, 9, 282, 105]);
// Of
Copiar link para a área de transferência
Copiado
Hi,
try this one – I've kept the xOff (and yOff, which I assume you'll be using as well) as a separate var, which the onClick handler increases/decreases.
function c2t(c) {
return app.charIDToTypeID(c);
};
function s2t(s) {
return app.stringIDToTypeID(s);
};
var pngB1 ="/* YOUR LONG PNG STRING */";
var pngB2 ="/* YOUR LONG PNG STRING */";
var xOff = 0;
var yOff = 0;
win = new Window("dialog", "OffSet Image", [0, 0, 290, 115], { resizeable: true,});
Pnl_logo = win.add("panel", [9, 9, 282, 105]);
// Offset + X
text_x=Pnl_logo.add("edittext",[76,12,0,0] , " " + xOff + " cm");
text_x.size = [50, 20];
var Offset_x_cima = Pnl_logo.add("image", [0, 0, 0, 0], pngB1);
Offset_x_cima.helpTip = "Delocar para a direita!";
Offset_x_cima.size = [20, 10];
Offset_x_cima.location = [59, 12]
var Offset_x_bx = Pnl_logo.add("image", [0, 0, 0, 0], pngB2);
Offset_x_bx.helpTip = "Deslocar para a esquerda!";
Offset_x_bx.size = [20, 20];
Offset_x_bx.location = [59, 17]
statictext_x=Pnl_logo.add("statictext",[10,15,70,29] ,"OffSet X: ",{multiline:true});
//Event Offset + X
Offset_x_cima.onClick = function() {
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(c2t("null"), reference);
descriptor.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage"));
descriptor2.putUnitDouble(s2t("horizontal"), s2t("distanceUnit"), 15.200000);
descriptor2.putUnitDouble(s2t("vertical"), s2t("distanceUnit"), 0.000000);
descriptor.putObject(s2t("offset"), s2t("offset"), descriptor2);
descriptor.putEnumerated(c2t("Intr"), s2t("interpolationType"), s2t("bicubic"));
executeAction(s2t("transform"), descriptor, DialogModes.NO);
xOff += 0.5;
text_x.text = " " + xOff + " cm";
app.refresh();
}
//Event Offset -X
Offset_x_bx.onClick = function() {
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(c2t("null"), reference);
descriptor.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage"));
descriptor2.putUnitDouble(s2t("horizontal"), s2t("distanceUnit"), -15.200000);
descriptor2.putUnitDouble(s2t("vertical"), s2t("distanceUnit"), 0.000000);
descriptor.putObject(s2t("offset"), s2t("offset"), descriptor2);
descriptor.putEnumerated(c2t("Intr"), s2t("interpolationType"), s2t("bicubic"));
executeAction(s2t("transform"), descriptor, DialogModes.NO);
xOff -= 0.5;
text_x.text = " " + xOff + " cm";
app.refresh();
}
win.center();
win.show();
Also, I've cleaned the two Offset_x functions, which appeared to be a mistakenly renamed c2t function, and moved both s2t and c2t functions at the beginning.
This doesn't take into account the user entering values himself manually (there's no error checking nor parsing), but if you just need to display the values in .5 steps that should work.
In case you need this on Mac as well, be aware that the statictext requires a bit more space and the arrows aren't aligned: the joy of multiplatform development 🙂
Davide
Copiar link para a área de transferência
Copiado
I use mac
but do not the buttons work?
Copiar link para a área de transferência
Copiado
Wow, perfect! Great, you worked really well King David, I'm very happy with the great support of everyone here in this community. Thank you very much Davide_Barranca
Copiar link para a área de transferência
Copiado
LOL as a king I feel a bit dilapidated but you're welcome
Copiar link para a área de transferência
Copiado
Then do the kingly thing increase taxes and kill the tax collector for abusing your subjects.
Encontre mais inspiração, eventos e recursos na nova comunidade da Adobe
Explore agora