Skip to main content
New Participant
October 31, 2024
Answered

InDesign Script Error 30477

  • October 31, 2024
  • 4 replies
  • 1600 views

Hello Everyone,

 

I'm a beginner JS developer.

I need create a function to use at different times. When I indicate a paragraphStyle as a parameter, there is the following error:

 

Example:

function basicFunction(style){
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING
app.findGrepPreferences.appliedParagraphStyle = style
...

}

var author = app.activeDocument.paragraphStyleGroups.itemByName("authors").paragraphStyles.itemByName("first author")

basicFunction(author);

 

The error:

"Error Number: 30477
Error String: Invalid value for set property 'AppliedParagraphyStyle'. Expected String, ParagraphStyle or NothingEnum enumerator, but received nothing".

 

I didn't find anything on the forums about styles as parameters.

 

Thanks a lot for the help!

Correct answer Peter Kahrel

Your code works for me, as it did for @danaken3. If the group and style names look correct, maybe an invisoble character slipped into the style or group name. That can happen when you copy some string with a trailing return. When you paste that into the style name field the return comes along. You can't see it and it fails to match what you're asking for. So check again the names of the group and the style.

4 replies

Braniac
November 1, 2024

Add more error checking.

E.g. before picking up the activeDocument, check documents.length so that there is a document at all.

Same for your cascade of itemByName expressions - each may yield an empty / invalid result - an allowed outcome that won't immediately throw an error.

Evaluate each itemByName in a separate statement assigned to an intermediate variable, and check result.isValid that the result is not empty / your style group and style are actually found.

As others already mentioned, Javascript does not require semicolons to separate statements, but it will then occasionally also disagree with your intuition where the statements end.

Wrap up your code in a function that you call once, in order to keep variables local that otherwise are seen by functions where you would not expect them.

As you are hunting gremlins, does your larger script use a targetengine? If so, make it first run without, using the implicit targetengine "main", so you don't inherit leftovers from previous runs.

brian_p_dts
Braniac
October 31, 2024

You may also want to put a semicolon after .....("first author"), or rather looking more closely at the code, semicolons at the end of each distinct line (except func definitions and if statements, etc.)

Peter KahrelCorrect answer
Braniac
October 31, 2024

Your code works for me, as it did for @danaken3. If the group and style names look correct, maybe an invisoble character slipped into the style or group name. That can happen when you copy some string with a trailing return. When you paste that into the style name field the return comes along. You can't see it and it fails to match what you're asking for. So check again the names of the group and the style.

New Participant
October 31, 2024

Doing tests, I saw the name was right. The variable worked outside the function.
I deleted another function (between the first and the call) that, in some way, even without being called, was disturbing the previous. I moved all the functions to the end of the code, leaving only the function calls at the beginning. It worked, although i didn't quite understand.

Thank you all for your help

 

Regards

danaken3
Participating Frequently
October 31, 2024

Seems to work ok for me. Have you double-checked the names of your paragraph style group and paragraph style (mismatched capitalization, trailing spaces at the end of the name, etc.)?

 

Perhaps share the part of your code that you left out, in case there are any possible issues there?

danaken3
Participating Frequently
October 31, 2024

Or is there any chance the "first author" style is not actually saved inside the "authors" folder? Can be easy to miss but the style name should have an indent if it is actually inside the folder.

New Participant
October 31, 2024

The names and the folders are correct, including the variable.

Actually, it works outside the function. However, when I use the paragraphStyle as a parameter, doesn't work.

 

The code is a simple find and change function:


function substituicaoBasica(susbtituir, substituirPor, estilo){
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING
app.findGrepPreferences.appliedParagraphStyle = estilo
app.findGrepPreferences.findWhat = susbtituir
app.changeGrepPreferences.changeTo = substituirPor
var verificarSeExiste = app.activeDocument.findGrep()
if (verificarSeExiste.length > 0) {
app.activeDocument.changeGrep()
}
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
}

 

substituicaoBasica("find", "change", style);