Highlighted

How to add word and image count values in C++

Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

Hi Professionals,

 

Can someone suggest me to the image and word count in C++. Please guide me

Rajendran
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I don't see any connection of the code that you shared with what you have asked. There is no attempt whatsoever of dealing with the query that you posted. Also i see a lot of issues with your code as such

  • You query the IDocument interface twice, and then check if the document is open or not. This will surely lead to a crash a runtime with no document open
  • Secondly i see that you are trying to use JS for getting the image and wordcount, i don't get the reason why you would do so in a C++ plugin, anyhow what is the variable myDocumentAction i don't see it defined anywhere in your script

Now my question is do you want to do this in C++ or JS as you have done already(tried). If it's JS, then i would suggest to use ExtendScript of VSCode to write and debug the code first and then intgrate it into the C++ plugin once you find it working.

If it's C++ then i suggest you first brush up your C++ skills, i see no structure in code, no checks for nill pointers etc. This is disaster waiting to happen, at this point diving into SDK would only confuse you.

To complete the answer is would point you to the interfaces and boss classes that might help you do this in C++, once you are comfortable with C++ in general and basics of InDesign SDK

  • Document boss class i.e. kDocBoss has an interfaces ILinksManager, that has the method GetLinkCount. This might be the one you should look at
  • Text a.k.a. stories are a bit complex to handle, i am myself not too hands on with this part of the sdk. However you will have to get the storylist from kDocBoss class, then iterate over each story to get the ITextModel interface. This interface has a method QueryStrand, using which you can get the strand that represents the content of the story i.e. kTextDataStrandBoss. Beyond this you will have to investigate yourself.

I hope you put in serious effort to learn the language and sdk, this is something that takes years to understand so its surely not a cakewalk or a quickfix thing that can be resolved by just asking and copying the code.

 

-Manan

TOPICS
How to, SDK

Views

949

Likes

Translate

Translate

Report

Report
This conversation has been locked.

How to add word and image count values in C++

Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

Hi Professionals,

 

Can someone suggest me to the image and word count in C++. Please guide me

Rajendran
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I don't see any connection of the code that you shared with what you have asked. There is no attempt whatsoever of dealing with the query that you posted. Also i see a lot of issues with your code as such

  • You query the IDocument interface twice, and then check if the document is open or not. This will surely lead to a crash a runtime with no document open
  • Secondly i see that you are trying to use JS for getting the image and wordcount, i don't get the reason why you would do so in a C++ plugin, anyhow what is the variable myDocumentAction i don't see it defined anywhere in your script

Now my question is do you want to do this in C++ or JS as you have done already(tried). If it's JS, then i would suggest to use ExtendScript of VSCode to write and debug the code first and then intgrate it into the C++ plugin once you find it working.

If it's C++ then i suggest you first brush up your C++ skills, i see no structure in code, no checks for nill pointers etc. This is disaster waiting to happen, at this point diving into SDK would only confuse you.

To complete the answer is would point you to the interfaces and boss classes that might help you do this in C++, once you are comfortable with C++ in general and basics of InDesign SDK

  • Document boss class i.e. kDocBoss has an interfaces ILinksManager, that has the method GetLinkCount. This might be the one you should look at
  • Text a.k.a. stories are a bit complex to handle, i am myself not too hands on with this part of the sdk. However you will have to get the storylist from kDocBoss class, then iterate over each story to get the ITextModel interface. This interface has a method QueryStrand, using which you can get the strand that represents the content of the story i.e. kTextDataStrandBoss. Beyond this you will have to investigate yourself.

I hope you put in serious effort to learn the language and sdk, this is something that takes years to understand so its surely not a cakewalk or a quickfix thing that can be resolved by just asking and copying the code.

 

-Manan

TOPICS
How to, SDK

Views

950

Likes

Translate

Translate

Report

Report
May 05, 2020 0
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

Sorry i added the response to another question to this post.

Well what all did you try so far? SDK code tend to be big with lots of code scattered around so unless you identify the basic workflow you will never understand it. For ex:- Whare do you want to add these count values? Is the problem getting these values of adding these values to whatever place you are trying to add those

 

-Manan

Likes

Translate

Translate

Report

Report
May 05, 2020 1
Community Beginner ,
May 06, 2020

Copy link to clipboard

Copied

I want to add the count values inside the panel and I have the code in Javascript but while calling the script it doesn't work so I used to call the count values in C++ and I want to know how to define the count value

Rajendran

Likes

Translate

Translate

Report

Report
May 06, 2020 0
Most Valuable Participant ,
May 06, 2020

Copy link to clipboard

Copied

Are you experienced in working the InDesign API in C++? If so, please show your code so far. If not, perhaps we could focus on why yout script fails.

Likes

Translate

Translate

Report

Report
May 06, 2020 0
Community Beginner ,
May 06, 2020

Copy link to clipboard

Copied

I have attached the code for the reference


#include "VCPlugInHeaders.h"

// General includes:
#include "CObserver.h"
#include "ISubject.h"
#include "IControlView.h"
#include "IEVEUtils.h"
#include "Utils.h"
#include "FIleUtils.h"
#include "IActiveContext.h"
#include "IDocumentUIUtils.h"
#include "IDocument.h"
#include "IDocumentList.h"
#include "DocumentID.h"
#include "IDocumentUtils.h"
// Interface includes

