Highlighted

Fetching character count values in C++

Explorer ,
Jun 03, 2020

Copy link to clipboard

Copied

Hi,

 

IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(doc, UseDefaultIID());

Text::StoryRange storyRange = textStoryThreadDict->GetThreadBlockTextRange();

PMString characterCount;
characterCount.AppendNumber(storyRange);
CAlert::InformationAlert(characterCount);

 

it shows an error that "cannot convert argument 1 from 'Text::StoryRange' to 'int32' " how can  I solve this error please guide me.

Nithu
TOPICS
Feature request, How to, SDK

Views

526

Likes

Translate

Translate

Report

Report
This conversation has been locked.

Fetching character count values in C++

Explorer ,
Jun 03, 2020

Copy link to clipboard

Copied

Hi,

 

IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(doc, UseDefaultIID());

Text::StoryRange storyRange = textStoryThreadDict->GetThreadBlockTextRange();

PMString characterCount;
characterCount.AppendNumber(storyRange);
CAlert::InformationAlert(characterCount);

 

it shows an error that "cannot convert argument 1 from 'Text::StoryRange' to 'int32' " how can  I solve this error please guide me.

Nithu
TOPICS
Feature request, How to, SDK

Views

527

Likes

Translate

Translate

Report

Report
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

The Text::StoryRange is a class not an int32 variable that you can pass to AppendNumber method, there is not method defined for this conversion as well. Try the following

TextIndex blockStart = storyRange.GetStart();
TextIndex blockEnd = storyRange.GetEnd();

 

This will give you the start and end of the block. See the class details in the sdk for more information

 

-Manan

Likes

Translate

Translate

Report

Report
Jun 03, 2020 0
Explorer ,
Jun 06, 2020

Copy link to clipboard

Copied

Hi,

After using the start and end block InDesign get crashes is there is any other way to get the character count values

Nithu

Likes

Translate

Translate

Report

Report
Jun 06, 2020 0
Explorer ,
Jun 08, 2020

Copy link to clipboard

Copied

Hi,

I'm still struggling with the query I've posted. Can someone give me a solution..

Nithu

Likes

Translate

Translate

Report

Report
Jun 08, 2020 0
Most Valuable Participant ,
Jun 09, 2020

Copy link to clipboard

Copied

Of course it crashes:

 

CAlert::InformationAlert(characterCount);

 

This attempts to show 'characterCount' as if it's a string. But it is not -- it is a number. This was told you before in https://community.adobe.com/t5/indesign/plugin-creation-in-indesign/td-p/11119241?page=1

 

As we already explained to your alias/alter ego/coworker Jothi, you cannot learn InDesign SDK programming through cargo cult programming. You will have to properly learn C++ first; not only just the basics but every single detail of it. The SDK is meant for advanced programmers only, and there is no "beginner friendly" path into it.

Likes

Translate

Translate

Report

Report
Jun 09, 2020 1
Adobe Community Professional ,
Jun 09, 2020

Copy link to clipboard

Copied

To add to what Jongware mentioned and i have been telling you guys time and again that you need to learn stuff. I would add another thing to it, i gave you an answer on what sdk says, agreed that you don't have much experience with sdk but if you get a crash and you are asking for an alternative then it means you are finding faults with the sdk. Why do you think the sdk architect would create another route and leave a route that seems to be documented for this purpose susceptible to a crash? The plausible scenarios that i can think of

  • There are muliple ways to do things in an sdk for sure, but that does not mean a way would lead to undefined behaviour or crash. See the documentation, experiment, you might not be handling an error condition, like checking for null values, non negative indexes returned etc
  • The input to the api is not what it expects, Try varying the input, make it as simple as possible to atleast get it working. Once you have a working use case you can build from there to identify when an api works and when it does not

For me the key to learning any programming language is debugging your way out. Frankly speaking i don't rate myself even decent in C++ but i can surely debug things. If you let your guard down at the first crash without debugging the cause, i am afraid you are in the wrong trade here.

 

-Manan

Likes

Translate

Translate

Report

Report
Jun 09, 2020 2
Adobe Employee ,
Jun 11, 2020

Copy link to clipboard

Copied

duplicate thread locked

Likes

Translate

Translate

Report

Report
Jun 11, 2020 0