Page 1 of 2

PageWidth how to assign a value to a variable?

Posted: Tue Mar 11, 2014 8:13 am
by menglv
PageWidth how to assign a value to a variable?

How to use PageWidth variable in JavaScript?

PageWidth how to assign a value to a variable?

Posted: Tue Mar 11, 2014 12:13 pm
by freddyp
var pageWidth = job.getVariableAsNumber("[Stats.PageWidth]");

PageWidth how to assign a value to a variable?

Posted: Wed Mar 12, 2014 12:29 am
by menglv
Really worked, thank you very much.

PageWidth how to assign a value to a variable?

Posted: Wed Mar 12, 2014 2:27 pm
by menglv
var re =job.getPath();

re=re.mid(0,re.findRev("/")) + "/"+job.getName();

var curFileStats = new FileStatistics(re);

currentbook = curFileStats.getNumber("PageWidth");



why can't work?

PageWidth how to assign a value to a variable?

Posted: Wed Mar 12, 2014 2:59 pm
by dkelly
Is your job a file or folder?

PageWidth how to assign a value to a variable?

Posted: Thu Mar 13, 2014 12:37 am
by menglv
dkelly wrote: Is your job a file or folder?


my job is a file.

PageWidth how to assign a value to a variable?

Posted: Thu Mar 13, 2014 4:05 am
by menglv
how to use function FileStatistics?

PageWidth how to assign a value to a variable?

Posted: Thu Mar 13, 2014 3:47 pm
by dkelly
If your job is a single file use:



var curFileStats = new FileStatistics(job.getPath());

currentbook = curFileStats.getNumber("PageWidth");

PageWidth how to assign a value to a variable?

Posted: Sun Mar 16, 2014 1:08 am
by menglv
dkelly wrote: If your job is a single file use:



var curFileStats = new FileStatistics(job.getPath());

currentbook = curFileStats.getNumber("PageWidth");


I tried, but without success.

Can you give me an example of flow?







test.sflow

PageWidth how to assign a value to a variable?

Posted: Tue Mar 18, 2014 2:34 pm
by dkelly
Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.

PageWidth how to assign a value to a variable?

Posted: Thu Mar 20, 2014 5:39 am
by menglv
dkelly wrote: Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.






return value:undefined

PageWidth how to assign a value to a variable?

Posted: Sat Mar 22, 2014 1:45 am
by menglv
dkelly wrote: Your script doesn't follow the example I gave. You are not using the FileStatistics variable curFileStats to retrieve the PageHeight.






return value:undefined



Does anyone know what is the reason?

PageWidth how to assign a value to a variable?

Posted: Mon Mar 24, 2014 2:18 pm
by freddyp
The return value of a script expression is the "last" variable on a line of its own.



var result = "1";

result;



If the script expression is more than just one or two lines I recommend to structure it as follows: create a function that returns a value and call that function on the last line of your script expression. You do not have to do it like this, but it is generically applicable.



function someFunction(par1, par2)

{

var returnValue;

//perform stuff that gives returnValue the correct value



return returnValue;

}



someFunction("first parameter",second_parameter);



Freddy

PageWidth how to assign a value to a variable?

Posted: Tue Mar 25, 2014 6:50 am
by menglv
freddyp wrote: Freddy


Theresult of this variable is not important, the key is currentbook which returned the result is undefined. I want this currentbook value equals pdf's PageHeight.

PageWidth how to assign a value to a variable?

Posted: Tue Mar 25, 2014 2:36 pm
by freddyp
Then just write



currentbook;



as the last line of your script expression. I thought that was clear from the explanation.



Freddy