Page 1 of 1

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

Posted: Fri May 10, 2019 6:32 pm
by garciadelcastillo
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!

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

Posted: Fri May 10, 2019 11:49 pm
by andrew
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.

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

Posted: Mon May 13, 2019 2:33 pm
by garciadelcastillo
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!

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

Posted: Tue May 14, 2019 2:14 pm
by andrew
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

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

Posted: Tue May 14, 2019 3:49 pm
by garciadelcastillo
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,

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

Posted: Tue May 14, 2019 3:55 pm
by andrew
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