[Solved] How to get the list of layers in a drawing from the command line

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules
Always indicate Operating system, QCAD version
Attach Drawing files, Screenshots
Post one question per topic.
Post Reply
garciadelcastillo
Junior Member
Posts: 20
Joined: Fri May 10, 2019 6:26 pm

[Solved] How to get the list of layers in a drawing from the command line

Post by garciadelcastillo » Fri May 10, 2019 6:32 pm

Hi!

First of all, I just started using QCAD Pro command line tools, and I am very impressed by how efficient and featureful it is. Big congrats!

Writing a routine to export individual layers from a DWG file to raster. The "-layer=LAYER_NAMES" option from "dwg2bmp" seems to be the way to go, but I need to be able to fetch the layer list first from an external batch process. Is there any way to spit these out to a text file somehow with QCAD's command line tools?

Thanks!
Last edited by garciadelcastillo on Thu May 23, 2019 10:38 pm, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 6089
Joined: Fri Mar 30, 2007 6:07 am

Re: How to get the list of layers in a drawing from the command line

Post by andrew » Fri May 10, 2019 11:49 pm

You can use the command line tool "dwginfo". There is currently no batch or bash script for it, but you can invoke it as follows:

Code: Select all

qcad -no-gui -allow-multiple-instances -autostart "scripts/Pro/Tools/DwgInfo/DwgInfo.js" -l
Where -l lists all layers.

garciadelcastillo
Junior Member
Posts: 20
Joined: Fri May 10, 2019 6:26 pm

Re: How to get the list of layers in a drawing from the command line

Post by garciadelcastillo » Mon May 13, 2019 2:33 pm

Wonderful, this is very helpful! A couple questions still...

First, if I run the call from the terminal, I get nothing on the stdout (using window's powershell):

Code: Select all

qcad -no-gui -allow-multiple-instances -autostart "scripts/Pro/Tools/DwgInfo/DwgInfo.js" -l .\atestfile.dwg
However, if instead I create a batch file encapsulating the same logic:

Code: Select all

 
 @echo off
qcad.exe -no-gui -allow-multiple-instances -autostart scripts\Pro\Tools\DwgInfo\DwgInfo.js %0 %* 1>%temp%\dwginfo.log 2>&1
type %temp%\dwginfo.log
del %temp%\dwginfo.log
 
And call it with:

Code: Select all

.\dwginfo.bat -l .\atestfile.dwg
I get the layers output to the terminal (as well as a bunch of other debug dumps. Why is this difference?

Second question: I need to spit these to a text file or similar to use them somewhere else. I tried using -o options, no luck:

Code: Select all

.\dwginfo.bat -l -output="layers.txt" .\atestfile.dwg
Where can I find the documentation for "DwgInfo.js"? And where can I check the documentation/source for other similar scripts, such as "dwg2bmp", "merge", etc.?

Thanks a lot!

User avatar
andrew
Site Admin
Posts: 6089
Joined: Fri Mar 30, 2007 6:07 am

Re: How to get the list of layers in a drawing from the command line

Post by andrew » Tue May 14, 2019 2:14 pm

garciadelcastillo wrote:
Mon May 13, 2019 2:33 pm
Why is this difference?
A Windows GUI app like QCAD cannot write to stdout (a Windows limitation). The batch file streams to a file, then displays that file.
garciadelcastillo wrote:
Mon May 13, 2019 2:33 pm
I need to spit these to a text file or similar to use them somewhere else.
Simply stream the output directly to the file you want instead of %temp%\dwginfo.log:

Code: Select all

qcad.exe -no-gui -allow-multiple-instances -autostart scripts\Pro\Tools\DwgInfo\DwgInfo.js %0 %* 1>myoutputfile.txt
garciadelcastillo wrote:
Mon May 13, 2019 2:33 pm
Where can I find the documentation for "DwgInfo.js"?
dwginfo is not an official QCAD tool at this point. -h for usage works as usual.
garciadelcastillo wrote:
Mon May 13, 2019 2:33 pm
And where can I check the documentation/source for other similar scripts, such as "dwg2bmp", "merge", etc.?
https://qcad.org/en/products/qcad-command-line-tools

garciadelcastillo
Junior Member
Posts: 20
Joined: Fri May 10, 2019 6:26 pm

Re: How to get the list of layers in a drawing from the command line

Post by garciadelcastillo » Tue May 14, 2019 3:49 pm

Hi Andrew,

Thanks a lot, that was very helpful. I guess my question was more like where can I see the source for `dwginfo` in order to learn from it, but I guess the answer is that I cannot, since it is part of the pro bundle...?

Cheers,

User avatar
andrew
Site Admin
Posts: 6089
Joined: Fri Mar 30, 2007 6:07 am

Re: How to get the list of layers in a drawing from the command line

Post by andrew » Tue May 14, 2019 3:55 pm

garciadelcastillo wrote:
Tue May 14, 2019 3:49 pm
I guess my question was more like where can I see the source for `dwginfo` in order to learn from it, but I guess the answer is that I cannot, since it is part of the pro bundle...?
That's correct. However, there are plenty of other (script) sources available at:
https://github.com/qcad/qcad/tree/master/scripts

Post Reply

Return to “QCAD 'How Do I' Questions”