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

Script: "No such Element" error when looking for a specific paragraph

Community Beginner ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

Hello,

I've searched an answer to this everywhere, but in vain... My script looks for a specific paragraph in a textframe, based on its index in TextFrame.Paragraphs. So far so good, but in one of the files I ran my script on, it keeps blocking on a specific textframe when looking for the second paragraph in it.

I tried testing first that the index of the paragraph was within the TextFrame.Paragraphs.Count, but even so, it doesn't work : it confirms the textframe hold 2 paragraphs (TextFrame.Paragrephs.Count=2), but insists that TextFrame.Paragraphs(2) doesn't exist.

I twisted and turned my code around, trying to figure out why, in vain so far. And when looking at the textframe with the hidden characters shown, it shows clearly the two paragraphs, so I don't understand what happens here...

Here's a snippet of my code, where the error occurs:

paraNb = Cint(Para)

paraCnt = docTF.Paragraphs.Count

If paraNb > 1 Then

     If paraNb = paraCnt Then

          test = True

     End If

End If

Set docPar = docTF.Paragraphs(paraNb) 'This is where the error occurs

TOPICS
Scripting

Views

2.8K

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 Beginner , Mar 26, 2017 Mar 26, 2017

Once again, my bad, I should also have posted my answer here, and not only in my other post...

The problem was with variable types: I was casting my variable paraNb as an Integer, when Paragraphs() requires a Double.

As long as paraNb value was 1, it was still OK, but as soon as it got to 2, Illustrator couldn't take it as a Double, it was obviously an Integer.

The issue here should have been reported as wrong type, which would have pointed me in the right direction from the start, but Illustrato

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

it's not something as simple as the index starting with 0, is it?

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 Beginner ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

No, it works perfectly with the other textframes, that contains only 1 paragraph, and docTF.Paragraphs(paraNb) with paraNb=1 causes no error. On another file, where a textframe includes 8 paragraphs, there was no error either, that's why I don't understand why I get this error...

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 ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

i'd suggest you take this over to the scripting board, in that case. i'll see if i can find a mod to move it.

Illustrator Scripting

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 Beginner ,
Mar 21, 2017 Mar 21, 2017

Copy link to clipboard

Copied

My bad, should have thought about it in the first place. I copied my post 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
Guide ,
Mar 26, 2017 Mar 26, 2017

Copy link to clipboard

Copied

i would guess there is something about that text frame that has illy confused.

if you copy the text to a notepad app. then draw a new text frame and re copy and paste the text back in to illy does it still wig out on the same frame?

after that i would be trying to see if there is something strange in the formatting, special chars or something. maybe add a 3rd parragraph. and or remove the gap between 1 and 2 combining them into 1 parragraph. at each stage query the dom to see whats going on.

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 Beginner ,
Mar 26, 2017 Mar 26, 2017

Copy link to clipboard

Copied

Once again, my bad, I should also have posted my answer here, and not only in my other post...

The problem was with variable types: I was casting my variable paraNb as an Integer, when Paragraphs() requires a Double.

As long as paraNb value was 1, it was still OK, but as soon as it got to 2, Illustrator couldn't take it as a Double, it was obviously an Integer.

The issue here should have been reported as wrong type, which would have pointed me in the right direction from the start, but Illustrator reported it as though Paragraphs(Int) is an unknown element (when Paragraphs(Dbl) isn't)...

Anyway, I corrected my cast in paraNb = CDbl(Para) and haven't had any issue with it ever since.

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 ,
Mar 27, 2017 Mar 27, 2017

Copy link to clipboard

Copied

LATEST

thanks for posting back your results.

i work mainly with javascript, and i had not even thought about type of variable.

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