Hello, thanks for the hint. Could you please check my code? The function is able to detect number of pages (tested with a .pdf, which works; I believe it will work with other figure formats, too). When the file is not found, it doesn't break Ctx, which is good. The problem is that once a file is not found, later calls to the function fail (means they return 'false'), too. It seems like a figure being "hanging" somewhere or what; but I'm not able to find the bad place iin the code. Note that the directory structure is: t2.mkiv - file to be tested T/Kn.pdf - file to be inserted (2 pages) ---- t2.mkiv \startluacode nOfPages = function(fn) local n do local fig = figures.push{name = fn} local info = figures.identify() --inspect(info) if info.status.status ~= 0 then figures.check() -- This may check all figures; I'm interested in the last figure only - any call improvement? n = fig.used.pages end figures.pop() -- I thought no figure should stay "hanging" due to this line end if not n then return false end return n end \stopluacode \starttext AAA \startluacode context(nOfPages("Kn.pdf") or "???") -- [1] -- When you comment the line above, later Ctx detects correctly 2 pages of 'Kn.pdf'. \stopluacode \setupexternalfigures[directory=T] % Find the 'Kn.pdf' in 'T/Kn.pdf' \startluacode context(nOfPages("Kn.pdf") or "???") -- Now, Ctx should find 'T/Kn.pdf' anyway and thus detect 2 pages of 'Kn.pdf'. -- This doesn't occure when [1] is on \stopluacode \stoptext ---- Any idea? TIA. Best regards, Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038