Author Topic: DWG Batch Conversion with Lisp ?  (Read 2614 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 720
DWG Batch Conversion with Lisp ?
« on: February 12, 2024, 08:01:20 AM »
Is it possible to use the DWGCONVERT command ... from Lisp?
(...passing the right arguments...)

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #1 on: February 12, 2024, 11:40:18 AM »
1 - I prepare a text file with "BCL" extension
which contains a list of names (including path) of DWG files

2 - command : DWGCONVERT

3 - APPEND BATCH CONTROL LIST and select the BCL file

4 - nothing happens !

???

MrSmith

  • Mosquito
  • Posts: 19
Re: DWG Batch Conversion with Lisp ?
« Reply #2 on: February 12, 2024, 12:10:30 PM »
Isn't DWGConvert already a batch command? Or are you trying to progmatically create the list of files and pass it to DWGCONVERT? You could achieve the same effect by simply saving the drawings via a script or ACCORECONSOLE.

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #3 on: February 12, 2024, 12:48:47 PM »
Isn't DWGConvert already a batch command?
DWGConvert is a command to be used from the command line

Or are you trying to progmatically create the list of files and pass it to DWGCONVERT?
I programmatically create the list of files and from the dialog choose the option to add a file BCL the contains a list of files.

You could achieve the same effect by simply saving the drawings via a script or ACCORECONSOLE.
I prefer to not use ACCORECONSOLE

MrSmith

  • Mosquito
  • Posts: 19
Re: DWG Batch Conversion with Lisp ?
« Reply #4 on: February 12, 2024, 12:53:46 PM »
I called it "batch command" as it allows the user to pick multiple files. It is basically a DCL wrapper for multi-convert. If you want to do it all via program without any user interaction, your best bet is to use .SCR or ACCORECONSOLE. I ended up implementing both for my save down needs since DWGCONVERT isn't automatable.

JohnK

  • Administrator
  • Seagull
  • Posts: 10555
Re: DWG Batch Conversion with Lisp ?
« Reply #5 on: February 12, 2024, 01:25:30 PM »
Sounds like you are using Lisp [AutoCAD] as an "interface", it might be easier on you/your users if you let Microsoft windows be the interface. -i.e. let people drag-and-drop or right click on files.

Requiring a user to open an instance of AutoCAD to preform an operation like: "convert files for export to client/archive" is sort of counter productive. It would be easier to drag an entire folders worth of files to a batch script which does the work for you.

This is how I did all my scripting; in the cases where I had hundreds of drawings on a project, I would do batches of files at a time -i.e. a list for drawings that needed "cleaning", "binding", etc..

But for the most part I would keep a list of files--I set up BEFORE the due date!!--that needed scripting, like drawings that needed transmitting to a client, so when that time came I would just run the script and be done.


My Lists used to look something like:

Code - Bash: [Select]
  1. @echo off
  2. set SCRIPT="%~dp0\cleanup_script.scr"
  3. set LOGFILE="<LOCATION>\<TO>\<PROJECT>\<FILES>\scripting.log"
  4.  
  5. set CWS="<LOCATION>\<TO>\<PROJECT>\<FILES>\00-CWS-201.dwg"
  6. set CWS=%CWS%;"<LOCATION>\<TO>\<PROJECT>\<FILES>\00-CWS-211.dwg"
  7. set CWS=%CWS%;"<LOCATION>\<TO>\<PROJECT>\<FILES>\00-CWS-212.dwg"
  8. set CWS=%CWS%;"<LOCATION>\<TO>\<PROJECT>\<FILES>\00-CWS-412.dwg"
  9. ...
  10.  
  11. set TWS="<A>\<DIFFERNT>\<LOCATION>\<TO>\<PROJECT>\<FILES>\00-TWS-201.dwg"
  12. set TWS=%TWS%;"<A>\<DIFFERNT>\<LOCATION>\<TO>\<PROJECT>\<FILES>\00-TWS-211.dwg"
  13. set TWS=%TWS%;"<A>\<DIFFERNT>\<LOCATION>\<TO>\<PROJECT>\<FILES>\00-TWS-212.dwg"
  14. set TWS=%TWS%;"<A>\<DIFFERNT>\<LOCATION>\<TO>\<PROJECT>\<FILES>\00-TWS-412.dwg"
  15. ...
  16.  
  17. echo "Cleaning CWS drawings..."
  18. call <LOCATION>\<TO>\<PROJECT>\<FILES>\Batch_accoreconsole_script.cmd %CWS% %SCRIPT% %LOGFILE%
  19.  
  20. echo "Cleaning TWS drawings..."
  21. call <LOCATION>\<TO>\<PROJECT>\<FILES>\Batch_accoreconsole_script.cmd %TWS% %SCRIPT% %LOGFILE%
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #6 on: February 12, 2024, 02:00:22 PM »
Yes
but I must first study and learn to use ACCORECONSOLE

I asked why DWGCONVERT doesn't do anything when I give it a text file in BCL format (as requested) that contains a list of files that I need to convert to the ACAD 2000 version

Can you show me an example of how to do it
(given a text file containing a list of DWG files to convert) with ACCORECONSOLE ?

I'm sure you are suggesting the right thing to me.

And it's also very interesting.

BATCH procedures and SCR files are a great possibility…

MrSmith

  • Mosquito
  • Posts: 19
Re: DWG Batch Conversion with Lisp ?
« Reply #7 on: February 12, 2024, 02:38:14 PM »
There are lots of script writers if you want to use that method, Lee Mac has a good one. This is what I use accoreconsole.  You'd have to generate & pass it the outList yourself. By default, I use the DefaultFormatForSave but you could change this for whatever.

Code - Auto/Visual Lisp: [Select]
  1. ;Different save formats based on the (getenv "DefaultFormatForSave")
  2. (defun DFFStranslate (var / saves)
  3.         ;Saves is (enviroment variable . save autocad version)
  4.         (setq saves '((8 . "R14")(12 . "2000")(24 . "2004")(36 . "2007")(48 . "2010")(60 . "2013")(64 . "2018")))
  5.         (if (setq saves (assoc (numInt var) saves))
  6.                 (cdr saves)
  7.                 nil
  8.         )
  9. )
  10. (defun cadConvert (outList / batFile scriptFile txt fl)
  11.         (setq batFile (strcat (getvar "TEMPPREFIX") "autoCADSaveDown.bat"))
  12.         (setq scriptFile (strcat (getvar "TEMPPREFIX") "quickSave.scr"))
  13.         (setq txt "")
  14.         (foreach it outList (setq txt (strcat "\"" it "\"," txt)))
  15.         (setq txt (vl-string-right-trim "," txt))
  16.         (setq txt (strcat "FOR %%G IN (" txt ") DO \"" (findfile "accoreconsole.exe") "\" /i %%G /s \"" scriptFile "\""))
  17.        
  18.         ;Write Bat File
  19.         (if (setq fl (open batFile "w"))
  20.                 (progn
  21.                         (write-line txt fl)
  22.                         (close fl)
  23.                 )
  24.         )
  25.         ;Write Script File
  26.         (if (setq fl (open scriptFile "w"))
  27.                 (progn
  28.                         (write-line (strcat "saveas " (DFFStranslate (getenv "DefaultFormatForSave")) "  y") fl) ;Double space for default file name, yes to save over it, should save as defaultsave format.
  29.                         (close fl)
  30.                 )
  31.         )
  32.         (startapp batFile)
  33. )
  34.  

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #8 on: February 12, 2024, 03:05:04 PM »
thank you MrSmith


I give to cadConvert my outList and
your code creates a batch file and an scr

I try to execute the BATCH file but nothing happens !


JohnK

  • Administrator
  • Seagull
  • Posts: 10555
Re: DWG Batch Conversion with Lisp ?
« Reply #9 on: February 12, 2024, 03:58:05 PM »
Do NOT use AutoCAD to launch accoreconsole. Using AutoCAD to manage a batch operation being run in another program makes ZERO sense.

A script to launch accoreconsole is here:
https://www.theswamp.org/index.php?topic=56891.msg605601#msg605601

-e.g.
I have to cook dinner but I do not know how to turn on the stove. I know how to use a bar of soap, so I will turn the shower on, get in, and throw the soap at the stove to turn it on.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #10 on: February 12, 2024, 04:07:28 PM »
I launched the batch file by simply right clicking on it and "run as administrator"

JohnK

  • Administrator
  • Seagull
  • Posts: 10555
Re: DWG Batch Conversion with Lisp ?
« Reply #11 on: February 12, 2024, 04:15:03 PM »
I launched the batch file by simply right clicking on it and "run as administrator"

If you are directing that statement at me, and you are referring to the BAT file I provided in that link: why didn't you just read the comment header where I give you a sample SCR file and drag some DWG files to the BAT file instead (because right clicking or double clicking it will do nothing because you didn't give it any files to do anything to)?

If you're not directing that statement at me...okay. what happened? And you typically run a BAT file by double-clicking (to use your current system's permissions). Running a bat file as admin can have serious consequences!

