Word/PDF Sketchup ruby API


Hello everyone,

i’m exploring the possibilities given by Sketchup
Ruby API,and i found the “attrreporter.rb” file but it only generates csv and html files and only from groups or components.
I have a question is it possible to generate a Word or PDF documents that contains information extracted from Sketchup models ?
and those the model has to contain groups and components to do so ?

thank you so much.


The SketchUp API doesn’t come with any methods by itself to generate these specific files. But you can certainly traverse the model, collect the info you need and generate these files yourself - using libraries that allows you to do so.


in the attrreport.rb file it generates csv and html files but they say :
# Currently we support CSV and HTML.
# More format can be easily defined here by defining the @filetype expected and the
# various variables @doc_start, @doc_end, @row_start, @row_end, @cell_start, @cell_mid, and @cell_end
how can i know the values to give t those variables ?
i kept searching but didn’t found anything about it ?
can u give an example of libraries that allows me to generate Word/PDF files ?


I’m afraid I’m not familiar with that code. Where did you find it? Got a link?

I’m afraid that I’ve not had to generate PDF or Word files - so I don’t know of any libraries of hand. I’d search Google for such libraries.


that’s the link where i found that code:

i’ve searched a lot about it but can’t find something that helps


did you try changing the extension to .htm without the final l

Word can open .htm files and these can be saved as .doc…

there seems to be plenty of links for saving html to Word doc…



i didn’t try that by i tried to change the .csv to .pfd in code i found in the link above, it generates a pdf file but when i want to open it it says that the doc wasn’t decoded correctly.
i guess it has something to do with the # various variables @doc_start, @doc_end, @row_start, @row_end, @cell_start, @cell_mid, and @cell_end
because in that code they say if u want other file forma change those variables.


they are two completely different formats, but htm and html are closely related…



yeah it workd with the htm method but it generates a htm and i need to open it with Microsoft Word, isn’t there a possibility to generate a Word file directly ?
i found a library named Prawn http://prawnpdf.org/api-docs/2.0/
do u have an idea about it ? how can i integrate those kind of libraries to sketchup ruby API ?


The prawn site says it is pure Ruby (vs compiled code) and distributed as a Gem, so there is a fair chance it will work within SketchUp. Try the following in the Ruby Console:


and see what happens. Note: it writes PDF, not MS Word. The Word file format is proprietary, there are no free published specs and an author probably has to pay a fee to MS to get access.


thank you so much i’ll try it now and tell you the result


aaawsooooooome it worked thaaaank you soo much i didn’t know the Gem.install(“prawn”) commande :smiley:


The code is really speaking of plain text formats (I think.)

MS Word’s .DOC format is a binary proprietary format. (It has been replaced as the default by DOCX format. See info below.)

However there are newer formats that Office applications (like MS Office, LibreOffice and OpenOffice.org) use that are XML based plain text.

ODT : Open Document Text

DOCX : Office Open XML

Ruby has XML libraries in it’s standard library, and other extra gems.

Wikipedia on XML format:


thatn you soo much for your aswer this is the best forum eveeer