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!
[Solved] How to get the list of layers in a drawing from the command line
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
-
- Active Member
- Posts: 28
- Joined: Fri May 10, 2019 6:26 pm
[Solved] How to get the list of layers in a drawing from the command line
Last edited by garciadelcastillo on Thu May 23, 2019 10:38 pm, edited 1 time in total.
Re: How to get the list of layers in a drawing from the command line
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:
Where -l lists all layers.
Code: Select all
qcad -no-gui -allow-multiple-instances -autostart "scripts/Pro/Tools/DwgInfo/DwgInfo.js" -l
-
- Active Member
- Posts: 28
- Joined: Fri May 10, 2019 6:26 pm
Re: How to get the list of layers in a drawing from the command line
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):
However, if instead I create a batch file encapsulating the same logic:
And call it with:
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:
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!
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
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
Code: Select all
.\dwginfo.bat -l .\atestfile.dwg
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
Thanks a lot!
Re: How to get the list of layers in a drawing from the command line
A Windows GUI app like QCAD cannot write to stdout (a Windows limitation). The batch file streams to a file, then displays that file.
Simply stream the output directly to the file you want instead of %temp%\dwginfo.log:garciadelcastillo wrote: ↑Mon May 13, 2019 2:33 pmI need to spit these to a text file or similar to use them somewhere else.
Code: Select all
qcad.exe -no-gui -allow-multiple-instances -autostart scripts\Pro\Tools\DwgInfo\DwgInfo.js %0 %* 1>myoutputfile.txt
dwginfo is not an official QCAD tool at this point. -h for usage works as usual.garciadelcastillo wrote: ↑Mon May 13, 2019 2:33 pmWhere can I find the documentation for "DwgInfo.js"?
https://qcad.org/en/products/qcad-command-line-toolsgarciadelcastillo wrote: ↑Mon May 13, 2019 2:33 pmAnd where can I check the documentation/source for other similar scripts, such as "dwg2bmp", "merge", etc.?
-
- Active Member
- Posts: 28
- Joined: Fri May 10, 2019 6:26 pm
Re: How to get the list of layers in a drawing from the command line
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,
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
That's correct. However, there are plenty of other (script) sources available at:garciadelcastillo wrote: ↑Tue May 14, 2019 3:49 pmI 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...?
https://github.com/qcad/qcad/tree/master/scripts