[QGIS-Developer] DWG files preview in QGIS

Charles Dixon-Paver charles at kartoza.com
Tue Jul 20 08:38:20 PDT 2021


It's not totally clear to me what the objective is for your DWGs.

By "preview", do you mean wish to just view an overview image of the DWG
contents? If that is the case, I would recommend using a separate command
line/ batch process to produce raster format previews as DWGs. You can then
create a new field for the accompanying raster file using the field
calculator and QGIS expressions.

With the rasters you can use the preview option in the feature form, or
even use a "Raster Image Marker" based symbol at certain scales to
represent the DXF previews.

Another option for previews is to use the "Show map tips" option from the
QGIS toolbars. In the "Display" section of the layer properties you will
find that tooltips can use HTML code which will render a "web preview" of
the feature when you hover the cursor on it. for example, the
following should allow image previews:

<img src='file:///[%  @project_folder || '/' || "image" %]' height=400
width=400 />

In theory, you could likely combine this with a DWG rendering library such
as https://sharecad.org/it/DWGOnlinePlugin but I expect it will be
difficult to use and not very efficient, hence why I would suggest
converting the data to raster beforehand. One other thing you could do as
well is to use the "web view" of the QGIS form to render an html template
with an integrated viewer, but again, this is likely difficult and not
necessary.

I am not aware of any "preview" plugin for rendering DWG data within QGIS.

If your aim is to "load" the DWG into your project from a command available
within the point feature attributes, this is supported by using GitHub
actions and some custom code, although the process may be quite cumbersome.
Actions functionality was covered on the last QGIS Open Day[1] and I
recommend watching the demonstration if that is your use case.
Alternatively, there is also some written material on this topic [2] f you
would prefer to start there

[1] https://github.com/qgis/QGIS/wiki/QOD-June-2021#qgis-actions-deep-dive
[2]
https://courses.spatialthoughts.com/pyqgis-in-a-day.html#creating-custom-python-actions


On Tue, 20 Jul 2021 at 16:40, todor lambev <totolamb at abv.bg> wrote:

> Dear QGIS developers,
>
> I have a strange need. Could you help me?
> I have 30 000 DWG files that are not georeferenced, each file has unique
> and a specific name. I have a point shapefile which in its attribute table
> contains a column with the names of the *dwg files.
>
> My question is: How I can load to preview the DWG files in QGIS next to
> the points or to preview the DWG by clicking on the point (similar to the
> photo preview widget)?
>
> I hope that you won't skip my question and will help me to find a solution
> basically because otherwise, I have to do it manually...
>
> Best regards
>
> Todor Lambev, PhD Student- - - - -*Institute of Oceanology
> **Department of coastal zones dynamics
> mob: +359 886 75 72 85;
> Varna, Bulgaria
> URL: http://www.io-bas.bg <http://www.io-bas.bg>*
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210720/ef3ca999/attachment.html>


More information about the QGIS-Developer mailing list