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

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10661
Re: DWG Batch Conversion with Lisp ?
« Reply #45 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.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #46 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-")

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #47 on: February 15, 2024, 08:39:21 AM »
what is "_SCR_BatchExe" ?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #48 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...)

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #49 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 ?

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #50 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
« Last Edit: February 15, 2024, 09:59:31 AM by domenicomaria »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #51 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...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #52 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?


domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #53 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 ...

« Last Edit: February 15, 2024, 11:58:44 PM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #54 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)

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #55 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")

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: DWG Batch Conversion with Lisp ?
« Reply #56 on: February 16, 2024, 03:08:10 PM »
@Domenico: have you never tried the vlax-...   functions in Core Console?

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #57 on: February 16, 2024, 03:59:45 PM »
Not for the moment ...
... soon i will give it a try

ciao

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2151
  • class keyThumper<T>:ILazy<T>
Re: DWG Batch Conversion with Lisp ?
« Reply #58 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.  :|
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.

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: DWG Batch Conversion with Lisp ?
« Reply #59 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...
« Last Edit: February 16, 2024, 11:36:12 PM by domenicomaria »