1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

PDF Export via command?

Posted by Klaus on Apr 23, 2007

Hi,

I like to know if there is a command for exporting a PDF, so that I can use it lets say in a "for x in range..." loop to export several PDFs.



Posted by Tom De Smedt on Apr 23, 2007

Hi Klaus,

In the export menu there's a "Number of Pages" input box. Instead of putting your script inside a loop, you can define the number of PDF's it needs to generate in the input box (10, 100, 100000 :-)

If your script contains random() commands the output in each of the generated PDF's will be different.



Posted by Klaus on Apr 24, 2007

Hi Tom De Smedt,

yes, I know thanks! But what if I like to create a pic for example where I add a Circle, and then one more and so on, and like to export every singel picture but don't like to use "random". I also don't like to export a movie, I need PDFs.

Is there a command for exporting? Or will it be possible to include such a command in a future release?

Thanks
Klaus



Posted by Tom De Smedt on Apr 24, 2007

Then you need the page number of the current PDF being exported. You can use the global PAGENUM variable for that.

Here's an example that draws more and more circles on each page (try exporting 200-300 PDF's):

size(400,400)
from math import sin, cos, radians
 
for i in range(PAGENUM):
    
    x = 200 + sin(radians(i*2)) * 100
    y = 200 + cos(radians(i*2)) * i/2
    
    fill(i*0.002, 0, 0)
    oval(x, y, 20, 20)

If you need to do specific things on certain pages, use an if-statetement:

if PAGENUM == 100:
    # specific stuff for page 100 goes here
Hope that helps!



Posted by MarkM on Apr 24, 2007

Klaus, this has worked for me although it is not a documented feature and relies on looking under the hood--use it with caution since it does no error checking and will overwrite files that get in it's way.

data = graphicsView.pdfData
data.writeToFile_atomically_("FileName" + ".pdf" , False)
where FileName is the name of the file. The file ends up in the same place as the script you are running.



Posted by Klaus on Apr 25, 2007

Thank you very much, it seems that it is exactly that what I need!
Thank you for your help!

Klaus