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

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: DWG Batch Conversion with Lisp ?
« Reply #15 on: February 13, 2024, 08:52:57 AM »
You do not "need" to launch the BAT file created from MrSmith's routine. It is called by startapp on line 31 of his routine however it is only doing a saveas not a purge, zoom, etc..

However, any drawings you have open in AutoCAD will not get "converted" by accoreconsole. ...Again, please do not use AutoCAD as a "scripting interface".
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #16 on: February 13, 2024, 12:28:22 PM »
If you do not need:  commands, ssget, ssname, ssdel... getvar, setvar... entmod, entupd... you can use ObjectDBX and open in Background...


ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: DWG Batch Conversion with Lisp ?
« Reply #17 on: February 13, 2024, 12:36:25 PM »
If you do not need:  commands, ssget, ssname, ssdel... getvar, setvar... entmod, entupd... you can use ObjectDBX and open in Background...

Unfortunately, ObjectDBX saves *.DWG files only in the latest file format - R2018... And OP wanted to save as R2000...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #18 on: February 13, 2024, 12:44:38 PM »
If you do not need:  commands, ssget, ssname, ssdel... getvar, setvar... entmod, entupd... you can use ObjectDBX and open in Background...

Unfortunately, ObjectDBX saves *.DWG files only in the latest file format - R2018... And OP wanted to save as R2000...
ObjectDBX saves in the current version format.

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: DWG Batch Conversion with Lisp ?
« Reply #19 on: February 13, 2024, 01:44:10 PM »
Wouldn't ObjectDBX be far more complicated then you need?!
I don't understand everyone's issue or aversion to using a simple batch script and a lisp file to do this. Two files.

1. Choose a folder (Mydocuments, c:\temp, etc.)
2. Save the below code as "BatchDrawings_Script.scr"
Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / )
  2.     (mapcar
  3.       '(lambda ( x / )
  4.          (eval x)
  5.          (repeat 2 (command))
  6.          (princ))
  7.       '(
  8.         (command "_audit" "yes")                      ;; audit the drawing
  9.         (repeat 5 (command "_purge" "a" "*" "n"))     ;; purge the drawing a ;few times
  10.         (command "_.saveas" "2000" "" "Y")              ;; save
  11.         )
  12.       ) ; mapcar
  13.     (princ)
  14.     )
  15.  )

3. Save the below code as "BatchDrawings_accoreconsole.bat"
        3a. Update the path to accoreconsole; I use AutoCAD 2022 you may use something different.
Code - Bash: [Select]
  1. @echo off
  2. if [%logfile%]==[] set logfile="%~dp0\scripting.log"
  3. echo ----------------------------------------x- %date% -x------ >> %logfile%
  4. echo Batch command: %0 %* >> %logfile%
  5. echo Started at %date% %time% >>%logfile%
  6.  
  7. if [%script%]==[] (
  8.         set script="%~dp0\BatchDrawings_Script.scr"
  9.         argc=0
  10.         ) else (
  11.         set argc=-1
  12.         )
  13. set script=%script:\\=\%
  14.  
  15. :: UPDATE as necessary.
  16. if [%accoreconsole%]==[] set accoreconsole="C:\Program Files\Autodesk\AutoCAD 2022\accoreconsole.exe"
  17.  
  18. set count=1
  19. for %%x in (%*) do set /A argc+=1
  20.  
  21. :processArgs
  22.    if [%1]==[] goto endmark
  23.    if NOT [%~x1]==[.dwg] goto endmark
  24.    echo Processing [%count%/%argc%]: %~f1
  25.    call %accoreconsole% /i "%~f1" /s %script% /l en-US
  26.    echo     %accoreconsole% /i "%~f1" /s %script% /l en-US >> %logfile%
  27.    set /A count +=1
  28.    if errorlevel 1 goto errormark
  29.    SHIFT
  30.    goto processArgs
  31.  
  32. :errormark
  33.   echo.
  34.   echo.
  35.   echo ERROR processing %~f1
  36.   pause
  37.   echo.
  38.   goto endmark
  39.  
  40. :endmark
  41.   rem
  42.   rem     finished
  43.   rem
  44.   echo Ended at %date% %time% >> %logfile%
  45.   rem
  46.   rem

4. Open two window explorer windows
        4a. To the location where you just saved the above script.
        4b. To the location where you have drawings that need scripting.
5. Select dwg files and drag them to the "BatchDrawings_accoreconsole.bat" you just made.


Now you have the batch script and the AutoCAD script (the system to batch drawings is complete).


EDIT: I removed the use of "command-s"; I don't really know what that version of command does so I probably shouldn't use it in a post.
EDIT: I think my browser autocorrected my text (I did not know it did that)?!
« Last Edit: February 13, 2024, 03:00:20 PM by JohnK »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: DWG Batch Conversion with Lisp ?
« Reply #20 on: February 13, 2024, 04:53:42 PM »
F.W.I.W.

(getenv "DefaultFormatForSave")

