WP Get position -> a killer on time execution

Hi,

Following the presentation of @Roland_Lannuzel, I set up the creation of a table of contents.
Having documents of more than 500 pages, analyzing the style of each line killed me: more than 15 minutes on an i7 2.2Ghz/32Go!

I changed a little bit the code by putting a bookmark each time I assigned a style. As a result, I just have 525 bookmarks to analyze against 41050 lines.

But, the next code line kills a lot of nerves since it takes a significant amount of time.

$o:= WP Get position ($paragraph;wk 4D Write Pro layout)

Is there anything that can be done to improve the speed or is it just this command that’s screwed up?

Patrick

Hi Patrick

Only sometimes (in some special use cases) it is faster to create first a $tmpDoc:=OB Copy(wpDoc) to get a enhanced from view copy,
and than do a great bundle of wpCmds only with this copy.
When it is needed, you can assign back the copy to the original wpDoc variable (which is displayed).

wpAnalyze(gWpDocInView)

// PM: “wpAnalyze”
$wpDoc:=OB Copy($1)
// …now inside this method work only with the copy in $wpDoc

I did not know this helps in your szenario?

Greetings Lutz

Hi Lutz,

First at all, thanks for your reply.

The portion of code is this one:

		$paragraph:=WP Bookmark range($sourceDocument;$w_bookmarks{$a})
		WP GET ATTRIBUTES($paragraph;wk style sheet;$styleSheet)
		$index:=$_styleNames.indexOf($styleSheet)
		
		If ($index>=0)
			$range:=WP Text range($summary;wk end text;wk end text)
			  // WP Get position es very Slow
			$o:=WP Get position($paragraph;wk 4D Write Pro layout)
			$label:=WP Get text($paragraph;wk expressions as value)
...

So, if I follow your advice, I should create a copy of $sourceDocument to search each bookmark.
I have this part of code in a loop (1 -> 550) and a source document of 670 pages.
I’m not sure that I will gain on time execution, but I will try, who knows? :roll_eyes:

Patrick