TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: domenicomaria on February 12, 2024, 08:01:20 AM

Title: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 12, 2024, 08:01:20 AM
Is it possible to use the DWGCONVERT command ... from Lisp?
(...passing the right arguments...)
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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 !

???
Title: Re: DWG Batch Conversion with Lisp ?
Post by: MrSmith 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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
Title: Re: DWG Batch Conversion with Lisp ?
Post by: MrSmith 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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%
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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…
Title: Re: DWG Batch Conversion with Lisp ?
Post by: MrSmith 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.  
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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 !

Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 12, 2024, 04:07:28 PM
I launched the batch file by simply right clicking on it and "run as administrator"
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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. ::       )
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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!
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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


Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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".
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi 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...

Title: Re: DWG Batch Conversion with Lisp ?
Post by: ribarm 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...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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)?!
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz 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 . .
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc 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 (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:
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 14, 2024, 08:55:39 AM
You can use Lisp inside of SCR files.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 09:07:13 AM
You can use Lisp inside of SCR files.
everything ?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK 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.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc 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"?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria 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 !
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 10:43:31 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 !

The only limitation I can think of is that you don't want to use dialogs or anything that requires user interaction. Also, your lisp solution is what ScriptPro does. It's a nice GUI for batch processing. The only problem is that you have to restart AutoCAD for each dwg processed, but it does it automatically. AcCoreConsole is much faster though. If you just want an easy solution, ScriptPro (https://github.com/ADN-DevTech/ScriptPro-installer#start-of-content) is user friendly. But if you have tasks that take a lot of processing time, AcCoreConsole is a better choice.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 11:03:34 AM
The only limitation I can think of is that you don't want to use dialogs or anything that requires user interaction. Also, your lisp solution is what ScriptPro does. It's a nice GUI for batch processing. The only problem is that you have to restart AutoCAD for each dwg processed, but it does it automatically. AcCoreConsole is much faster though. If you just want an easy solution, ScriptPro (https://github.com/ADN-DevTech/ScriptPro-installer#start-of-content) is user friendly. But if you have tasks that take a lot of processing time, AcCoreConsole is a better choice.

and if I only want the content (excluding dialogues and interactions)
of the ACADDOC.LSP file (and the inside defun S::STARTUP) ...
to be executed ...

do you think that ACCORECONSOLE does it?
...

And if I only want this,
what is the command I have to put in the SCR file?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 11:09:43 AM
The only limitation I can think of is that you don't want to use dialogs or anything that requires user interaction. Also, your lisp solution is what ScriptPro does. It's a nice GUI for batch processing. The only problem is that you have to restart AutoCAD for each dwg processed, but it does it automatically. AcCoreConsole is much faster though. If you just want an easy solution, ScriptPro (https://github.com/ADN-DevTech/ScriptPro-installer#start-of-content) is user friendly. But if you have tasks that take a lot of processing time, AcCoreConsole is a better choice.

and if I only want the content (excluding dialogues and interactions)
of the ACADDOC.LSP file (and the inside defun S::STARTUP) ...
to be executed ...

do you think that ACCORECONSOLE does it?
...

And if I only want this,
what is the command I have to put in the SCR file?
I don't know what you have in startup, but I doubt you would need it when using console. It's like using ObjectDbx, there's no interface. When using console, you can't do anything with the coordinate system, like Zoom extents. You may be able to just change the extension on your lisp file to scr and run it. Give it a try. That's the best way to find out what you can do.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 11:28:31 AM
You may be able to just change the extension on your lisp file to scr and run it. Give it a try. That's the best way to find out what you can do.
I tried... but nothing happens!
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 11:34:09 AM
I don't have an app for 7z. Can you post the scr using code tags? Or as a zip?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 11:40:48 AM
7z should be a Zip file...try renaming it...
https://www.7-zip.org/download.html
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 11:43:37 AM
Renaming doesn't work. I can't use 7z on my work pc.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 11:57:25 AM
Renaming doesn't work. I can't use 7z on my work pc.

...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 12:28:01 PM
I don't think you are doing it right. Re read John's code in post 17. You have to make a couple of changes to his bat file.

In the code below, is the name of the scr file to run. If you always name your scr file BatchDrawings_Script.scr, then you don't ever need to edit the bat file again.
Code: [Select]
if [%script%]==[] (
        set script="%~dp0\BatchDrawings_Script.scr"
In the line below, change it to the path of your acad.exe.
Code: [Select]
:: UPDATE as necessary.
if [%accoreconsole%]==[] set accoreconsole="C:\Program Files\Autodesk\AutoCAD 2024\accoreconsole.exe"
There's no need to create a bat that names all the dwg files. In Windows, if you drag a file onto a bat file, the bat file will run with the file passed as an argument. So just drag a bunch of dwg files onto the bat file and it will take care of running core console.

As far as your lisp goes, you have to debug it on a single dwg first. Do that by opening a dwg and running the SCRIPT command or dragging the scr file onto AutoCAD.


Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 12:59:04 PM
I don't think you are doing it right.

you suggested me to try renaming the LISP file extension to SCR

And I tried

And it doesn't seem to work

so how do you use Lisp in an SCR file?

There's no need to create a bat that names all the dwg files. In Windows, if you drag a file onto a bat file, the bat file will run with the file passed as an argument. So just drag a bunch of dwg files onto the bat file and it will take care of running core console.

I have a main folder that contains other subfolders that contain other folders ... that contain DWG files ...

First, with Lisp, I find the structure of the folders and sub-folders and for each of these I look for the DWG files contained

So I don't have some file somewhere to drag into the BAT file
but I have many files in different locations...

But this should not be a problem for a BAT file ...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: 57gmc on February 14, 2024, 01:56:46 PM
you suggested me to try renaming the LISP file extension to SCR

And I tried

And it doesn't seem to work
Then troubleshoot the scr using the method I told you. Also, I don't know how you are trying to run the script. If you want to code your own method for running AcCoreConsole, then you will have to send each file to the console by loading the script along with it. The syntax is:
"C:\Program Files\Autodesk\AutoCAD 2024\accoreconsole.exe" /i "path\Drawing1.dwg" /s "path\BatchDrawings_Script.scr"

Your code needs to build a bat that has a line like that for each file you want to process.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 14, 2024, 04:02:30 PM
1. 7z and zip are differnt. Apples and Oranges. You cannot change the extension.

2. Looks like you are using dos_lib in that lisp which I don't think could be run by accoreconsole without trying to load that ARX/dll. I only glanced at the code (very busy at the moment) but I'm pretty sure you don't need that much code to do what you want (seems to be a saveas would be just fine).

3. My script has the ability to be called several differnt ways; a. with a drang-n-drop or b. by another script (see my post #5 for what that list looks like).  This is a list of drawings to run the script on (I set those up when I start setting up my project so I have it ready when I need it).

4. SCR is just another text file with a differnt file extension at the end of the day (Like what you thought 7z and zip were). It just so happens that accoreconsole will only "load files with the extension of .scr" but any lisp within the file are loaded too. This is the same thing as the "script" command in AutoCAD.

5. My script to load a file into accoreconsole is not using a FOR loop. Using a "FOR %%DWG IN ... DO ..." in a bat file would case the DO part to start over and over again (much like how scriptpro starts a new instance of AutoCAD for each iteration). ...my stuff is good, theirs is garbage.

6. Using acccoreconsole will have other limitations but you have to expect that; it is a very light/trimmed down AutoCAD. There isnt a GUI so imagine using only the command line to do things like plot, purge, erase, etc. (the things you would want to do to a lot of files).  You wouldnt use accoreconsole to draw with.

7. If you don't know where drawings are located then how can you possibly know what you need to do to them? Yes, you could recurssivly dig into a folder structure to find files with a BATCH script, but this is sounding more like a job for eTransmit then a batch script.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 09:59:18 PM
Then troubleshoot the scr using the method I told you. Also, I don't know how you are trying to run the script. If you want to code your own method for running AcCoreConsole, then you will have to send each file to the console by loading the script along with it. The syntax is:
"C:\Program Files\Autodesk\AutoCAD 2024\accoreconsole.exe" /i "path\Drawing1.dwg" /s "path\BatchDrawings_Script.scr"

Your code needs to build a bat that has a line like that for each file you want to process.

so this code (by MrSmith) that creates the file Bat is not good ?

 (foreach it outList (setq txt (strcat "\"" it "\"," txt)))
 (setq txt (vl-string-right-trim "," txt))
 (setq txt (strcat "FOR %%G IN (" txt ") DO \"" (findfile "accoreconsole.exe") "\" /i %%G /s \"" scriptFile "\""))
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 14, 2024, 10:14:19 PM
but I'm pretty sure you don't need that much code to do what you want (seems to be a saveas would be just fine).
what I need to do is more complex
the Lisp contained in the SCR file is just a piece of the real Lisp
because I made a (partial) copy and paste (and all very quickly)
For this reason you will have found pieces of code that seemed superfluous


5. My script to load a file into accoreconsole is not using a FOR loop. Using a "FOR %%DWG IN ... DO ..." in a bat file would case the DO part to start over and over again (much like how scriptpro starts a new instance of AutoCAD for each iteration). ...my stuff is good, theirs is garbage.
ok

7. If you don't know where drawings are located then how can you possibly know what you need to do to them? Yes, you could recurssivly dig into a folder structure to find files with a BATCH script, but this is sounding more like a job for eTransmit then a batch script.
I can find all the files in all the subfolders and create a list of all the file names including the entire path
This means that I know where are the files
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 14, 2024, 10:36:05 PM
Then troubleshoot the scr using the method I told you. Also, I don't know how you are trying to run the script. If you want to code your own method for running AcCoreConsole, then you will have to send each file to the console by loading the script along with it. The syntax is:
"C:\Program Files\Autodesk\AutoCAD 2024\accoreconsole.exe" /i "path\Drawing1.dwg" /s "path\BatchDrawings_Script.scr"

Your code needs to build a bat that has a line like that for each file you want to process.

so this code (by MrSmith) that creates the file Bat is not good ?

 (foreach it outList (setq txt (strcat "\"" it "\"," txt)))
 (setq txt (vl-string-right-trim "," txt))
 (setq txt (strcat "FOR %%G IN (" txt ") DO \"" (findfile "accoreconsole.exe") "\" /i %%G /s \"" scriptFile "\""))

No, that code looks like it would create a FOR loop in a batch script. That doesn't look bad to me. I choose not to use a FOR loop in my batch script because I didn't want to restart accoreconsole for each drawing but that doesn't mean MrSmith's code is bad.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 14, 2024, 10:47:12 PM
but I'm pretty sure you don't need that much code to do what you want (seems to be a saveas would be just fine).
what I need to do is more complex
the Lisp contained in the SCR file is just a piece of the real Lisp
because I made a (partial) copy and paste (and all very quickly)
For this reason you will have found pieces of code that seemed superfluous
...>%

I'm sorry but we cannot answer questions without knowing the entire question.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 15, 2024, 08:12:45 AM

I have been using a script file (SCR) like this for many years:
Code: [Select]
_.OPEN
"C:/Temp/A001.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
_.OPEN
"C:/Temp/A002.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
... etc.
_.NEW
"C:/Temp/End.dwt"
(load "_SCR_BatchEnd"); reset variables etc.
(_SCR_BatchEnd nil); reset variables etc.
(alert "Elaborazione conclusa correttamente.")
(princ "\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-")
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 15, 2024, 08:39:21 AM
what is "_SCR_BatchExe" ?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 15, 2024, 09:23:34 AM
what is "_SCR_BatchExe" ?
a lisp File, can be .LSP . FAS/(.DES for BricsCAD)
it is a file that when loaded executes various types of instructions (print, modify, export...)
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 15, 2024, 09:29:32 AM

I have been using a script file (SCR) like this for many years:
Code: [Select]
_.OPEN
"C:/Temp/A001.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
_.OPEN
"C:/Temp/A002.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
... etc.
_.NEW
"C:/Temp/End.dwt"
(load "_SCR_BatchEnd"); reset variables etc.
(_SCR_BatchEnd nil); reset variables etc.
(alert "Elaborazione conclusa correttamente.")
(princ "\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-")

and what do I have to do to run this script?
drag it into acad ?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 15, 2024, 09:53:47 AM
however a few minutes ago I managed to use ACCORECONSOLE
with a simple BAT file and with an SCR file which is a simple LSP file

...

and I have for the moment understood that
no ARXLOAD
no (command "opendcl")
no comments
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 15, 2024, 12:36:37 PM

I have been using a script file (SCR) like this for many years:
Code: [Select]
_.OPEN
"C:/Temp/A001.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
_.OPEN
"C:/Temp/A002.dwg"
(load "_SCR_BatchExe") ; here you can do anything you want as long as it doesn't break the script
(if(=(getvar "DBMOD")0)(command "_.CLOSE")(command "_.CLOSE" "_Y"))
... etc.
_.NEW
"C:/Temp/End.dwt"
(load "_SCR_BatchEnd"); reset variables etc.
(_SCR_BatchEnd nil); reset variables etc.
(alert "Elaborazione conclusa correttamente.")
(princ "\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-\n-")

and what do I have to do to run this script?
drag it into acad ?
(command "_.SCRIPT" "yourFile.scr") you can also Drag&Drop...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 15, 2024, 04:41:07 PM
however a few minutes ago I managed to use ACCORECONSOLE
with a simple BAT file and with an SCR file which is a simple LSP file

...

and I have for the moment understood that
no ARXLOAD
no (command "opendcl")
no comments
Do you know about ActiveX functions and accoreconsole?

Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 15, 2024, 11:43:47 PM
Do you know about ActiveX functions and accoreconsole?
this is the code to make the BAT file i need :

Code - Auto/Visual Lisp: [Select]
  1. (defun :FILE-WRITE-ASCII (list-strings full-file-name / file-wstream )
  2.    (setq file-wstream (open full-file-name "w") )
  3.    (foreach item list-strings (write-line item file-wstream) )
  4.    (close file-wstream )
  5. )
  6.  
  7. (defun :ACC-MAKE-DIR-BAT (folder-path full-accoreconsole-name full-scr-name full-bat-name )
  8.    (setq folder-path   (vl-string-right-trim "\\" folder-path) )
  9.    (setq full-scr-name (vl-string-right-trim ".SCR" (strcase full-scr-name) ) )
  10.    (:FILE-WRITE-ASCII
  11.                         (list
  12.                            "echo on"
  13.                            ""
  14.                            (strcat "set accoreexe=" "\""  full-accoreconsole-name "\"" )
  15.                            ""
  16.                             (strcat "set \"source=" folder-path "\"")
  17.                            ""
  18.                            (strcat "set script=" "\"" full-scr-name "\"")
  19.                            ""
  20.                            "FOR /f \"delims=\" %%f IN ('dir /b \"%source%\\*.dwg\"') DO %accoreexe% /i \"%source%\\%%f\" /s %script%"
  21.                            ""
  22.                            "pause"
  23.                         )
  24.                         full-bat-name
  25.    )
  26.    full-bat-name
  27. )
  28.  
  29.  
  30. (startapp full-bat-name)

and this is the SCRIPT ...

if you set  k-vla = t 
it doesn't work ! ... (it does nothing)

Code - Auto/Visual Lisp: [Select]
  1. (setvar "layerfilteralert" 0)
  2. (setq k-vla nil)
  3.  
  4. (defun LM:DWGVERSION ( dwg / des vrs )
  5.     (cond
  6.         (   (not (and (setq dwg (findfile dwg) ) (setq des (open dwg "r") ) ) )
  7.         )
  8.         (   (wcmatch (strcase dwg t) "*`.dw[gst]")
  9.             (setq vrs (strcase (substr (read-line des) 1 6)))
  10.         )
  11.         (   (wcmatch (strcase dwg t) "*`.dxf")
  12.             (repeat 7 (read-line des))
  13.             (setq vrs (strcase (read-line des)))
  14.         )
  15.     )
  16.     (if (= 'file (type des)) (close des))
  17.     (cdr
  18.         (assoc vrs
  19.            '(
  20.                 ("AC1032" . "2018")
  21.                 ("AC1027" . "2013-2015")
  22.                 ("AC1024" . "2010-2012")
  23.                 ("AC1021" . "2007-2009")
  24.                 ("AC1018" . "2004-2006")
  25.                 ("AC1015" . "2000-2002")
  26.                 ("AC1014" . "Release 14")
  27.                 ("AC1012" . "Release 13")
  28.                 ("AC1009" . "Release 11/12")
  29.                 ("AC1006" . "Release 10")
  30.                 ("AC1004" . "Release 9")
  31.                 ("AC1003" . "Release 2.60")
  32.                 ("AC1002" . "Release 2.50")
  33.                 ("AC1001" . "Release 2.22")
  34.                 ("AC2.22" . "Release 2.22")
  35.                 ("AC2.21" . "Release 2.21")
  36.                 ("AC2.10" . "Release 2.10")
  37.                 ("AC1.50" . "Release 2.05")
  38.                 ("AC1.40" . "Release 1.40")
  39.                 ("AC1.2"  . "Release 1.2")
  40.                 ("MC0.0"  . "Release 1.0")
  41.             )
  42.         )
  43.     )
  44. )
  45.  
  46.  
  47. (defun :LAYER-FILTERS-DELETE ()
  48.    (vl-catch-all-apply
  49.       '(lambda   ()
  50.           (vla-remove
  51.              "AcLyDictionary"
  52.           )
  53.        )
  54.    )
  55.    (princ "\nAll layer filters have been deleted.")
  56.    (princ)
  57. )
  58.  
  59. (if k-vla (:LAYER-FILTERS-DELETE) )
  60.  
  61.  
  62. (setenv "DefaultFormatForSave" "64")
  63.  
  64.  
  65. (setq curr-dwg-name (getvar "dwgname") )
  66. (setq curr-full-dwg-name (strcat (getvar "dwgprefix")  curr-dwg-name) )
  67. (princ (strcat "\nthe " curr-dwg-name "\n version is : " (LM:DWGVERSION curr-full-dwg-name ) ) )
  68.  
  69.  
  70. (setq new-dwg-name       (strcat (vl-filename-base (getvar "dwgname") ) "---[ACAD-2000].dwg") )
  71. (setq new-full-dwg-name (strcat (getvar "dwgprefix")  new-dwg-name) )
  72.  
  73. (setenv "DefaultFormatForSave" "12")
  74.  
  75.  
  76. (if k-vla
  77.    (vla-SaveAs (vla-get-activedocument (vlax-get-acad-object)) new-full-dwg-name acR15_DWG)
  78.    (if(findfile new-full-dwg-name )
  79.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name "y") )
  80.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name    ) )
  81.    )
  82. )
  83.  
  84.  
  85. (if cmd-r
  86.    (princ  
  87.          (strcat   "\n\nsave as ACAD 2000 version : "
  88.                   "\n\nThe active DWG has been saved as : \n\n< " (strcase new-dwg-name) " > ."
  89.                   "\n\nIts verified version is : " (LM:DWGVERSION (strcat (getvar "dwgprefix") new-dwg-name ) )
  90.          )
  91.    )
  92.    (princ (strcat "\n\nAn error occurred attempting to save \n\n< " new-dwg-name  " .")   )
  93. )
  94.  
  95.  
  96.  
  97.  
  98. (setenv "DefaultFormatForSave" "64")
  99.  
  100.  
  101. (if k-vla
  102.    (vl-cmdf "close")
  103. )
  104.  

consider that in the script there are some superfluous instructions
because I used this code in the defun s::startup
to perform the same task in a different way.

Because by changing S::STARTUP in acaddoc.lsp there are NO LIMITS !

But ACCORECONSOLE is much faster because it doesn't have a graphical interface ...

Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 16, 2024, 05:10:41 AM
and NO special character in the file and path names
such as    °
(that are allowed in windows)
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 16, 2024, 07:11:50 AM
however the code strictly necessary for the script is only that below :
Code - Auto/Visual Lisp: [Select]
  1.    (setenv "DefaultFormatForSave" "64")
  2.  
  3.    (vl-cmdf "_qsave")
  4.  
  5.    (setq curr-dwg-name (getvar "dwgname") )
  6.    (setq curr-full-dwg-name (strcat (getvar "dwgprefix")  curr-dwg-name) )
  7.  
  8.    (setq new-dwg-name      (strcat (vl-filename-base (getvar "dwgname") ) "---[ACAD-2000].dwg") )
  9.    (setq new-full-dwg-name (strcat (getvar "dwgprefix")  new-dwg-name) )
  10.  
  11.    (setenv "DefaultFormatForSave" "12")
  12.    
  13.    (if(findfile new-full-dwg-name )
  14.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name "y") )
  15.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name    ) )
  16.    )
  17.  
  18.    (setenv "DefaultFormatForSave" "64")
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 16, 2024, 03:08:10 PM
@Domenico: have you never tried the vlax-...   functions in Core Console?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 16, 2024, 03:59:45 PM
Not for the moment ...
... soon i will give it a try

