There are two solutions for different ArchiCADs and with different effort. The older one is the correct one. The newer is easier to handle in GDL. This older script was rewritten for common use for a question in the German GDL user forum.
Additional there is a explanation for usage with the quantity_text_writer - makro, which is part of the main library.