Text per-page for LPub4

LPub4 offers a way to add text to a page, but no option for text to appear on every page. Whilst working on the BIs for the DuckToppl3r I had a need to put a disclaimer on each page. I am lead to believe that LPub3D can do this, but that is currently a Windows-only program. Since LDraw and LPub4 use text and I’m no stranger to Perl I figured a quick script would come to my rescue 🙂

LPub4 produces a new page on each STEP or ROTSTEP statement when not in a multi-step page, or on a “MULTI_STEP END” statement. So, all I needed to was to output the same “INSERT TEXT” statement above one of those three where relevant. The code used is as below if this proves to be useful to anyone:

#!/usr/bin/perl

use Getopt::Long;

$first = 'The MINDSTORMS® Community Partners present ROBOTREMIX3 [31313 + 42050] Community Challenge 2016. DUCK TOPPL3R Design & Building Instructions by Jerry Nicholls.';
$second = 'MINDSTORMS is a registered trademark of The LEGO Group. This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. August 2016';

GetOptions( 'first=s' => \$first, 'second=s' => \$second );

$multi = 0;
while(<>) {
 $multi = 1 if /MULTI_STEP\s+BEGIN/;

 if ((!$multi && /^0\s+(?:ROT)?STEP\s/) ||
     (/MULTI_STEP\s+END/)) {
     $multi = 0;
     print <<"TEXT";
0 !LPUB INSERT TEXT "$first" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.935
0 !LPUB INSERT TEXT "$second" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.95
TEXT
  }
 print;
}