ciao
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 16, 2024, 07:37:04 PM
I thought vlax-.. didn't work in accoreconsole.

?? has that changed ?

or have I been delusional for the last 12 (or so ) years.  :|
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 16, 2024, 11:32:37 PM
@Domenico: have you never tried the vlax-...   functions in Core Console?
sorry... it doesn't work... as expected...

so ACCORECONSOLE can be very useful on many occasions
but there are also many limitations to take into account...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 17, 2024, 12:32:39 AM
while the code below, for a Dwg that contains only a TEXT entity,
works normally ...
Code - Auto/Visual Lisp: [Select]
  1. (princ ". . . . . . . . . . . . . . . . . . . . . . . . . . . .")
  2. (princ "start")
  3. (setq el      (entlast)
  4.       egl     (entget el)
  5.       new-egl (subst (cons 1 "S U B S T") (assoc 1 egl) egl)
  6. )
  7. (entmod new-egl)
  8. (entupd el)
  9. (princ ". . . . . . . . . . . . . . . . . . . . . . . . . . . .")
  10. (princ "end")  
in ACCORECONSOLE
it doesn't work !
...
it seems to work ...
but it doesn't make any modification to the dwg !


...
if this is the true
(find some of my possible errors, please)
the question is :
what it is possible to do with ACCAORECONSOLE ?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 17, 2024, 03:13:36 AM
This the reason I don't like Core Console...
Try Odbx with some limitation... It is fast...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: Marc'Antonio Alessi on February 17, 2024, 12:08:04 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 . .
Odbx save in same version of CAD used
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 17, 2024, 01:27:55 PM
I really wish you would state what you are trying to do using complete thoughts. It looks like you are trying to replace some text AND save a COPY of the drawing. In the thread I linked to I gave an updated text find and replace that I've used many times. A save as is easy to do. Using packages like dos_lib to parse a path string is unnecessary and probably not going to work in accoreconsole. You keep typing your hands with these odd snippets and then blame the tool.

