Skip to main content
Innotex Nico Tanne
Inspiring
October 17, 2019
Question

Help with Javascript Values

  • October 17, 2019
  • 2 replies
  • 486 views

Hi,

 

I have a promt box to set the Value for Moving an Object

in this case i get percent #Prc  or  pixel #Pxl as Value but i need MM or CM

 

desc2.putUnitDouble(cTID('Hrzn'), cTID('#Prc'), InputfromPromt);

or

desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), InputfromPromt);

 

can you Help me please?

This topic has been closed for replies.

2 replies

JJMack
Community Expert
Community Expert
October 17, 2019

It looks like you set the units to pixels for use in the script. you will need to convert the units received from your prompts to pixels using the document current resolution

JJMack
Innotex Nico Tanne
Inspiring
October 18, 2019
Ok Thank you i found the Solution var WidthMM= horv/25.4*doc.resolution;
Innotex Nico Tanne
Inspiring
October 17, 2019

 

Here is my code, Hope you can Help me.

 

#target photoshop

var StartrulerUnits = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

var horv = prompt ("Horizantal Value" , "0");
var verv = prompt ("Vertical Value" , "0");
var repv = prompt ("Repeat Value" , "0");


function moveing() {
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('copyToLayer'), undefined, dialogMode);
  };
  
  
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
	
    desc2.putUnitDouble(cTID('Hrzn'), cTID('#Pxl'), horv);
    desc2.putUnitDouble(cTID('Vrtc'), cTID('#Pxl'), verv);
    desc1.putObject(cTID('T   '), cTID('Ofst'), desc2);
    executeAction(cTID('move'), desc1, dialogMode);
  };
  step1();
  step2();
};
moveing.main = function () {
  moveing();
};
for(var i = 0; i < repv; i++){
moveing.main();
 }