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
varwithletfor variable initialization - Replace
CReportPagewithPrintPage - 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,authorandversionfields in theScriptobject. You can also set the text of the menu entry via thetextproperty 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,docandlotsparameters. - Replace
Documentwithdoc.Documentwas a global object, butdocis now just a local function parameter toprintJob(), so make sure to forwarddocto sub-routines as needed. - Replace
Jobwithjob.Jobwas a global object, butjobis now just a local function parameter toprintJob(), so make sure to forwardjobto 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.lotsinstead ofDocument.items. - If you want to support printing just the selected lots, do not iterate over
doc.lots, but use thelotsparameter given to theprintJobfunction. - Replace
Money.toLocalString(m, showCurrencyCode)withBrickStore.toCurrencyString(m, currencyCode). The document's currencyCode is not set implicitly anymore, but needs to be retrieved viadoc.currencyCodein the mainprintJob()function. Keep in mind to forward eitherjobor the currency code to sub-routines if needed there. - All enumeration values in the
BrickLinkmodule are scoped now to prevent problems due to ambiguous values:BrickLink.UsedbecomesBrickLink.Condition.Used,BrickLink.Extrabecomes 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
newoperator 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.fontandpage.colorproperties 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.