#include "IPanelControlData.h"
#include "IStringData.h"
#include "IExtendScriptUtils.h"
#include "IScriptArgs.h"
#include "SDKLayoutHelper.h"
#include "IPageList.h"
#include "ILayoutUIUtils.h"

// Project includes:

#include "IStringListControlData.h"
#include "IScriptUtils.h"
#include "IPMStream.h"
#include "ISpreadList.h"
#include "IScriptManager.h"
#include "IScriptRunner.h"
#include "IScriptUtils.h"
#include "JavaScriptID.h"
#include "IPlugInList.h"
#include "CAlert.h"
#include "IDocument.h"

UIDRef CustomHttpLinkUIObserver::GetSpreadLayerRef()
{
IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();

InterfacePtr<IPageList> pagelist(doc, IID_IPAGELIST);
int32 count = pagelist->GetPageCount();
IDocument* document = Utils<ILayoutUIUtils>()->GetFrontDocument();
int32 aWarning = 0;
if (document== nil)
{



}

// IDatabase* database = ::GetDatabase((IPMUnknown*)document);
UIDRef spreadRef;
do
{
IDocument* document1 = GetExecutionContextSession()->GetActiveContext()->GetContextDocument();
if (document1 == nil)
{
aWarning = CAlert::ModalAlert("Please open the document. No active document", "Ok", "Continue", kNullString, 1, CAlert::eWarningIcon);
break;
}

} while (kFalse);

return spreadRef;

}
void CustomHttpLinkUIObserver::loadFilesInDropdown()
{
InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
InterfacePtr<IScriptRunner> scriptRunner(scriptManager, UseDefaultIID());

PMString scriptCode;


scriptCode.Append("var myDoc1 = app.activeDocument;");

scriptCode.Append("var wordCount = 0;");
scriptCode.Append("for(var i=0;i<app.activeDocument.stories.length>i;i++)");
scriptCode.Append("wordCount += app.activeDocument.stories[i].words.length;");
scriptCode.Append("myDocumentAction.countPanel.countWord = add('WordCount : ' + wordCount);");
scriptCode.Append("var doc = app.documents[0];");
scriptCode.Append("var imageCount = doc.allGraphics.length;");
scriptCode.Append("myDocumentAction.countPanel.countImage = add('Image Count : ' + imageCount);");


//scriptCode.Append("};");
//scriptCode.Append("};");
//scriptCode.Append("};");
//scriptCode.Append("};");

PMString engineName("myengine");
int32 errorCode = Utils<IExtendScriptUtils>()->RunScriptInEngine(engineName, scriptCode);
//scriptRunner->RunScript(scriptCode);
Utils<IScriptArgs>()->Clear();

 

Rajendran

Likes

Translate

Translate

Report

Report
May 06, 2020 0
Explorer ,
May 12, 2020

Copy link to clipboard

Copied

try this,


scriptCode.Append("var wordCount = 0;");
scriptCode.Append("for(var i=0;i<app.activeDocument.stories.length>i;i++)");
scriptCode.Append("wordCount += app.activeDocument.stories[i].words.length;");
scriptCode.Append("var doc = app.documents[0];");
scriptCode.Append("var imageCount = doc.allGraphics.length;");

Nithu

Likes

Translate

Translate

Report

Report
May 12, 2020 1
Adobe Community Professional ,
May 06, 2020

Copy link to clipboard

Copied

I don't see any connection of the code that you shared with what you have asked. There is no attempt whatsoever of dealing with the query that you posted. Also i see a lot of issues with your code as such

  • You query the IDocument interface twice, and then check if the document is open or not. This will surely lead to a crash a runtime with no document open
  • Secondly i see that you are trying to use JS for getting the image and wordcount, i don't get the reason why you would do so in a C++ plugin, anyhow what is the variable myDocumentAction i don't see it defined anywhere in your script

Now my question is do you want to do this in C++ or JS as you have done already(tried). If it's JS, then i would suggest to use ExtendScript of VSCode to write and debug the code first and then intgrate it into the C++ plugin once you find it working.

If it's C++ then i suggest you first brush up your C++ skills, i see no structure in code, no checks for nill pointers etc. This is disaster waiting to happen, at this point diving into SDK would only confuse you.

To complete the answer is would point you to the interfaces and boss classes that might help you do this in C++, once you are comfortable with C++ in general and basics of InDesign SDK

  • Document boss class i.e. kDocBoss has an interfaces ILinksManager, that has the method GetLinkCount. This might be the one you should look at
  • Text a.k.a. stories are a bit complex to handle, i am myself not too hands on with this part of the sdk. However you will have to get the storylist from kDocBoss class, then iterate over each story to get the ITextModel interface. This interface has a method QueryStrand, using which you can get the strand that represents the content of the story i.e. kTextDataStrandBoss. Beyond this you will have to investigate yourself.

I hope you put in serious effort to learn the language and sdk, this is something that takes years to understand so its surely not a cakewalk or a quickfix thing that can be resolved by just asking and copying the code.

 

-Manan

Likes

Translate

Translate

Report

Report
May 06, 2020 2
Adobe Employee ,
Jun 11, 2020

Copy link to clipboard

Copied

duplicate thread/spam, locked

Likes

Translate

Translate

Report

Report
Jun 11, 2020 0