Page 1 of 1

[solved] dxf to pdf

Posted: Wed Sep 30, 2020 3:42 pm
by TSG
QCAD 3.25.2 is running on my iMac with macOS Catalina (10.15.7).

I would like to convert all dxf in a folder to pdf via batch or script. How do I have to proceed under macOS?
Please step-by-step, as my Unix and script knowledge is only rudimentary.

Re: dxf to pdf

Posted: Wed Sep 30, 2020 8:30 pm
by andrew
You can find the dwg2pdf command line tool under macOS under /Applications/QCAD-Pro.app/Contents/Resources.

To convert all files in a directory, you'd typically run a bash script that calls dwg2pdf for all files in the folder. Here's an example bash script that converts all DXF files in a directory to PDF size A4 (-p A4), auto fitting to page (-a), overwriting existing files (-f):

Code: Select all

for file in *.dxf
do
    /Applications/QCAD-Pro.app/Contents/Resources/dwg2pdf -a -p A4 -f "$file"
done

Re: dxf to pdf

Posted: Thu Oct 01, 2020 1:45 pm
by TSG
Many Thanks. The procedure works for me if I set the path manually in the terminal (cd) and then enter the program loop you mentioned ("for i = ...") in the terminal window. So far so good.

Then I tried to create an executable shell script ("#! / Bin / sh" and "chmod 755" filename ") according to instructions found on the web. Unfortunately, the path does not change, it is always the path under which the executable script was created used.

Although it is no longer a QCAD problem, I still hope to find help here.

Re: dxf to pdf

Posted: Thu Oct 01, 2020 3:44 pm
by andrew
You'd typically create the script in a folder that is in your PATH environment variable and execute it from wherever the folder with your files is.

For example:

- Save your bash script to /Users/yourname/bin/alldwg2pdf.sh

- Make it executable:

Code: Select all

chmod a+x /Users/yourname/bin/alldwg2pdf.sh
- Add this to your ~/.profile file:

Code: Select all

export PATH="/Users/yourname/bin:$PATH"
From now on, your script will be found from any directory in any new Terminal.

- Start a new Terminal

- cd to the path where your drawings are:

Code: Select all

cd /Users/yourname/mydrawings
- run the script:

Code: Select all

alldwg2pdf.sh

Re: dxf to pdf

Posted: Fri Oct 02, 2020 10:55 am
by TSG
Thanks again.
After some troubleshooting, I got the script to work.
I got stuck at your "./alldxf2pdf.sh".
It should read: "alldxf2pdf.sh".

Re: dxf to pdf

Posted: Fri Oct 02, 2020 10:57 am
by andrew
Yes, I've corrected it in case anyone else reads this, thanks.

Re: dxf to pdf

Posted: Fri Oct 02, 2020 11:32 am
by TSG
I've added a second for-do-loop in the script:

for file in *.dwg
do
/Applications/QCAD-Pro.app/Contents/Resources/dwg2pdf -a -p A4 -f "$file"
done

With this dwg are also converted to pdf.

Re: dxf to pdf

Posted: Fri Oct 02, 2020 2:16 pm
by andrew
For the record, this would also work:

Code: Select all

for file in *.dxf *.dwg
Note: Make sure that the file names don't contain spaces.