Skip to main content
Known Participant
August 25, 2022
Answered

How to set specific EdgeStrokeWeight for each cell properties?

  • August 25, 2022
  • 2 replies
  • 603 views

I try to set specific EdgeStrokeWeight for each cell properties.

cells[0].properties = {topEdgeStrokeWeight:1, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[1].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[2].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:1, leftEdgeStrokeWeight:1};

It is not working. All side, borders are applied.

This topic has been closed for replies.
Correct answer Laubender

Hm…

Will it work, if you address the cells directly, eg. by using a selection of the table through the GUI ?

// Table selected:
var table = app.selection[0];
var cells = table.cells.everyItem().getElements();

cells[0].properties = {topEdgeStrokeWeight:1, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[1].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[2].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:1, leftEdgeStrokeWeight:1};

 

I had no issue when I did that with a simple test document.

 

Did not look much into your code, but do you really address cell objects on your page?

Check what exactly is in variable attCellsScript when running evaluateXPathExpression().

 

As far as I know an array of xmlElements should be returned.

And every element in that array could have a property cells.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#XMLElement.html

 

Some dummy code to test for cell objects in the returned array of xmlElements:

var xmlElementsArray = doc.xmlElements[0].evaluateXPathExpression("//"+cell );

	for( var n=0; n<xmlElementsArray.length; n++ )
	{
		$.writeln( n +"\t"+ xmlElementsArray[n].cells.length )
	};

 

Regards,
Uwe Laubender
( Adobe Community Professional )

2 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
August 26, 2022

Hm…

Will it work, if you address the cells directly, eg. by using a selection of the table through the GUI ?

// Table selected:
var table = app.selection[0];
var cells = table.cells.everyItem().getElements();

cells[0].properties = {topEdgeStrokeWeight:1, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[1].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[2].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:1, leftEdgeStrokeWeight:1};

 

I had no issue when I did that with a simple test document.

 

Did not look much into your code, but do you really address cell objects on your page?

Check what exactly is in variable attCellsScript when running evaluateXPathExpression().

 

As far as I know an array of xmlElements should be returned.

And every element in that array could have a property cells.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#XMLElement.html

 

Some dummy code to test for cell objects in the returned array of xmlElements:

var xmlElementsArray = doc.xmlElements[0].evaluateXPathExpression("//"+cell );

	for( var n=0; n<xmlElementsArray.length; n++ )
	{
		$.writeln( n +"\t"+ xmlElementsArray[n].cells.length )
	};

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Known Participant
August 26, 2022

Hi Uwe,

 

I tried as per your suggestion, it is working. For dynamic, it is not working based on the cell index.

var table = app.activeDocument.stories.everyItem().tables.everyItem();//app.selection[0];
var cells = table.cells.everyItem().getElements();

cells[0].properties = {topEdgeStrokeWeight:1, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[1].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:1};
cells[2].properties = {topEdgeStrokeWeight:0, rightEdgeStrokeWeight:1, bottomEdgeStrokeWeight:1, leftEdgeStrokeWeight:1};

 

Community Expert
August 25, 2022

Hi @Arunkumar25715058ufpl ,

please show more of your code.

Especially how you access the table and do the cells array or cells collection.

And show a screenshot of the table before and after running the script.

 

I tested your code OK on a table with 4 columns and 4 rows where every stroke weight was set to 0 through the GUI.

InDesign 2022 version 17.4.0 on Windows 10.

 

What's your version of InDesign and operating system?
Could you share a sample table?

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Known Participant
August 26, 2022

Hi Uwe,

 

I am using OS is Windows 10 Enterprise and Adobe InDesign 2020.

 

XML code

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
<para border="1" ids="table"><emphasis><table xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" type="simple_table" aid:trows="3" aid:tcols="1"><cell aid:table="cell"  valign="top" style="width:461.55pt;border:solid windowtext 1.0pt;border-bottom:none" aid5:cellstyle="lrtEdgeStrokeWeight" type="simple_table" aid:ccolwidth="545" aid:crows="1" aid:ccols="1"><para ids="Body1"><emphasis ids="normal"><emphasis role="underline">Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis></emphasis></para>

<para ids="Body1"><emphasis ids="normal">Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis>            </para>
</cell><cell aid:table="cell"  valign="top" style="width:461.55pt;border-top:none;border-left:solid windowtext 1.0pt;border-bottom:none;border-right:solid windowtext 1.0pt" aid5:cellstyle="lrEdgeStrokeWeight" type="simple_table" aid:ccolwidth="545" aid:crows="1" aid:ccols="1"><para ids="Body1"><emphasis ids="normal">Proceed to click the paragraph dialog box launcher on the page layout tab:</emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab:</emphasis></emphasis>            </para>
<para ids="Body1"><emphasis ids="normal">Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis>            </para>
</cell><cell aid:table="cell"  valign="top" style="width:461.55pt;border:solid windowtext 1.0pt;border-top:none" aid5:cellstyle="lrbEdgeStrokeWeight" type="simple_table" aid:ccolwidth="545" aid:crows="1" aid:ccols="1"><para ids="Body1"><emphasis ids="normal">Proceed to click the paragraph dialog box launcher on the page layout tab:</emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab</emphasis></emphasis>            </para>
<para ids="Body1" role="Bullet"><emphasis ids="normal"><emphasis role="tab">– Proceed to click the paragraph dialog box launcher on the page layout tab.</emphasis></emphasis>            </para>
</cell></table></emphasis></para></Root>

Script

var doc = app.activeDocument; 


var attCellsScript = doc.xmlElements[0].evaluateXPathExpression("//cell");
var j;
for (j = 0;  j < attCellsScript.length; j++)
{
	var getCellStyleVal = attCellsScript[j].xmlAttributes.itemByName("aid5:cellstyle").value;
	var splitCellStyleVal = getCellStyleVal.split("EdgeStroke");
	var borderData = splitCellStyleVal[0];
	
	var splitCharArr = borderData.split(/(?!$)/);
	var topBorder = 0;
	var rightBorder = 0;
	var bottomBorder = 0;
	var leftBorder = 0;
	for(var cc=0;cc<splitCharArr.length;cc++){
		if(splitCharArr[cc] == 't'){
			topBorder = 1;
		}
		if(splitCharArr[cc] == 'r'){
			rightBorder = 1;
		}
		if(splitCharArr[cc] == 'b'){
			bottomBorder = 1;
		}
		if(splitCharArr[cc] == 'l'){
			leftBorder = 1;
		}
	}
	attCellsScript[j].properties = {topEdgeStrokeWeight:topBorder, rightEdgeStrokeWeight:rightBorder, bottomEdgeStrokeWeight:bottomBorder, leftEdgeStrokeWeight:leftBorder};
	
}
alert('Process Completed');