Porting old BrickStore and BrickStock Print Scripts
The old BrickStore scripts were based on a JavaScript 4 interpreter, but this JS version was abandoned by the industry (see Wikipedia).
The new scripts are running in a state-of-art JavaScript 7 environment as provided by web browsers (see QML JavaScript environment).
Sadly JS4 did a few things differently than today's JS7, so you have to adapt your scripts: some of these required changes are just simple search-and-replace jobs, while others require you to rewrite your code a bit.
The simple changes
- Replace
var
withlet
for variable initialization - Replace
CReportPage
withPrintPage
- Replace
Utility.localDateString(d)
withQt.formatDate(d)
Intermediate changes
- Replace the
load()
function with a new file header. Just copy the one from classic-print-script.bs.qm (from the start of the file up tofunction printJob
) and change thename
,author
andversion
fields in theScript
object. You can also set the text of the menu entry via thetext
property of PrintingScriptAction. - Don't forget to add a
} add the end of the file afterwards to balance the scope: the old scripts only had global JS functions, but all functions are members of the Script object nowadays.
- Rename the existing
function printDoc()
function tofunction printJob(job, doc, lots)
. See below on how to use thejob
,doc
andlots
parameters. - Replace
Document
withdoc
.Document
was a global object, butdoc
is now just a local function parameter toprintJob()
, so make sure to forwarddoc
to sub-routines as needed. - Replace
Job
withjob
.Job
was a global object, butjob
is now just a local function parameter toprintJob()
, so make sure to forwardjob
to sub-routines as needed. - A lot (or row in the document) was wrongly called *item* in the old API, but this was just too confusing with full catalog access for the JS API, so it had to be renamed to *lot*. So, in order to iterate over all lots in a document, you now have to access
doc.lots
instead ofDocument.items
. - If you want to support printing just the selected lots, do not iterate over
doc.lots
, but use thelots
parameter given to theprintJob
function. - Replace
Money.toLocalString(m, showCurrencyCode)
withBrickStore.toCurrencyString(m, currencyCode)
. The document's currencyCode is not set implicitly anymore, but needs to be retrieved viadoc.currencyCode
in the mainprintJob()
function. Keep in mind to forward eitherjob
or the currency code to sub-routines if needed there. - All enumeration values in the
BrickLink
module are scoped now to prevent problems due to ambiguous values:BrickLink.Used
becomesBrickLink.Condition.Used
,BrickLink.Extra
becomes BrickLink.Status.Extra, etc. Please have a look at the documentation of the properties based on enumeration values for the correct scope name.
Complex changes
Font and Color objects changed a lot! The new JS engine is using the built-in Qt types for fonts and colors and these can be a bit weird, when compared to the old objects:
- Both cannot be created via the
new
operator anymore- For fonts, you have to use the factory function
Qt.font()
: see the Qt documentation for Qt.font and the QML font documentation for the available font properties. - For colors, see the QML color documentation.
- For fonts, you have to use the factory function
- Accessing the
page.font
andpage.color
properties now returns a reference to the current value, not a copy. This means that you cannot save the current value at the start of the function and reset the property to that value again when the function ends, because the "saved" value changes everytime you change the actual property. If you relied on this behavior (the default print script did), you have to change your approach here to always set the colors and fonts before drawing in a sub-routine.
Have a look at the classic-print-script.bs.qml to get an idea how to work with fonts and colors in the new JS engine.
© 2004-2025 Robert Griebl. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. All trademarks are property of their respective owners.