Skip to main content
dublove
Legend
Jun 20, 2025 1:04 PM UTC
Question

How can I make the function parameters in the main program automatically same as in the library?

I have multiple parameters in my library function like this:
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.

12 replies

rob day
Community Expert
Community Expert
Jun 20, 2025 3:18 PM UTC

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});
    }
}

 

 

Translate
dublove
dubloveAuthor
Legend
Jun 20, 2025 3:34 PM UTC

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.

Translate
rob day
Community Expert
Community Expert
Jun 20, 2025 3:49 PM UTC

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.

 

Translate
m1b
Community Expert
Community Expert
Jun 20, 2025 1:20 PM UTC

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

Translate
dublove
dubloveAuthor
Legend
Jun 20, 2025 3:14 PM UTC

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.

Translate