[Ipe-discuss] Script to export all views from all pages of the Ipe drawing

Wojciech Zabolotny wzab01 at gmail.com
Sun May 13 18:11:41 CEST 2018


I often use Ipe to prepare animated (i.e., incrementally displayed on
subsequent slides)
drawings for my presentations in beamer.
The "iperender" tool allows exporting a single view.
However, I need an automatic tool, that is able to export all the
views in the separate files,
located in another directory. That allows me to use it in a Makefile
prepared for conversion
of the figures, as shown below:

In the Makefile:
[...]
.ipe.pdf: *.ipe
        ipescript expallviews $*.ipe ../figures_processed
[...]

If I have a figure "my_figure.ipe", that contains a few views in the
page 1, then I can include it in my presentation as shown below

In the presentation.tex file:

\usepackage{xmpmulti}
\graphicspath{{./figures_processed/}}
[...]

\multiinclude[format=pdf,start=1,graphics={width=0.9\linewidth}]{my_figure-p-1-v}

At the end of that message I attach the source code of my
"expallviews.lua" script.

The code is published as PUBLIC DOMAIN or under Creative Commons
CC0 license, whatever better suits your needs.
The code is published without any warranty. You use it on your own risk.

-- 
With best regards,
Wojtek

==== expallviews.lua =====
-- This is the script for exporting all views from all pages
-- in the IPE drawing.
-- I use it to export animated figures for beamer presentations.
-- Based on the information from
-- http://ipe.otfried.org/manual/luapage.html
-- This script was written by Wojciech M. Zabolotny
-- ( wzab01<at>gmail.com )
-- and is published as Public Domain or under
-- Creative Commons CC0 license, whatever better suits your needs.
-- 
-- Problems:
-- At the moment I can only epxort figures in PDF 1.4 format.
-- (iperender exports in PDF 1.5, but exportView in PDF 1.4)
if #argv ~= 2 then
  io.stderr:write("Usage: ipescript expallviews <inputfile> <outputdir>\n")
  return
end
fname=argv[1]
print(fname)
doc = ipe.Document(fname)
-- Prepare the base file name for the output files
-- Remove the directory part (if exists)
fbase=fname:reverse()
-- reverse the string. to make searching for last "/" and "." easier
i = fbase:find("/",1,"plain")
if (i) then
  fbase=fbase:sub(1,i-1)
end
i = fbase:find(".",1,"plain")
if (i) then
  fbase=fbase:sub(i+1)
end
fbase=fbase:reverse()
-- Add the output directory to the base filename
fbase=argv[2] .. "/" .. fbase
-- Now we can convert all the views from all pages
np=#doc
--print(fname .. " contains " .. np )
for p=1,np,1
do
  pg=doc[p]
  nv = pg:countViews()
  --print(fname .. " page " .. p .. " contains " ..  nv .. " views")
  for v=1,nv,1
  do
    fout=fbase .. "-p-" .. p .. "-v-" .. v .. ".pdf"
    --print("exporting to: " .. fout)
    doc:exportView(fout,nil,nil,p,v)
  end
end


More information about the Ipe-discuss mailing list