EDIT: repeated instructions found in my BATCH script for reference.
Instructions are in the BAT file I posted.
Code - Bash: [Select]
  1. :: USAGE
  2. :: Place this file (`BatchDrawings_accoreconsole.bat`) along with a script
  3. :: file (`BatchDrawings_accoreconsole.scr`) and drag-n-drop drawing files
  4. :: to this file (`BatchDrawings_accoreconsole.bat`).
  5. ::
  6. :: SAMPLE `BatchDrawings_accoreconsole.scr`:
  7. ::      ( (lambda ( / )
  8. ::          (mapcar
  9. ::            '(lambda ( x / )
  10. ::               (eval x)
  11. ::               (repeat 2 (command-s))
  12. ::               (princ))
  13. ::            '(
  14. ::              ;; --== ==--
  15. ::
  16. ::
  17. ::              ;; --== ==--
  18. ::              (command-s "_audit" "yes")
  19. ::              ;; audit the drawing
  20. ::              (repeat 5 (command-s "_purge" "a" "*" "n"))
  21. ::              ;; purge the drawing a ;few times
  22. ::              (command "_qsave")
  23. ::              ;; save
  24. ::              )
  25. ::            ) ; mapcar
  26. ::          (princ)
  27. ::          )
  28. ::       )
« Last Edit: February 12, 2024, 04:18:26 PM by JohnK »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #12 on: February 12, 2024, 11:28:58 PM »
@JonK
Quote
If you are directing that statement at me, ...

