Export determined bounding box to image

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
jocieldo
Registered Member
Posts: 1
Joined: Sun Mar 03, 2024 5:36 pm

Export determined bounding box to image

Post by jocieldo » Sun Mar 03, 2024 5:41 pm

Hi all, I'm taking a look on the scripting from qcad and I was wondering if there is any way I can export a determined bounding box to an image.
For instance, I have those coordinates:
min: 120,120
max: 240,240

And I want to export the view from this box to an image with 500px, 500px.

There's any scripting or command line I can do it?

333onlyhalfevil
Junior Member
Posts: 24
Joined: Fri Apr 28, 2023 12:39 pm

Re: Export determined bounding box to image

Post by 333onlyhalfevil » Sun Mar 03, 2024 8:20 pm

Under file there's the bitmap export where you can select what image filetype you want and also the image size (i.e., 500x500px). I could imagine to do this you would create a view that looks at your 120x120 coordinates, then view your view, then do the bitmap export. Pretty sure it's doable with the scripting interface.

CVH
Premier Member
Posts: 3480
Joined: Wed Sep 27, 2017 4:17 pm

Re: Export determined bounding box to image

Post by CVH » Mon Mar 04, 2024 6:39 am

@jocieldo
Hi, and welcome to the QCAD forum.

There is a OS Command Line method but I don't think that this will crop the output to a given area, window or box: dwg2bmp
https://www.ribbonsoft.com/en/products/ ... line-tools

The GUI method BitmapExport.js is open source, see: https://github.com/qcad/qcad/blob/maste ... pExport.js

The beginEvent eventually calls this.exportBitmap(this.getDocumentInterface(), bmpFileName, properties); at line 277.
  • this.getDocumentInterface() is a reference to a document interface, in this case the current.
    bmpFileName is a path+filename for the generated output.
    properties is a collection of properties or settings to work with.
See the getProperties function on line 155 on how to define the properties argument.

Cropping is another problem, QCAD exports all visible and/or the region of a box around all selected.
One can indeed create a Viewport on a Layout block and export that.

A simple test exported the content cropped to the Viewport as expected but it included the border of the Viewport.
That should be tweaked somehow when exporting a border is not intended but then the export area is less defined.

Another method is creating a temporary copy of the intended art in an off-screen document clipped to a rectangle (CLR).
You can then export only the clipped area with the associated document interface, deleting the off-screen document afterwards.

But there may be a different route ...
The export itself is handled in BitmapExportWorker.js:
https://github.com/qcad/qcad/blob/maste ... tWorker.js

You might simply exploit the window property but again it is unsure if that crops.
Probably it only zooms in/out to that RBox like dwg2bmp does.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”