How can I use command line to obtain the position information of each layer in DWG/DXF files?

If you are having problems with QCAD, post here. Please report bugs through our Bug Tracker instead.

Always attach your original DXF or DWG file and mentions your QCAD version and the platform you are on.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
hik-IT
Junior Member
Posts: 20
Joined: Wed Jun 11, 2025 2:33 am

How can I use command line to obtain the position information of each layer in DWG/DXF files?

Post by hik-IT » Wed Jun 11, 2025 2:49 am

"I want to use the following command line instruction:
./dwg2bmp -platform offscreen -zoom-all -width=6000 -height=6000 -window=2000000,-573237.78,3552109.93,643795.06 -flat -f B.dwg to convert B.dwg into a PNG image. However, the file canvas is very large with many blank areas. I want to crop out the blank spaces and only convert the effective layers.

Problem:How can I use command line to obtain the position information of each layer in DWG/DXF files?"

Environment
Linux Centos7
Qcad 3.23.3

QCAD version:3.32.3
Attachments
Image20250611094812717.png
Expected output
Image20250611094812717.png (79.81 KiB) Viewed 14957 times
B.dwg
CAD source file
(6.3 MiB) Downloaded 152 times

CVH
Premier Member
Posts: 4920
Joined: Wed Sep 27, 2017 4:17 pm

Re: How can I use command line to obtain the position information of each layer in DWG/DXF files?

Post by CVH » Wed Jun 11, 2025 4:16 am

hik-IT wrote:
Wed Jun 11, 2025 2:49 am
Problem:How can I use command line to obtain the position information of each layer in DWG/DXF files?"
Probably not in direct.
The misconception is that a layer has no position within the drawing.

In CAD layers are intended to control the attributes of the entities that live on it.
Block are collections of entities and intended to group things that belong together.
Entities in Block may live on different layers that define their: Color, Linetype, weight and so on.

There is the tool bbox but that is for all (visible) content.
dwg2bmp has a -layer= switch and -zoom-all switch to limit the export. (Read lower :!: )

You can always script your own custom designed Command Line tools.
hik-IT wrote:
Wed Jun 11, 2025 2:49 am
However, the file canvas is very large with many blank areas.
Not really blank because QCAD auto zooms by default to the visible content on opening in the GUI.
If I then select the 'Expected output' and invert the selection (TI) I get 418 entities outside the 'Expected output' area.

I can now copy the selection with reference (RC) and paste (PS) that in a new drawing (Not to current layer).
That would create the 16 layers of the copied entities besides layer '0' and 3 Block definitions.
Block entities are not shown in direct, these Blocks are re-created because I copied Block reference entities.
Entities of Block:
- '$equip$00002656' live on layer '0'
- 'sfg' live on layer 'A-text'
- with invalid name '*U161' live on layer 'A Ceiling size' (translated, Chinese is not allowed on the forum :wink: )
The 4 Block references of the latter refer to Block 'sfg' but display no visible content.

In short:
Using a comma separated list of layer names after the -layer= switch of dwg2bmp would at least be problematic.
I would not know how to enter Chinese text on the Command Line of my system to start with. :(
Filtering out some layers of the 16 may filter out content of the 'Expected output' area.

Also seen in other attached drawing are blocks with content (extremely) far away from the Block origin.
Among other things.
In all an ill-designed drawing to start with.

Regards,
CVH

Post Reply

Return to “QCAD Troubleshooting and Problems”