Copy link to clipboard
Copied
function creatStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn)
I have multiple main programs, and every time I've changed a parameter in the library, I have to go and change each of them, forgetting parts and getting errors that will make me look for half a day.
Is there any way to make:
creatStyle(......) ;
with
function creatStyle(......) ;
always be automation consistent.
I change the parameters of the function in the library, and it is automatically updated in the main program.
Copy link to clipboard
Copied
Hi @dublove consider this:
function createStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn) {
// ... do something with all the params
return newStyle;
};
function createDefaultStyle() {
var paraStn = 1;
var tabStn = 5;
var contiParaStn = 16;
var bodyParaStn = 20;
var headerParaStn = 2;
var bodyStn = 15;
var headerStn = 30;
var contiStn = 123;
var footerStn = 4356;
var capLStn = 1233;
var capCStn = 3;
var capCSDhtn = 4;
var newStyle = createStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn);
return newStyle;
};
You can make one function that wants every parameter. Then you can make another function that *calls* the first function, and supplies it with preset values for the parameters. So if you want to reuse a particular createStyle, make this second kind of function and to call it (from this script or the top-level script) just use:
var myStyle = createDefaultStyle();
Does that help?
- Mark
Copy link to clipboard
Copied
Hi m1b.
Thank you very much.
It's a little complicated. I'm afraid to move now.
Feels like I'll be cross-referencing a couple of my files now.
I'm intrigued and will definitely try it when I have time.
Copy link to clipboard
Copied
I still couldn't hold back my curiosity and tried it.
It suggests that newStyle is undefined, another variable issue across functions?
Copy link to clipboard
Copied
> I still couldn't hold back my curiosity and tried it. It suggests that newStyle is undefined, another variable issue across functions?
I didn't give you complete code, just a structural option. You would have to write the code to "create the style". I just showed you one way to do it without passing any parameters.
- Mark
Copy link to clipboard
Copied
Hi m1b.
Thank you very much.
I will try this program of yours again sometime.
There are some urgent matters that need to be taken care of right now.
Copy link to clipboard
Copied
in my main program
creatStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn);
and in the library publicLib.jsx the
fuction creatStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn);
with the same same parameter name.
Can I just pass it in a variable?
Copy link to clipboard
Copied
fuction creatStyle(paraStn, tabStn, contiParaStn, bodyParaStn, headerParaStn, bodyStn, headerStn, contiStn, footerStn, capLStn, capCStn, capCSDhtn);
Is not a function, (function is misspelled as fuction) , there are no opening and closing braces, and no code to run:
Copy link to clipboard
Copied
Hi rob day.
Thank you
The creatStyle misspelling has been corrected.
I have a complicated situation, and I'm not going to look into this issue for now, or it will get more complicated.
Copy link to clipboard
Copied
I have multiple main programs, and every time I've changed a parameter in the library,
If you are loading libraries the loaded functions should never change. So a global function might create a named style and check if it already exists. Then you would set the properties after the style is constructed:
var ps = makeParaStyle(app.activeDocument, "MyStyle")
//set the style object’s properties after it is constructed
ps.properties = {fillColor:"Black", fillTint:50}
/**
* Makes a new named Paragraph Style—if a style named n exists use that style
* @ param the document to add the style to
* @ param style style’s name
* @ return the new or existing paragraph style
*/
function makeParaStyle(d, n){
if (d.paragraphStyles.itemByName(n).isValid) {
return d.paragraphStyles.itemByName(n);
} else {
return d.paragraphStyles.add({name:n});
}
}
Copy link to clipboard
Copied
Hi @rob day
I'm not getting what you're saying.
What I'm asking is that there are too many function parameters, and I only want those parameters to appear once to minimize the problem of omissions due to modifications.
Copy link to clipboard
Copied
If your function has 12 parameters, so you have to include all 12 when you call the function.
This throws an error because I did not include the 2nd parameter (a string) at run time.
Copy link to clipboard
Copied
Hi rob day.
Thanks a lot.
Yes, I realized later that the number of parameters must be the same.
I have some urgent things to take care of right now.
I have used the traditional program. I will try again when I have time.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now