[QGIS-Developer] DWG files preview in QGIS

Charles Dixon-Paver charles at kartoza.com
Mon Jul 26 00:28:26 PDT 2021


There should be no need to buy additional software to bulk convert DWG
files to PNG format. If you have access to autocad you should be able to
bulk export your layouts. I could likely share an auto lisp routine but
without an autocad license and sample data I wouldn't be able to test it.

As I said, I personally used the Autodesk True View application (which is
free) to bulk export to pdf. You can also use a program like imagemajick to
bulk convert PDF to PNG, so although it's a more complex workflow than
exporting directly to PNG it is certainly possible without purchasing
separate software.

If you struggle with automating these steps let me know. I expect it to be
quite a common procedure for users who work with CAD data and it may be
worth a quick YouTube tutorial or similar. Even if it does take some extra
time to develop, if you pay an open source consultant to develop a solution
rather than paying for conversion software, everyone can benefit.

On Mon, 26 Jul 2021, 01:31 todor lambev, <totolamb at abv.bg> wrote:

> Dear Charles,
>
> Thank you very much for your reply. I learned something new and usefull.
> I have to buy a DWG -> PNG convertor now but I think that will be fair if
> I need to preview all the files.
>
>
> 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>*
>
>
>
>
>
> >-------- Оригинално писмо --------
> >От: Charles Dixon-Paver charles at kartoza.com
> >Относно: Re: [QGIS-Developer] DWG files preview in QGIS
> >До: todor lambev <totolamb at abv.bg>
> >Изпратено на: 23.07.2021 00:20
>
> No problem Todor, although it may be worth bearing in mind that these
> sorts of usability questions are typically better suited to the QGIS User
> mailing list and may get a better response from there.
>
> In terms of your query, I would say it is certainly possible to achieve in
> QGIS, but there are a few limits to what is possible and what is practical.
>
> Like I mentioned before, I believe what you are after is better served
> using raster files displaying your CAD information, so converting your DWGs
> to a raster format beforehand would be beneficial.
>
> Previewing the DWG file itself in QGIS probably isn't easily feasible, the
> easiest approach likely being some sort of HTML viewer integration. You can
> also convert the DWG to GPKG using QGIS tools to make it easier to work
> with, but again I feel this is not what you seem to need for your use case.
>
> I would expect some data from a DWG to be unsupported by QGIS when
> converting it, as well as having data which is outside of the drawing
> paperspace not be included in the preview image (amongst other issues
> depending on the structure/ design of the DWGs). Jorge outlined the code
> needed to load the DWG with an external program using an action as
> well, but that would specifically require loading an instance of a third
> party program. My suggestion would be to build the map project as outlined
> in the presentation with raster images, and attach an action to open the
> complete drawing for further introspection.
>
> I have created a small demo project which demonstrates how to achieve the
> outcomes I described. It includes various actions for launching file
> previews and contains a number of different layer styles and approaches for
> rendering the data in various manners as you would like. You can also
> configure the feature identification tool to automatically load the feature
> form and use the QGIS drag and Drop form designer to configure an image
> preview. The project also demonstrates using the QGIS atlas feature with
> print layouts to achieve the specific outcome highlighted in the
> presentation document.
>
> [image: output_3.png]
>
> You can download the files and project, DWG_integration_example.zip, from
> the following temporary file share:
>
> https://filebin.net/qxrw2xc94syeioo4
>
> (The Chrome browser security may complain it is unsafe, but you should be
> able to download it with firefox or edge etc)
>
> SHA256: 7E9E5A398BFAE4115EEE6D5C1B2073ED7314C6B7186AB61818D613B389991FD7
>
> I used some sample DWGs from the internet and bulk exported them to PDF
> using TrueView before converting to PNG, so this is definitely something
> you can make at least semi-automatic. If you have access to autocad, I
> imagine there are a number of options available for bulk exporting/
> plotting/ publishing, if not from within the software itself, certainly
> using AutoLisp.
>
> You could of course try to build similar DWG viewing functionality and
> leverage it in QGIS similar to what I have demonstrated with raster data,
> but I doubt it would be practical.
>
> I hope that this solves your issues and provides you with a strong
> starting point for configuring your project.
>
> On Thu, 22 Jul 2021 at 09:34, todor lambev < totolamb at abv.bg> wrote:
>
> Dear Charles,
>
> Thank you very much for your reply. In fact this is my first time that I
> use QGIS-developer forum and I am pleasantly surprised that someone replied
> to my questions.
>
> No on the topic.  In the attached presentation you can find an explanation
> what I would like to receive as a final "product.  Do you think that it is
> possible or at least someting similar? The idea of the hole excersice is to
> be able to make a quick visual check of all the profiles which I have in
> separate DWGs.
>
>
> 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>*
>
>
>
>
>
> >-------- Оригинално писмо --------
> >От: Charles Dixon-Paver charles at kartoza.com
> >Относно: Re: [QGIS-Developer] DWG files preview in QGIS
> >До: todor lambev < totolamb at abv.bg>
> >Изпратено на: 20.07.2021 18:38
>
> 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/20210726/96a214be/attachment.html>


More information about the QGIS-Developer mailing list