How to set specific EdgeStrokeWeight for each cell properties?

Community Beginner ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

74

Likes

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 Expert , Aug 26, 2022 Aug 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, 
...

Likes

Translate

Translate
Community Expert ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

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 )

Likes

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 ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

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');

BeforeScript.PNGAfterScript.PNG

 

 

Likes

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

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 )

Likes

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

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};

 

Likes

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 ,
Aug 26, 2022 Aug 26, 2022

Copy link to clipboard

Copied

LATEST

Hi Uwe,

 

I missed the cell object. Now it is working fine. Thanks for your help.

Likes

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