Returns "64" which represents AutoCAD 2018 DWG format

in ac2023, 2024, 2025(beta)

Opening a drawing I save fron 2023 yesterday :

Code: [Select]
Opening an AutoCAD 2018 format file.
Regenerating model.
AutoCAD menu utilities loaded.
 KDUBToolsRibbon.mnl loaded . [Build 243:2023.05.25]
Autodesk DWG.  This file is a TrustedDWG last saved by an Autodesk application or Autodesk licensed application.
Command:

. . . just saying . .
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

57gmc

  • Bull Frog
  • Posts: 365
Re: DWG Batch Conversion with Lisp ?
« Reply #21 on: February 13, 2024, 05:05:33 PM »
Wouldn't ObjectDBX be far more complicated then you need?!
I don't understand everyone's issue or aversion to using a simple batch script and a lisp file to do this. Two files.

This is a nice solution John. I'm going to copy it.

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: DWG Batch Conversion with Lisp ?
« Reply #22 on: February 13, 2024, 05:21:18 PM »
Wouldn't ObjectDBX be far more complicated then you need?!
I don't understand everyone's issue or aversion to using a simple batch script and a lisp file to do this. Two files.

This is a nice solution John. I'm going to copy it.
It's the same as what you've already seen in this thread: https://www.theswamp.org/index.php?topic=56891.msg605601#msg605601

I've already linked to that batch script in this thread--and others--and people seem to ignore it and try to write a complicated thing using a combination of lisp, willpower, and duct tape; is it because they don't know what a batch script is?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 365
Re: DWG Batch Conversion with Lisp ?
« Reply #23 on: February 13, 2024, 05:33:59 PM »
Wouldn't ObjectDBX be far more complicated then you need?!
I don't understand everyone's issue or aversion to using a simple batch script and a lisp file to do this. Two files.

This is a nice solution John. I'm going to copy it.
It's the same as what you've already seen in this thread: https://www.theswamp.org/index.php?topic=56891.msg605601#msg605601

I've already linked to that batch script in this thread--and others--and people seem to ignore it and try to write a complicated thing using a combination of lisp, willpower, and duct tape; is it because they don't know what a batch script is?

Unfortunately, I did not test it out back then.  :idiot2:

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: DWG Batch Conversion with Lisp ?
« Reply #24 on: February 14, 2024, 12:09:21 AM »
I had an idea that works.

1 - I save the ACADDOC.LSP file
with the name ACADDOC-STANDARD.LSP

2 - I create a new ACADDOC.LSP
    with the defun S::STARTUP inside

3- inside this defun
   I write all the actions I want
   and at the end,
   after saving the drawing
   I also write (command "close")

   and this way I do everything I want
   SIMPLY


4 - So I open an ACAD session without opening any DWG

5 - I go to the folder that contains the drawings I want to edit

6 - I select them all
(maybe 10 at a time to avoid making too much mess)
and press ENTER

...

and the game is done !
you have only to watch the show !


For example
i want to save every DWG into the Acad 2000 version
preserving the original DWG in the original version

so after doing some things (zoom extents, purge ... and what I want)
I save it with the same name in the same version
and after
I save it in the acad 2000 verison
modifing the name adding to the original name,
the suffix "---[acad 2000]"


It's a game now.

And this system
it lends itself to doing a thousand things.

Naturally
for normal work
B E F O R E opening any drawing
you have to restore the ORIGINAL ACADDOC.LSP file

what do you think about it ?

it is very simple ... and works !

And this wihout the limitations of ObjectDBX and SCR files
« Last Edit: February 14, 2024, 07:29:53 AM by domenicomaria »

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: DWG Batch Conversion with Lisp ?
« Reply #25 on: February 14, 2024, 08:55:39 AM »
You can use Lisp inside of SCR files.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: DWG Batch Conversion with Lisp ?
« Reply #26 on: February 14, 2024, 09:07:13 AM »
You can use Lisp inside of SCR files.
everything ?

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: DWG Batch Conversion with Lisp ?
« Reply #27 on: February 14, 2024, 09:41:27 AM »
You can use Lisp inside of SCR files.
everything ?

I don't understand your question. If you don't want my help, then just please say so.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

57gmc

  • Bull Frog
  • Posts: 365
Re: DWG Batch Conversion with Lisp ?
« Reply #28 on: February 14, 2024, 10:31:55 AM »
You can use Lisp inside of SCR files.
everything ?

I don't understand your question. If you don't want my help, then just please say so.
I think they mean "all lisp functions"?

domenicomaria

  • Swamp Rat
  • Posts: 724
Re: DWG Batch Conversion with Lisp ?
« Reply #29 on: February 14, 2024, 10:36:11 AM »
I don't understand your question.
If you don't want my help,
then just please say so.

I don't understand your last answer...

I just asked if it is possible to use LISP
to write ANYTHING in SCR files...
or if there are LIMITATIONS...

I never used ACCORECONSOLE
and SCR files ...
...
So i am simply trying
to understand something
...

that's all !