No.

when I say :
Quote
I launched the batch file by simply right clicking on it and "run as administrator

I was referring to the batch file created by cadConvert of MrSmith

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #13 on: February 13, 2024, 03:46:42 AM »
however I managed to add a text file containing a list of dwg files
to DWGCONVERTER
and then I managed to make it work

but I discovered that DWGCONVERTER
opens the files one by one

and then saves them in the required format
(and also does some other things)

While I was hoping that DWGMANAGER
would convert the files WITHOUT OPENING THEM!

Because to make a lisp file,
which opens the files one by one,
and then does everything I want
(zoom extents, purge ... and more)
and then saves them,
(even by changing the name by adding a suffix indicating the file version)
and preserving the original files,
it's easy.

I have already made this Lisp and have already used it many times.

What I HOPED is that there was a way to convert
(many) files without opening them.

Your BAT and SCR files,
which I haven't been able to test (and understand) yet
WHAT ARE THEY DOING ?

Do they open files one by one?

Because if that's the case, Lisp is enough.

In fact, you can do a lot more with Lisp!

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: DWG Batch Conversion with Lisp ?
« Reply #14 on: February 13, 2024, 07:59:36 AM »
Because if that's the case, Lisp is enough.
In fact, you can do a lot more with Lisp!
I tried again to do what I said with Lisp.
(I changed the defun s::startup in the acaddoc.lsp file)

and it seems to work
but it keeps crashing and giving me this error message:

INTERNAL ERROR: VL namespace mismatch

and I don't undestand the reason