Skip to main content
Known Participant
April 3, 2023
Question

InDesign Crash While executing this script

  • April 3, 2023
  • 2 replies
  • 289 views

Hi,

 

I have used the script in the SDK source. While executing this script the InDesign Application gets crashed. Please guide me on this.

 

 

InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
InterfacePtr<IScriptRunner> scriptRunner(scriptManager, UseDefaultIID());
PMString scriptCode;	
	scriptCode.Append("function IterateDocument(){");
	scriptCode.Append("var doc = app.activeDocument;");
	scriptCode.Append("doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;");
	scriptCode.Append("doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;");
	scriptCode.Append("for (var i = 0; i < doc.pages.length; i++)");
	scriptCode.Append("{");
	scriptCode.Append("var page = doc.pages[i];");
	scriptCode.Append("var pageHeight = page.bounds[2] - page.bounds[0];");
	scriptCode.Append("for (var j = 0; j < page.textFrames.length; j++) {");
	scriptCode.Append("var frame = page.textFrames[j];");
	scriptCode.Append("if (frame.overflows  == true && frame && frame.associatedXMLElement && frame.associatedXMLElement.markupTag && frame.associatedXMLElement.markupTag.name == 'products')");
	scriptCode.Append("{");
	scriptCode.Append("for(var k = frame.tables.length-1; k >= 0; k--) {");
	scriptCode.Append("var table = frame.tables[k];");
	scriptCode.Append("if (pageHeight < table.height) {");
	scriptCode.Append("AddColumnToTable(frame, i, table);");
	scriptCode.Append("}");
	scriptCode.Append("}");
	scriptCode.Append("}");
	scriptCode.Append("}");
	scriptCode.Append("}");
	scriptCode.Append("app.activeDocument.documentPreferences.facingPages = true;");	
	scriptCode.Append("}");
	scriptCode.Append("function AddColumnToTable (mySel,addPageLocation, originalTable)");
	scriptCode.Append("{");
	scriptCode.Append("app.activeDocument.documentPreferences.facingPages = false;");
	scriptCode.Append("var gb = mySel.geometricBounds;");
	scriptCode.Append("gb[2] = gb[0] + originalTable.height/2;");
	scriptCode.Append("gb= [95.891, 37.5, 640, 540];");
	scriptCode.Append("mySel.geometricBounds = gb;");
	scriptCode.Append("var newPage = app.activeDocument.pages.add(LocationOptions.AFTER, app.activeDocument.pages[addPageLocation]);");
	scriptCode.Append("var textframe = app.activeDocument.pages[addPageLocation+1].textFrames.add({geometricBounds:[95.891, 37.5, 640, 540]});");
	scriptCode.Append("mySel.nextTextFrame = textframe;");
	scriptCode.Append("textframe.fit(FitOptions.frameToContent);");
	scriptCode.Append("if(textframe.overflows  == true){");
	scriptCode.Append("addPageLocation = addPageLocation +1;");
	scriptCode.Append("AddColumnToTable (textframe,addPageLocation,originalTable);");
	scriptCode.Append("}");
	scriptCode.Append("}");

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

 

The issue is from the line 

 

scriptCode.Append("app.activeDocument.documentPreferences.facingPages = true;");

 

  

This topic has been closed for replies.

2 replies

Community Expert
April 6, 2023

Hi @Barathi,

I would suggest that you isolate all the script code in a jsx file and then test it. If you still find issues then post the jsx code and sample document to test it.

-Manan

-Manan
HARSHIKA_VERMA
Community Manager
Community Manager
April 5, 2023

Hi @Barathi,

 

Thank you for reaching out. Would you mind telling us if InDesign is crashing while using this script only? Please share the version of InDesign and the details of your operating system so that we can investigate on the issue.

 

Please generate logs from the log collector tool and upload them to a shared location such as CC or Dropbox and share the URL with me over a private message.

 

We will try our best to help.

 

Thanks,

Harshika