• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

InDesign Script Error 30477

New Here ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

351

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 31, 2024 Oct 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.

Votes

Translate

Translate
Participant ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

Looks like you have a typo on the word "substituir" in this line:

function substituicaoBasica(susbtituir, substituirPor, estilo){

 

Does that solve it?

 

Edit: Oh sorry, jsut realized it's spelled the same in both places, so that's probably not the issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

As the names are the same, it does not influence the code.
The only error is that InDesign does not recognize the paragraph style parameter, even though the style path and variable are correct.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines