How to get reference to the first body row on page in a long table?

Guru ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Dear forum,

I have a long table which is threaded among several text frames (pages). I want to get the reference to the first body row in each frame so that to check if it contains a product name. (I can do this by checking if all the cells in the row have been merged.)

04-01-2017 21-36-26.png

Since a table looks like a single character for script, I don’t see a straightforward way to achieve my goal.

So far, I solved it in a sloppy way: I check the baseline of the 1st insertion point of the 1st cell in the row.

else if (RoundString(row.cells[0].insertionPoints[0].baseline, 1) == firstRowBaseline && mainRow != null) {

Is there a more elegant solution?

Thank you in advance!

Regards,
Kasyan

TOPICS
Scripting

Views

5.6K

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

Guru , Jan 04, 2017 Jan 04, 2017

Likes

Translate

Translate
Guru ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Hi Kasyan

1e6 is not HEX it's DEC the number after the e is the amount of zeros.

1e1 == 10

1e-1 == 0.1

So 1e6 is 1000000 just in less keystrokes. It's a bit less error prone when there's a lot of 0's

0xe1 == 225 "0x" intro means HEX number so e1  is 225

0123 == 83 "0" intro means OCT so 123 is 83

Therefore:

100 === 1e2

1e2 === 0x64

0x64 === 0144

All this is true is our little Adobeland world, in the wider world there are other ones see New number and Math features in ES6

I still plan on writing a few blog articles on my site and one of  the topics I plan on covering is symbolism.

It will cover the above and a wide range of things like the use all different types of symbols and the pros and cons (there's quite a lot of both) of using them.

10.4532446463423216 | 0 === 10 // quicker than Math.floor(4325436.3546346724357) but not too readable.

If you want you can be the very first and probably the very last person to subscribe to my site. (Not even my dads subscribed and he's a really nice guy)

http://creative-scripts.com/

I can guarantee 02 things 100%

1e0) I will not pass on your mail to anybody or send any spam

0x2) You will not get sick of the multitude of post notifications, My last 2 (and first 2) posts were November 2014

Still I do have plans for a couple of quite good one, not likely to be more than 3 a year.

The other week I was contacted by someone from a large multinational who saw the site and ordered a script from me that payed for the site so far

Regards

Trevor

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
Guru ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Thank you again, Trevor!

Now everything is clear to me. I had no chance to study maths at school so had no idea about such elementary things.

Yes, I subscribed to your blog: sure I won't be the one and only your subscriber if you start writing some posts there.

Regards,
Kasyan

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
Guru ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

@Marc,

True hair split there, but I was comparing 2 functions that people use and not 2 truly comparable functions.

@Kasyan

I don't use the above script too much, for these sorts of petty functions the extra time is normally very insignificant and only relevant for server usage that have to be really efficient. The results are very interesting never the less. If you stick some DOM function in the loop that's going to normally going to make the fine tuning pretty pointless. see the below example.

The real value of the above snippet is for real functions.

#include "/Users/Trevor/Documents/Adobe Scripts/Scripts Panel/Functions/function tests/Compare Functions.jsx";

var doc = app.activeDocument;

function While(n) {

    var r;

    while (n--) {

        r = doc.rectangles.add();

        r.remove();

    }

}

function For(n) {

    var r;

    for (; n >= 0; n--) {

        r = doc.rectangles.add();

        r.remove();

    }

}

$.writeln(compare([For, While], 1, 1e5, 3));

/**********************************************************************

Test Started: Wed Jan 11 2017 18:57:07 GMT+0200

Functions Tested: (Listed in order of performance) "For", "While"

Arguments: 100000

Runs: 1

Test Took: 835608ms

**********************************************************************

Function 1) "For"

Average execution time: 417254ms

Rank: 1 (1 is best)

1.002 times (0.263%) quicker than slowest function

** QUICKEST **

**********************************************************************

Function 2) "While"

Average execution time: 418353ms

Rank: 2 (1 is best)

** SLOWEST **

1.002 times (0.262%) slower than quickest function

**********************************************************************/

Trevor

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
Guide ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Hi again Trevor,

Sorry to be insistent but my point was, while is not significantly faster than for. That's it. Not a very important fact in itself, we all agree and that's why I was talking about splitting hairs, but it would be technically wrong to claim that ExtendScript's implementation of while may intrinsically provide opportunities for optimization. There are reasons to use while and reasons to use for, and all are syntactic. I don't know exactly what you mean by “I was comparing 2 functions that people use,” since no serious JS developer would ever use a syntax like for(  ; n > 0 ; n-- ); as soon as for(  ; n-- ; ); is available to her/him. Of course I assume s/he knows what this exactly means, as well as you assume “people” know what exactly means the syntax while( n-- ). So, while still admitting my point is not crucial, I took time to argue and illustrate it, and I maintain your benchmark might be misunderstood… whatever the coding style “people use” 😉

Thanks for reading.

Best,

Marc

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
Enthusiast ,
Dec 13, 2017 Dec 13, 2017

Copy link to clipboard

Copied

Hi @Trevor,

Out of curiosity, I wanted to test your code but I have a runtime error. Can you help me ?

//----

Par curiosité, je voulais teste votre code mais j'ai une erreur à l'exécution. Pouvez-vous m'aider ?

Capture d’écran 2017-12-13 à 10.53.17.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
Guru ,
Dec 13, 2017 Dec 13, 2017

Copy link to clipboard

Copied

Hi Liphou,

1) I can't see from the screenshot what the problem is. If you want you can post the whole code here.

2) You should note that you are trying the comparison out on DOM calls. The DOM call take so much longer to execute than the time difference your notice from the 2 methods. Think how long the creation of 10,000 (1e5) rectangles is going to take and thing how long an empty loop of 10,000 will take. Based on your figures the DOM is taking 835,000 ms the empty loop takes about 5ms. So there's not much point in that test. Let's say the one empty loop takes 80ms and the other takes 1ms you are not going to see the difference.

The function is useful for comparing for example one function that has enable redraw false with another  that has enable redraw true or one that uses one doScript method against another that uses some other method. Of even the simple loop methods but not used with ultra slow DOM methods.

3) Completely of topic. It looks to me that you have a French windows set up.

Please can you run this snippet from CMD promt

powershell "get-childitem -force 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' -erroraction silentlycontinue | select-object *"

I'm looking to see how the date formats come out on a non-English Windows system.

Do they come out in English or French? Can you post a screenshot of the results.

I'll go to my Windows system soon and show you what it looks like by me.

Same request applies to anyone who has any non-English locale Windows.

Thanks

Trevor

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
Guru ,
Dec 13, 2017 Dec 13, 2017

Copy link to clipboard

Copied

2017-12-13_15-57-27.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
Guide ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Great snippet Trevor, thanks a lot for sharing.

Now let me split hairs over your while vs. for benchmark. The test seems to establish that the while syntax is about 2X faster than the for syntax. And indeed I got similar results (from CS4 to CC) using your sample code. However, IMHO it doesn't actually compare equivalent statements.

The strict equivalent of your While function

function While(n){ 

    while (n--); 

should syntactically be

function For(n){ 

    for ( ; n-- ; ); 

which as you can notice behaves the same. So I think there is a bias when you ‘translate’ it into

function For(n){ 

    for (; n>=0; n--); 

}

since you artificially dissociate the post-decrement operation (n--) from the boolean test, this dissociation being required neither in while nor for. Having two atomic expressions (n>=0 and n--) in your For function makes it, indeed, noticeably slower. But my version seems to me a more accurate translation and you will then check that it runs in almost the same time.

There remains, I admit, a tiny gap of a fraction of a millisecond in the 1e6 test, which means that while is about 1.03 or 1.04 faster than for in that configuration. The reason, I think, is that for is formally more complete than while and has three placeholders in its inner structure, which could be considered having more arguments and then requiring an additional, incompressible, formal stage. But, as soon as you have an initialization step and/or some additional process between two iterations, I really don't think it has been proved here that while beats for at a perceptive level. To me, the while construct is only a formal shortcut of the for construct when the 1st and 3rd placeholders are not used. Otherwise, for remains the most generic form of a loop in the sense that any while syntax can always be rewritten using for.

</split-hairs-mode>

Best,

Marc

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
Guru ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

Hi Marc,

Thank you for your comment. It's very interesting!

Regards,
Kasyan

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
Enthusiast ,
Dec 13, 2017 Dec 13, 2017

Copy link to clipboard

Copied

LATEST

Merci

I'm on Mac, I do not know the command in Termibal.

For the error, it signals me that 'r' is 'undefined'.

I am especially curious to be able to use the 'Compare Functions.jsx' script

//---------------------------

Je suis sur Mac, je ne connais pas la commande en Termibal.

Pour l'erreur, il me signal que 'r' est 'undefined'.

Je suis surtout curieux de pouvoir réutilisé le script 'Compare Functions.jsx'

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