• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to know if a cellStyle attribute is "ignored"?

Explorer ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Hi everyone,

 

I'm working on a script that changes the cell styles of the selected row by a new one (chosen from my cell styles list). But I need to analyse the previous row cell styles in order to override the cell style or not. So I check if a stroke exist or not, which seems easy, but… if an attribute of a cell style is "ignored", example below:

Capture d’écran 2020-09-15 à 15.32.26.png

I need to know if something has been define. With this example if I write:

alert(app.activeDocument.cellStyles.item("Total").bottomEdgeStrokeColor.name)

it returns "Null is not an object". I assume it is because it's not define, so it could not return anything. So how can I know if it could return anything? For information, if I check bottomEdgeStrokeWeight it returns NOTHING, not null.

 

Hope I was clear enough, have a nice day,

Nicolas

TOPICS
Scripting

Views

353

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

Explorer , Sep 16, 2020 Sep 16, 2020

Hello Uwe,

 

This night let me understand what was the problem, so, here's the solution:

Actually NothingEnum.NOTHING works fine, it's just I tried to trigger it with "bottomEdgeStrokeColor" instead of "bottomEdgeStrokeWeight" as I was trying previously. In the documentation, there's no mention of NothingEnum.NOTHING it's only Swatch for bottomEdgeStrokeColor, so that's normal I could not find anything.

 

Here's an indesign example with a table that has three types of cell styles:

– header: top stroke

...

Votes

Translate

Translate
Community Expert ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Hi Nicolas,

inspect the DOM documentation for the cellStyle object:

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

You will notice that a lot of property values ( by far not all ) can be:

NothingEnum.NOTHING

You could test for this.

 

Regards,
Uwe Laubender

( ACP )

Votes

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
Explorer ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Hello Uwe,

 

I tried this property, but unfortunately, it does not work.

The only way I found was not really clean but at least it works…

 

If the ignored value is NOTHING, I add a parseFloat() to the variable, it returns a very long number (like 5458654).

So if the parseFloat(topEdgeStrokeWeight) value  is superior to something like 10 or equal to 0, I consider the stroke does not exists. Strokes on my documents are usualy between 0.3 and 1.

 

Maby I'm not using NothingEnum.NOTHING the proper way, but I can't find how it should work.

 

Thanks for all your answers,

Nicolas

Votes

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 ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Yes, as Uwe mentioned, there is no single value that you can check to ascertain if a particular property is set or not. In this case, you could compare with the NothingEnum.Nothing. It depends upon case by case basis, for ex. when checking some objects, we can ascertain their veracity by using the isValid property. The best way is to look at the DOM object/debug the code for various use cases and identify values that represent the absence/presence of something.

-Manan

Votes

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 ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Also: The DOM suggests that sometimes also a string can be a value.

In this case you could test for an empty string with:

== ""

 

Regards,
Uwe Laubender

( ACP )

Votes

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 ,
Sep 15, 2020 Sep 15, 2020

Copy link to clipboard

Copied

Hi Nicolas,

then post a functional code snippet we could test.
Also a sample InDesign document along with it.

Use Dropbox or a similar service and post the link.

 

Thanks,
Uwe Laubender

( ACP )

Votes

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
Explorer ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Hello Uwe,

 

This night let me understand what was the problem, so, here's the solution:

Actually NothingEnum.NOTHING works fine, it's just I tried to trigger it with "bottomEdgeStrokeColor" instead of "bottomEdgeStrokeWeight" as I was trying previously. In the documentation, there's no mention of NothingEnum.NOTHING it's only Swatch for bottomEdgeStrokeColor, so that's normal I could not find anything.

 

Here's an indesign example with a table that has three types of cell styles:

– header: top stroke at 1 pt, bottom stroke forced to 0 pt, the other edges are default values;

– body: default stroke, it takes all the table style values;

– footer: bottom stroke at 1 pt, the other edges are default values.

 

I wrote this little script which checks the bottomEdgeStrokeWeight of a selected cell:

var selection = app.selection[0]

if (selection.cells[0].appliedCellStyle.bottomEdgeStrokeWeight == NothingEnum.NOTHING) {
	alert("NothingEnum.NOTHING found, table styles set by default")
} else if (selection.cells[0].appliedCellStyle.bottomEdgeStrokeWeight > 0) {
	alert("bottom stroke exists, weight superior to 0")
} else if (selection.cells[0].appliedCellStyle.bottomEdgeStrokeWeight == 0) {
	alert("stroke at 0 pt is forced")
}

I still don't know how to prevent error with bottomEdgeStrokeColor but for my needs, it works fine with bottomEdgeStrokeWeight.

 

The indesign example file: https://www.dropbox.com/s/jobjm6jrqvmjohr/exemple-NOTHING.indd?dl=0

 

I hope it will help,

Nicolas

Votes

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 ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Can you check if bottomEdgeStrokeColor == app.document[0].swatches[0], which is the None color?

Votes

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
Explorer ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Hello Brian,

 

it works only if I selected "[None]" for the bottom stroke color.

But I finally managed to trigger bottomEdgeStrokeColor when it's ignore if I compare it to null:

if (selection.cells[0].appliedCellStyle.bottomEdgeStrokeColor == null) {
alert("No color")
}

Nicolas

Votes

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 ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

LATEST

Hi Brian,

yes there is a difference if color [None] is applied or if no color is applied, so the value of the property is ignored.

 

Regards,
Uwe Laubender

( ACP )

Votes

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