ObjectDBX is just another method to use AutoCAD as the interface to update drawings. Doing so could lock up your PC and cause you to be unproductive during that time; using a smaller footprint process like accoreconsole is far better for production.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 17, 2024, 02:04:43 PM
I really wish you would state what you are trying to do using complete thoughts. It looks like you are trying to replace some text AND save a COPY of the drawing. In the thread I linked to I gave an updated text find and replace that I've used many times. A save as is easy to do. Using packages like dos_lib to parse a path string is unnecessary and probably not going to work in accoreconsole. You keep typing your hands with these odd snippets and then blame the tool.
I don't blame ACCORECONSOLE ...

I am only trying to understand
what Is possibile to do with
ACCORECONSOLE

this is my complete and simple thought

but I saw that the ARX files cannot be loaded,
the VLA-XXX functions
and the VLAX-XXX functions do not work,
ENTMOD, ENTUPD and perhaps
ENTMAKE (this last function is not I've tested it yet)
they don't work...

and so I'm wondering what good can be done....

and it's certainly one more possibility...

because something can be done...

but I expected that they weren't there all these limitations
but
when I asked you if there were any LIMITATIONS...

when I asked you if EVERYTHING could be done,

you got angry and told me
to be clear and to say clearly that I didn't want your help...

but there is NO RELATIONSHIP
between the TWO THINGS...

if I write something it is only because
I try to understand something
and this means that anyone who helps me
to understand something is welcome...

...

there are no hidden thoughts,
hidden purposes but everything
is very simple...

have a nice day
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 17, 2024, 02:43:22 PM
`everything` you NEED or WANT? `Everything` is not a fair question because the answer invariably has to be NO because you cannot show dialog boxes, or draw AEC things, or use third party libraries like Python or probably dos_lib, or etc., etc..

If all you need to do is to save a copy of a file, make a PDF, find and replace text, etc. than you can most certinaly use accoreconsole. These are all things that do not NEED to use the VL* libraries.

I've used entmod.
https://www.theswamp.org/index.php?topic=4591.msg605179#msg605179

So, what does batch drawing conversion mean to YOU? Saving a copy, doing text replacement, and what? What VLX functions do you NEED?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 17, 2024, 02:59:09 PM
`everything` you NEED or WANT? `Everything` is not a fair question because the answer invariably has to be NO because you cannot show dialog boxes, or draw AEC things, or use third party libraries like Python or probably dos_lib, or etc., etc..

If all you need to do is to save a copy of a file, make a PDF, find and replace text, etc. than you can most certinaly use accoreconsole. These are all things that do not NEED to use the VL* libraries.

I've used entmod.
https://www.theswamp.org/index.php?topic=4591.msg605179#msg605179

So, what does batch drawing conversion mean to YOU? Saving a copy, doing text replacement, and what? What VLX functions do you NEED?

Code - Auto/Visual Lisp: [Select]
  1. (setq el      (entlast)
  2.       egl     (entget el)
  3.       new-egl (subst (cons 1 "S U B S T") (assoc 1 egl) egl)
  4. )
  5. (entmod new-egl)
  6. (entupd el)
  7.  
Why doesn't this code work?
 ...
I have no special needs.

 I have already solved my problems.

 I'm just trying to understand something.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 17, 2024, 04:21:36 PM
Quote
Code - Auto/Visual Lisp: [Select]
  1. (setq el      (entlast)
  2.       egl     (entget el)
  3.       new-egl (subst (cons 1 "S U B S T") (assoc 1 egl) egl)
  4. )
  5. (entmod new-egl)
  6. (entupd el)
  7.  
Why doesn't this code work?

That is probably the stupidest test I can imagine for ACCORECONSOLE.

There are several elements to a test.
establist your goals,
write the code,
is the code logically correct,
is the code syntactically correct,
does the code load,
does the code run,
does the code act as expected,
is it error free,
is it safe,
are there side effects,
is it performant,
etc . .

To my mind you have failed the first and third elements of the procedure.
What are the chances that opening a random drawing and executing (entlast) will return an entity that has a dxf key of 1 ??
and that the entity is the one you wanted to modify.


I'm suggesting that you put your time into doing some reading on the issues mentioned in this thread,
rather than pollute the space with incomplete thoughts and questions disguised as statements.

This is a peer to peer forum and anyone reading these posts in the future is going to be more confused at the the end that they may have been at the start.

Regards,


Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 17, 2024, 11:16:12 PM
To my mind you have failed the first and third elements of the procedure.
What are the chances that opening a random drawing and executing (entlast) will return an entity that has a dxf key of 1 ??
and that the entity is the one you wanted to modify.

I did the test on three drawings that contain only 1 entity. and this entity is a text.
(and I already explained this in previous posts)
I tested the script (i.e. simple lisp code and it works fine without any problem)


There are several elements to a test.
-establist your goals,
my gol is discover what is possible to do with accoreconsole,  because i don't know it
and to test something that I don't know I begin from simple and little things

write the code (it has been done)
is the code logically correct,  (I think so... it's very simple)
is the code syntactically correct, (I think so... it's very simple)
does the code load, yes ...
does the code run,  yes ...
does the code act as expected,  i tested it as "normal" lisp before and it works fine
is it error free, (I think so... it's very simple)
is it safe, (I think so... it's very simple)
are there side effects, (... side effects certainly not dangerous ...)
is it performant, (it is a secondary aspect in this simple case)


. . . trying to know something you don't know
and doing tests starting from small and simple things,
is it stupid ?

I do not agree !

I think it's smart !


rather than pollute the space
with incomplete thoughts
and questions disguised as statements

I honestly don't understand the meaning of these statements
and the reasons for the rude tone

This is a peer to peer forum and anyone reading these posts
in the future is going to be more confused
at the end than they may have been at the start.

to clarify it is necessary to understand the simple things first ...
... I don't know accoreconsole ...
... and I did some small tests, very simple ...
... the small steps help to understand bigger things ...
... and I think this contributes to the clarity...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 12:18:40 AM
What are the chances that opening a random drawing and executing (entlast) will return an entity that has a dxf key of 1 ??
and that the entity is the one you wanted to modify.

this image (which has already been posted by me)...
shows what happens while ACCORECONSOLE is active
(  c:\windows\system32\cmd.exe  )


What are the chances that opening a random drawing ...  (100% ... it is not a random drawing)

and as you can see (for drawings that contain only 1 entity and that is a TEXT)
it finds the entity of TEXT type ,
extracts the list with ENTGET,
modifies the list with SUBST, ...

... but even if everything seems to work,
at the end the result is that
the drawing is not modified ...
....
... basically nothing happens...

... this is what I'm trying to understand...

Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 18, 2024, 04:29:06 AM
WorksforMe

Code - Auto/Visual Lisp: [Select]
  1.         ( (lambda ( / )
  2.                 (setq   el      (entlast)
  3.                                 egl     (entget el)
  4.                                 new-egl (subst (cons 1 "S U B S T") (assoc 1 egl) egl)
  5.                 )
  6.                 (entmod new-egl)
  7.                 (entupd el)
  8.                 (command "_qsave")
  9.                   ;; save
  10.                  
  11.             (princ)
  12.           )
  13.    )
  14.  

Quote
----------------------------------------x- 2024/02/18 -x------
Batch command: "D:\BatchingScriptFiles\BatchDrawings_accoreconsole.bat" D:\BatchingScriptFiles\Drawing101.dwg
Started at 2024/02/18 22:26:54.43
    "C:\Program Files\Autodesk\AutoCAD 2023\accoreconsole.exe" /i "D:\BatchingScriptFiles\Drawing101.dwg" /s "D:\BatchingScriptFiles\BatchDrawings_accoreconsole.scr" /l en-US
Ended at 2024/02/18 22:26:55.34


So I have no idea why it doesn't work for you.
Unless you are doing something different than advised.


Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 05:41:23 AM
@kdub_nz

I'll believe you if you tell me it works!

that's what I want to hear,
because this means that it is possible to do many things
with Accoreconsole...
...
I didn't put it in my script
(command "_qsave") !
(and this is what you should have told me from the first moment)

And it was "slightly" necessary!

But still I can't get it to work.

It seems like everything is fine
looking at the CMD.exe window
but when I open the 3 drawings on which I do the test
nothing has changed.

There is something important
which escapes me even now!

If I find out what it is I'll let you know!

Thank you
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 06:25:21 AM
Code - Auto/Visual Lisp: [Select]
  1. (setq el      (entlast)
  2.       egl     (entget el)
  3.       new-egl (subst (cons 1 "AAAAAAAA") (assoc 1 egl) egl)
  4. )
  5. (princ (assoc 1 egl) )
  6. (entmod new-egl)
  7. (entupd el)
  8. (setq p1 (list 0 0 0) p2 (list 99 99 99) )
  9. (entmakex (list '(0 . "LINE") '(100 . "AcDbEntity") '(410 . "Model") '(100 . "AcDbLine") (cons 10 p1) (cons 11 p2) ) )
  10. (command "_qsave")

take a look to the
cmd.exe window

I tested also entmakex to draw a line...

And it seems everything goes well
(there is also qsave !)

But at the end
nothing happens !

And the tested files are NOT read only !
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 10:14:47 AM
and in any case in reality I didn't forget to add to the script
(command "_qsave")
because I had taken it for granted that the changes made to the drawing
by accoreconsole were stored ...
(certainly I reasoned badly also because I don't know accoreconsole)
...
but I still can't get it to work
(also adding to the script (command "_qsave") )
...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 18, 2024, 01:07:48 PM
Without looking at the code (I didn't get past the part where you use ENTLAST to--hopefully--get a text item. My guess is that you have the drawing open in AutoCAD when you try to modify the drawing in accoreconsole (thus open the file with accoreconsole in readonly).
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 01:52:02 PM
Without looking at the code (I didn't get past the part where you use ENTLAST to--hopefully--get a text item. My guess is that you have the drawing open in AutoCAD when you try to modify the drawing in accoreconsole (thus open the file with accoreconsole in readonly).
NOT hopefully--get a text item
but certainly get a text item,
because the drawings on which I did the tests
contain only one entity... and it is obviously a TEXT !

My guess is that you have the drawing open in AutoCAD when you try to modify the drawing in accoreconsole
absolutely NOT...
I am aware that if a file is open in one application
it cannot be opened in write mode by another application...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 18, 2024, 01:55:29 PM
@

I shouldn't HAVE to tell you anything
. . particularly that you SHOULD save the drawing after you make changes to it if you want the changes to be sustained.

just stop and think before you blame me for not telling you.


Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 18, 2024, 02:07:27 PM
@

I shouldn't HAVE to tell you anything
. . particularly that you SHOULD save the drawing after you make changes to it if you want the changes to be sustained.

just stop and think before you blame me for not telling you.
I don't blame you for not telling me!

It was a serious oversight on my part...

Partly due to the fact that I thought that the changes made by Accoreconsole
were stored anyway and therefore there was nothing to save.

But it was the wrong reasoning of a person
who does not know how Accoreconsole works.

That is probably the stupidest test I can imagine for ACCORECONSOLE.
What are the chances that opening a random drawing and executing (entlast)
will return an entity that has a dxf key of 1 ??

But before you, very kindly, tell me that what I proposed is
the stupidest test you've ever seen...
... try reading the other posts FIRST
where I had already explained that
I was doing the tests on drawings containing a single entity
and that this was a TEXT
... so the chances to get a text entity with ENTLAST are 100% !

... But you haven't read these posts ...
... and you told me that the my test is
the stupidest you've ever seen...
...
and you also suggested that
before writing something,
it would be good for me
to first read what was written in previous posts...

And yours is certainly the right advice.

And it applies to everyone.


For you too.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 18, 2024, 02:26:52 PM
You are correct.
That wasn't the stupidist code I've seen.

It was impolite of me to say so.

I shan't do it again.

//-

On my signature I used to have
"  Everything will work just as you expect it to, unless your expectations are incorrect.  "

Perhaps I should have said that.


Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 18, 2024, 03:48:22 PM
Does my find and replace routine work?

Guess:
kdub seemed to use my batch script; maybe it’s your batch scrip that’s not loading the right script?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 18, 2024, 04:22:43 PM
Does my find and replace routine work?

Guess:
kdub seemed to use my batch script; maybe it’s your batch scrip that’s not loading the right script?

Yes John, I used your .bat and a suitably modified .scr.
It worked nicely.

I haven't used accc for years.
Have used ScriptPro

Before that I used  an app I hacked together long, long ago.
I'd like to see ScriptPro rejuvinated for ac2025.

// back to the issue at hand :
I believe that the original goal of cleaning up and saving drawings could be achieved nicely using your batcher ( with a suitable script file).

Regards,
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 19, 2024, 04:35:51 AM
maybe it’s your batch scrip that’s not loading the right script?
I understand that you are not addressing me... but to remove any doubt...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 19, 2024, 10:53:08 AM
Does my find and replace routine work?
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 19, 2024, 02:09:02 PM
Does my find and replace routine work?

yes

it works

but qsave however fails allways !

I also tried saving the files in Autocad 2000 format
to see if for some reason qsave would work

but he never saves what he does

I didn't add it to the end of the script...
...but now even if I did it, nothing has changed!

And the files are NOT read only !

And are NOT open in another application or in Acad


Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 19, 2024, 07:55:10 PM
Works for me.

Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / )
  2.         (setq el      (entlast)
  3.           egl     (entget el)
  4.           new-egl (subst (cons 1 "AAAAAAAA") (assoc 1 egl) egl)
  5.         )
  6.         (princ (assoc 1 egl) )
  7.         (entmod new-egl)
  8.         (entupd el)
  9.         (setq p1 (list 0 0 0) p2 (list 99 99 99) )
  10.         (entmakex (list '(0 . "LINE") '(100 . "AcDbEntity") '(410 . "Model") '(100 . "AcDbLine") (cons 10 p1) (cons 11 p2) ) )
  11.         (command "_qsave")
  12.                   (princ)
  13. ))
  14.  
  15.  

Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 19, 2024, 08:16:38 PM
I've got you to eliminate a few possibilities and now I'm thinking it might be a difference in your batch script and mine (kdub has no problems and neither does anyone else who's used my batch script) and the only difference between yours and mine--besides the for loop stuff--is that I specifiy a language. Try to add the language flag when you call acccoreconsole: "/l en-US".

Not the greatest test but let's roll with it. Try the <DOT> before the qsave to see if that helps.

Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / el tel)
  2.     (setq el (entget (entlast)))
  3.     (setq tel (entmod
  4.                 (subst
  5.                   (cons 1 "abc...")
  6.                   (assoc 1 el)
  7.                   el)))
  8.     (if (tel)
  9.       (princ "\n----> PASS!")                   ; -If entmod didnt return nil.
  10.       (progn                                    ; -Start printing some information
  11.         (princ "\n *ERROR* Faild to entmod")
  12.         (princ (strcat
  13.                  "\nThe current text is: "
  14.                  (assoc 1 (entget (entlast))))) ;; Have no idea if `entlast` will work
  15.         )
  16.       )
  17.     (command "_.qsave")
  18.     )
  19.  )
  20.  



My batch script should have the ability to be called from AutoLisp and tomorrow, when I get in front of a computer with AutoCAD, I will test it out.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 19, 2024, 08:22:13 PM
Hi John,
Perhaps add a Pause statement into the 'FAIL' block.

The ac command line whips past pretty damn quickly  :wink:


//---

I've noticed Dan is back from the jungle and playing with this too  :)
Title: Re: DWG Batch Conversion with Lisp ?
Post by: It's Alive! on February 19, 2024, 08:28:28 PM
I've noticed Dan is back from the jungle and playing with this too  :)

LOL, washing all the bat poop off my clothes, didn’t see any pythons though.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 19, 2024, 08:37:52 PM
Kerry, I just open a command prompt, or powershell, and open accoreconsole to do my testing.
Something like: "C:\Program Files\Autodesk\AutoCAD 2023\accoreconsole.exe /i D:\BatchingScriptFiles\Drawing101.dwg /l en-US"
should open the drawing like you would in AutoCAD. Then the drawing wont close and you can hack away.

If you want to load your script, you can use something like below (I think I remember that LOAD works because that's how you can load ARXs).
(load "D:\\BatchingScriptFiles\\BatchDrawings_accoreconsole.scr")

...
Pythons?! Bleh! I saw a gardner snake last summer and my family still won't let me live it down.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 19, 2024, 11:46:29 PM
Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / el tel)
  2.     (setq el (entget (entlast)))
  3.     (setq tel (entmod
  4.                 (subst
  5.                   (cons 1 "abc...")
  6.                   (assoc 1 el)
  7.                   el)))
  8.     (if (tel)
  9.       (princ "\n----> PASS!")                   ; -If entmod didnt return nil.
  10.       (progn                                    ; -Start printing some information
  11.         (princ "\n *ERROR* Faild to entmod")
  12.         (princ (strcat
  13.                  "\nThe current text is: "
  14.                  (assoc 1 (entget (entlast))))) ;; Have no idea if `entlast` will work
  15.         )
  16.       )
  17.     (command "_.qsave")
  18.     )
  19.  )
  20.  

As "normal" lisp, it works well ... (with entlast too)
even it says :  "extra cdrs in dotted pair on input"

but as script for accoreconsole still doesn't save anything !
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 20, 2024, 12:11:07 AM
Try the <DOT> before the qsave to see if that helps.
Yes !
this is the solution. A simple DOT !
Now it works ! Finally !


however in the script
(if (tell) ... doesn't work ... tell is a variabile, not a function
while
(if tell ... works well
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 20, 2024, 01:04:37 AM
With that in mind, this is probably worth reading
https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-D991386C-FBAA-4094-9FCB-AADD98ACD3EF

//-----
Good call John !
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 20, 2024, 01:07:07 AM
and so, in conclusion of this very long discussion, we can conclude that
in the scripts for Accoreconsole it is certainly possible to use functions of the type
ENTLAST, SUBST, ENTMOD, ENTUPD, ENTMAKE ...

.. and that it is useful to remember that in the end
it is better to add the command "qsave" or "saveas"
preceded by a small but important "dot".

That's all.

As far as I'm concerned,
in order not to create confusion in the heads of the reader,
my posts can be removed by the administrator...

... because what I wrote in the previous lines summarizes everything.

I apologize for the mess I made ...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: JohnK on February 20, 2024, 09:42:26 AM
This morning, I verified my batch script can be called from AutoLisp. I knew this was possible, but I have never used it in this way because using AutoCAD as a scripting interface is a bad idea. However, I wanted to verify this because you choose to ignore my recommendations almost immediately--because you thought this was not possible with what I offered--instead of asking.

So, that's not all!
Exercise 1:
        Please find a "Thank you" in this thread.
Exercise 2:
        Please work on something, offer it to someone in need. Have them ignore you and then help them debug a thing that will NOT work as well as what you offered them without a "thank you".
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 21, 2024, 06:21:14 AM
the problem in my opinion it's not gratitude...

In my opinion this happened:

I asked for a piece of bread

I was offered oranges, apples, kiwis of great quality

but I only needed a piece of bread

I wanted only to understand if with Accoreconsole
I could use functions like
ENTLAST, ENTGET, ASSOC, SUBST, ENTMOD, ENTUPD, ENTMAKE ...

etc...

This is what I just needed.

And to understand this, I did a TEST with some DWGs
containing only 1 entity of type TEXT

The ONLY answer I needed (the piece of bread) was :

<   Domenico you are very distracted!

You forgot to save the drawing!

You must add at the end of the SCRIPT

(command "_.qsave") !   >


That's all ...
... and it took around 90 posts and over 2000 views
to arrive at this simple solution.

So I say that I made a simple, stupid mistake forgetting to save the drawing.

But, (and don't get angry, please!)
it seems that here, the only distracted person,
it's not just me.

But also all the others who posted interventions
and all those who saw the posts!

And for what concerns the gratitude,
... yes, it is a very important thing.

And I'm grateful to TheSwamp,
because it almost always gives me the opportunity
to find solutions and understand new and interesting things.

And so I'm grateful, and I take this opportunity to say it:
"thank you !"
to all those who participate in the discussions
and in particular to the various gurus !

But in this case, there is no problem of gratitude.

But just a problem of not paying enough attention.

My first of all.

But not just only mine ...

...and don't get angry...
Title: Re: DWG Batch Conversion with Lisp ?
Post by: kdub_nz on February 21, 2024, 02:29:41 PM
I can see many references to save and qsave in the code samples provided to you.


Your suggestion that you didn't know you had to save is nullified by your own comments:


>>>

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]"

<<<<


however the code strictly necessary for the script is only that below :
Code - Auto/Visual Lisp: [Select]
  1.    (setenv "DefaultFormatForSave" "64")
  2.  
  3.    (vl-cmdf "_qsave")
  4.  
  5.    (setq curr-dwg-name (getvar "dwgname") )
  6.    (setq curr-full-dwg-name (strcat (getvar "dwgprefix")  curr-dwg-name) )
  7.  
  8.    (setq new-dwg-name      (strcat (vl-filename-base (getvar "dwgname") ) "---[ACAD-2000].dwg") )
  9.    (setq new-full-dwg-name (strcat (getvar "dwgprefix")  new-dwg-name) )
  10.  
  11.    (setenv "DefaultFormatForSave" "12")
  12.    
  13.    (if(findfile new-full-dwg-name )
  14.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name "y") )
  15.       (setq cmd-r (vl-cmdf "_save" new-full-dwg-name    ) )
  16.    )
  17.  
  18.    (setenv "DefaultFormatForSave" "64")




Unfortunately the goals of the topic changed several times throughout the discussion and it seems that the requirement to save a drawing after it is modified had slipped your mind.
Title: Re: DWG Batch Conversion with Lisp ?
Post by: domenicomaria on February 21, 2024, 09:57:48 PM
it's clear that I knew that the dwg needed to be saved...
... I tried to justify myself ...