QCAD.org Forum

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Before spending hours on what is bothering me now, I will just be bold and ask for a hint

If in QCad2 I wanted to draw on a template, a single line of code was sufficient app.fileOpen("Vorlage.dxf");

I looked at the files in the script directory, there is of course a "load template" script. I wonder, how to wrap this into a function, that I can call in my own script as convenient as that one. Please share your ideas!

Since a lot of the GUI part is implemented in ECMAScript (all MDI related things, how a document window looks like, scroll bars, rulers, etc.), you need to call that same script in order to get the same effect as when the user opens a file through the menu or tool button.

The script to open a file is located in scripts/File/Open/Open.js and can be used as follows in QCAD TP1:

You might want to create a wrapper function for this, so it can be easily ported if the script API changes for the final QCAD version. Class 'Open' will be called 'OpenFile' in the next QCAD release since we had some problems with class names like 'Open' or 'New'. So the code above will change for QCAD TP2 to:

The debugger calls the toString() function to display information about an object. toString() is implemented for all C++ class wrappers (classes starting with an R) to return the class name. Of course, you can also overwrite toString for your ECMAScript class, for example:

Sorry for waking up this old thread. Yet, the method in here, to programmatically open a template and use it as a base for further scripted drawing, got broken between release candidate 5 and qcad 3 final.