[solved] Get length of complete drawing through command line?

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
mrohnstock
Newbie Member
Posts: 4
Joined: Thu Aug 04, 2022 8:06 am

[solved] Get length of complete drawing through command line?

Post by mrohnstock » Thu Aug 04, 2022 8:50 am

Hi :),

Operation system: Archlinux
QCAD: 3.27.6.0 (3.27.6) Professional Trial

First of all: I'm new in using QCAD (and CAD in general - actually I did not made a single DXF file in my life so far...) and just took one day to take a look on it. So far I can tell that this piece of software is awesome and I'm planning to purchase the professional license! But first I have to find out if everything I need it for is feasible with it.

Some background information: I do receive complete worked out DXF files from an external source and send them to a producer who mills using an laser what is shown in the DXF file on carbon or metal. Then I get an invoice where the length that the laser had to travel and the approaches are invoiced.

The problem is, in order to be able to estimate whether what is invoiced actually corresponds to reality, I would need a way to extract the length (in mm) that the laser would travel from the DXF file.

I'm able to receive the correct length by using the GUI with the following steps:
1. open the DXF file
2. open the property editor by "View" → "Property Editor"
3. press CTRL + A to select everything available on the DXF file
4. change "Lineweight" from "0.09mm" to "Default" on "Property Editor"
5. get the "Total Length"

So far so good, but is this (somehow) possible to "automate" it with a command line, like it's done with dwginfo or bbox? If only a single (or 10) DXF file needs to get send to producer, I would fast be able to determine this value by my own, but if there are hundrets (like last month) this takes to much time.

I've attached one DXF file, where the "Total length" is 125mm, just in case someone needs to see, what I'm talking about.

I'm able to receive the approaches for the dxf files by using dwginfo, using the -e flag and the "real size" of the product by using bbox (so that alone is already a reason for the Professional license).

Thank you for any reply!

Best regards

- Mathias
Attachments
angel-1.dxf
(168.91 KiB) Downloaded 157 times
Last edited by mrohnstock on Thu Aug 04, 2022 12:19 pm, edited 1 time in total.

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

Re: Get length of complete drawing through command line?

Post by andrew » Thu Aug 04, 2022 9:20 am

There's no out of the box tool that gives you the total length but something close:

Code: Select all

dwg2csv -f -p "Length" angel-1.dxf
This produces a CSV file angel-1.csv with one single column "Length". For most objects (line types, layers, etc.) there is no length property, so these lines are left empty. For objects with a length, QCAD lists the length in the CSV output.

You can also output the object type in the first column like this:

Code: Select all

dwg2csv -f -p "Type" -p "Length" angel-1.dxf
You are then left with the task to sum up the length column which can be done in a simple command line chain:

Code: Select all

cat angel-1.csv | grep [0-9] | paste -sd+ - | bc
125.162287295490
Note that for splines, QCAD interpolates to compute the length. This might lead to different results depending on tolerance / interpolation / explode settings.

mrohnstock
Newbie Member
Posts: 4
Joined: Thu Aug 04, 2022 8:06 am

Re: Get length of complete drawing through command line?

Post by mrohnstock » Thu Aug 04, 2022 11:38 am

Awesome this is working great!
Instead of paste and bc, it would also work with awk (as paste has a different syntax on archlinux? at least this won't work directly...):

Code: Select all

grep angel-1.csv [0-9] | awk -F',' '{total +=$2} END {print total}'
Thank you very much!

Post Reply

Return to “QCAD 'How Do I' Questions”