Author Topic: How To run LISP in BACH  (Read 13351 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
How To run LISP in BACH
« on: December 18, 2013, 11:31:13 AM »
Hi all,..

I've seen many user trying to run LISP in Batch,...
some have created Huge tools, or using script...seeing running 1 by one open each drawing and wasting user time..
some use ODBX who I think is good but limited.

there is my contribution...
Why not using PUBLISH ?

yes,...you can do it what ever you want with PUBLISH !
PUBLISH open each drawing before printing...
so if you put your LISP on the SuitCase it will RUN !

ex:
Lisp Code:
Code: [Select]
(close (open (strcat "C:\\" (getvar 'dwgname) ".txt") "w"))

Put this Lisp in your Application SuitCase Startup.
and run Publish with any configuration you want.
I use DWF options to prevent wasting Paper print.

so the process its simple...
before runing your Lisp,.
1) add you LISP in the suitcase
2) make a publish
3) remove your lisp from the suitcase.

that's all.
the only problem is if a drawing is already opened, It can't be saved,.

 :ugly:
« Last Edit: December 18, 2013, 11:44:12 AM by Andrea »
Keep smile...

kruuger

  • Swamp Rat
  • Posts: 637
Re: How To run LISP in BACH
« Reply #1 on: December 18, 2013, 06:31:27 PM »
Hi all,..

I've seen many user trying to run LISP in Batch,...
some have created Huge tools, or using script...seeing running 1 by one open each drawing and wasting user time..
some use ODBX who I think is good but limited.

there is my contribution...
Why not using PUBLISH ?

yes,...you can do it what ever you want with PUBLISH !
PUBLISH open each drawing before printing...
so if you put your LISP on the SuitCase it will RUN !

ex:
Lisp Code:
Code: [Select]
(close (open (strcat "C:\\" (getvar 'dwgname) ".txt") "w"))

Put this Lisp in your Application SuitCase Startup.
and run Publish with any configuration you want.
I use DWF options to prevent wasting Paper print.

so the process its simple...
before runing your Lisp,.
1) add you LISP in the suitcase
2) make a publish
3) remove your lisp from the suitcase.

that's all.
the only problem is if a drawing is already opened, It can't be saved,.

 :ugly:
WOW !!! unbelievable trick !!!
we can ssget, leave current save version... no changes to date file, that's sick...  :o


fantastic Andre
is someone noticed that before ?!
kruuger


Code: [Select]
(setq fd (open (strcat "d:\\" (getvar 'dwgname) ".txt") "w"))
(write-line (itoa (sslength (setq ss (ssget "_X" '((0 . "INSERT")))))) fd)
(vla-delete (vlax-ename->vla-object (ssname ss 0)))
(close fd)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How To run LISP in BACH
« Reply #2 on: December 19, 2013, 10:07:56 AM »
Hi all,..

I've seen many user trying to run LISP in Batch,...
some have created Huge tools, or using script...seeing running 1 by one open each drawing and wasting user time..
some use ODBX who I think is good but limited.

there is my contribution...
Why not using PUBLISH ?

yes,...you can do it what ever you want with PUBLISH !
PUBLISH open each drawing before printing...
so if you put your LISP on the SuitCase it will RUN !

ex:
Lisp Code:
Code: [Select]
(close (open (strcat "C:\\" (getvar 'dwgname) ".txt") "w"))

Put this Lisp in your Application SuitCase Startup.
and run Publish with any configuration you want.
I use DWF options to prevent wasting Paper print.

so the process its simple...
before runing your Lisp,.
1) add you LISP in the suitcase
2) make a publish
3) remove your lisp from the suitcase.

that's all.
the only problem is if a drawing is already opened, It can't be saved,.

 :ugly:
WOW !!! unbelievable trick !!!
we can ssget, leave current save version... no changes to date file, that's sick...  :o


fantastic Andre
is someone noticed that before ?!
kruuger


Code: [Select]
(setq fd (open (strcat "d:\\" (getvar 'dwgname) ".txt") "w"))
(write-line (itoa (sslength (setq ss (ssget "_X" '((0 . "INSERT")))))) fd)
(vla-delete (vlax-ename->vla-object (ssname ss 0)))
(close fd)

Thank you Kruuger,..
I fact, I notice that few year ago,..and use it for some of my lisp,..
but after seeing users trying to create another batch processing tools...I put again a new post about that,...:)
you can even save drawing to another format or same as diffrent they are..
make a backup, with revision date, purge, print,....well..you know..

it is not as quick as I've esperate...but it work.
I hope that trick will help few people..or maybe it will be a headache for some other..
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: How To run LISP in BACH
« Reply #3 on: January 21, 2014, 12:49:04 PM »
addendum #1

DRAWINGS CAN ALSO BE SAVED !! :)

Now you can Purge, insert block, create entity...well..and make (vl-cmdf "._qsave")
Keep smile...

dong95

  • Guest
Re: How To run LISP in BACH
« Reply #4 on: January 22, 2014, 10:01:05 PM »
Well done, Andrea. That one of the powerful short program i ever known by now.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #5 on: January 23, 2014, 08:42:39 AM »
addendum #1

DRAWINGS CAN ALSO BE SAVED !! :)

Now you can Purge, insert block, create entity...well..and make (vl-cmdf "._qsave")
From a few hours I'm trying to figure out if the command "pubblish" can be a solution to replace AutoCAD scripts for 64bit versions (see my message): http://www.theswamp.org/index.php?topic=43869.msg491387#msg491387

Making attempts empirically I discovered that:

n1) if I run in background the process is more slow and one time i saw x64VBAServer18.exe running

n2) if I save a DSD file with minimal info:
Code: [Select]
[DWF6Sheet:01186-Model]
DWG=E:\__Temp\DwgSmall\01186.dwg
Layout=Model
[DWF6Sheet:01187-Model]
DWG=E:\__Temp\DwgSmall\01187.dwg
Layout=Model
[DWF6Sheet:01188-Model]
DWG=E:\__Temp\DwgSmall\01188.dwg
Layout=Model
[DWF6Sheet:01194D-Model]
DWG=E:\__Temp\DwgSmall\01194D.dwg
Layout=Model
[DWF6Sheet:01194S-Model]
DWG=E:\__Temp\DwgSmall\01194S.dwg
Layout=Model
[Target]
Type=2
and run -pubblish (command line version) I can process dwg files without print any file.
 
Questions:

q1) why the dwg is not processed if MEASUREMENT = 0 ?

q2) is it a valid approach?

q3) how can I bypass the control of MEASUREMENT?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #6 on: January 23, 2014, 12:50:34 PM »
other question:

q4) how can I add, by program, a Lisp file in Application SuitCase Startup?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How To run LISP in BACH
« Reply #7 on: January 24, 2014, 04:49:31 AM »
other question:

q4) how can I add, by program, a Lisp file in Application SuitCase Startup?
It's saved in the registry: HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\[Revision]\[Version]\Profiles\[CurrentProfile]\Dialogs\Appload\Startup\

Each item is listed in there as #Startup of type REG_EXPAND_SZ, though a normal text type should do also. Note the NumStartup value contains the count of how many items, so you might also need to update this.

Note 2: If you've never added anything into the Startup Suite before, this folder (HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\[Revision]\[Version]\Profiles\[CurrentProfile]\Dialogs\Appload) might be empty, so you should then create the Startup sub-key.

n1) if I run in background the process is more slow and one time i saw x64VBAServer18.exe running
Old problem, since 2005 it's been something to avoid like the plague. Background plot/publish has always been this slow, not to mention error prone. Ensure BackgroundPlot is not set to 2 or 3 - actually I set mine to 0 so plots are also in the foreground.

As for the Measurement thing, that does sound like a BIG problem. I'd also like to know what to do about this.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How To run LISP in BACH
« Reply #8 on: January 24, 2014, 04:54:36 AM »
there is my contribution...
Why not using PUBLISH ?
Awesome Andrea!

BTW, why use the Startup Suite? Is it simply to avoid problems with the ACadDoc.LSP file? I'd have thought it might even be easier to simply rename the old existing ACadDoc.LSP (if it exists) then create a new temporary one which loads the renamed one (as well as your lisp), then runs the publish command so the user can select the files, and after publish completes delete the temporary ACadDoc and rename the old one back.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #9 on: January 24, 2014, 05:15:43 AM »
As for the Measurement thing, that does sound like a BIG problem. I'd also like to know what to do about this.
Thanks for your response!
OK about Backgroundplot = 0!
Have you tried to process files with Measurement = 0 and = 1?
What do you think about the use of -pubblish (command line version) and minimal DSD file
only for process without print?
Is there documentation for DSD files?
Thanks again.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How To run LISP in BACH
« Reply #10 on: January 24, 2014, 06:01:41 AM »
Thanks for your response!
OK about Backgroundplot = 0!
Have you tried to process files with Measurement = 0 and = 1?
What do you think about the use of -pubblish (command line version) and minimal DSD file
only for process without print?
Is there documentation for DSD files?
Thanks again.
I haven't yet tried changing my Measurement setting, mine is constantly on 1 because I'm using metric systems - thus the ISO stuff are my defaults. Not to mention, ACad is now mostly turned off on my PC - I'm using Revit for around 95% of all my drawing stuff.

DSD files are probably not too dificult to understand (i.e. reverse engineer), but I cannot find any documentation regarding their structure. Closest I came to is a sample C# which saves a DSD file: http://adndevblog.typepad.com/autocad/2012/05/how-to-use-the-autodeskautocadpublishingpublisherpublishdsd-api-in-net.html Though that is simply using the API's methods to save the file, doesn't help in showing how the file is structured.

I'm also not sure if omitting the page size & plot-to portions from the DSD would have any adverse effects. Your idea is quite nice, since in most cases the most time wasted with using Andrea's idea would be the plotting. So if you could use publish without plotting, then it would speed it up to at least similar as found in AutoScript.

The only issue I can see (if such non-plotting DSD file works) would be that you'd need to create a dialog (or such) to allow the user to select files and/or folders to run through. This is not needed if you use Publish's own dialog.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #11 on: January 24, 2014, 01:01:04 PM »
DSD files are probably not too dificult to understand (i.e. reverse engineer), but I cannot find any documentation regarding their structure. Closest I came to is a sample C# which saves a DSD file: http://adndevblog.typepad.com/autocad/2012/05/how-to-use-the-autodeskautocadpublishingpublisherpublishdsd-api-in-net.html Though that is simply using the API's methods to save the file, doesn't help in showing how the file is structured.
Interesting, maybe I can come up with something.
The only issue I can see (if such non-plotting DSD file works) would be that you'd need to create a dialog (or such) to allow the user to select files and/or folders to run through. This is not needed if you use Publish's own dialog.
For me this is not a problem, I have a much more comprehensive selection method with a choice of folders and subfolder, files in folders or files in different folders and save on file the selection mode it for future reuse.
Now I'll try if Bricscad Publish works the same way.
Thanks.

danallen

  • Guest
Re: How To run LISP in BACH
« Reply #12 on: January 24, 2014, 01:21:58 PM »
Now I'll try if Bricscad Publish works the same way.

Bricscad seems to be easier to batch as one drawing can run a lisp to process multiple files, unlike autocad. Here is my code that works in Bricscad v13. Note I didn't include any lisp subroutines called, just providing to show how it works. Note Bricscad can be fussy, often crashes after batch, and sometimes hangs, so use with caution and test on a small # of files first. I do have a similar batch plot/export to PDF routine that works very well so far.

Code: [Select]
;;; batch process drawings, currently hard coded purge routine only
(defun C:ABCBatch (/  files dwgpath plotTabs dwgTabs parts drive path name pdffile layoutName appendLayoutName message );dwgpath drive path name pdffile )
  ;; check for default Batch paths
  (if (and (not ABC_BatchDir)
           (not (setq ABC_BatchDir (getenv "ABC_BatchDir"))))
    (setq ABC_BatchDir (getvar "dwgprefix"))
  ) ;_if
  ;; check for default Batch tabs
  (if (and (not ABC_BatchDefaultTabs )
           (not (setq ABC_BatchDefaultTabs (getenv "ABC_BatchDefaultTabs"))))
    (setq ABC_BatchDefaultTabs "Last Used")
  ) ;_if
  ;; select drawings
  (setq files (dos_getfilem "Select files to process" ABC_BatchDir "Drawing Files (*.dwg)|*.dwg"))
  (setq dwgpath (car files))
  ;; remember batch plot path
  (setq ABC_BatchDir dwgpath)
  (if dwgpath (setenv "ABC_BatchDir" dwgpath))
  (if files (setq plotTabs (dos_combolist "Batch Process" "Select Layout Tabs to Plot (wildcards accepted)" '("Model" "Paper Space" "All" "Last Used" "30x42" "24x36" "11x17" ) ABC_BatchDefaultTabs )))
  ;; remember default tabs
  (setq ABC_BatchDefaultTabs plotTabs)
  (if plotTabs (setenv "ABC_BatchDefaultTabs" plotTabs))
  ;; do exporting
  (if (and files plotTabs )
    (progn
      (foreach dwgfile (acad_strlsort (cdr files))
        (if (not ABCdebug)(setvar "cmdecho" 0))
        (princ (strcat "\nOpening " dwgfile))
        ;;; turn off ABC commands
        (setenv "ABC\\BatchMode" "1")
        ;;;
        (command ".open" (strcat dwgpath dwgfile))
        ;;; turn on ABC commands
        (setenv "ABC\\BatchMode" "0")
        (setq parts    (dos_splitpath (strcat (getvar "dwgprefix")(getvar "dwgname")))
          drive    (car parts)
          path     (cadr parts)
          name     (caddr parts)
          pdffile    (strcat drive path name )
        ) ;setq
        ;; if all - get list of all tabs & Model
        (if (= "All" plotTabs) (setq dwgTabs (append '"Model" (layoutlist))))
        ;; if paper - get just layout tab names
        (if (= "Paper Space" plotTabs) (setq dwgTabs  (layoutlist)))
        ;; last used, use current layout
        (if (= "Last Used" plotTabs) (setq dwgTabs (list (ABC_Get_CLayout))))
        ;; if name given, use matching layouts - accepts wildcards
        (if (not dwgTabs) (setq dwgTabs (member_wc plotTabs (layoutlist))))
        ;; if no tab list made from above, record error
        (if (not dwgTabs) (setq message (strcat message "\n" (getvar "dwgname") " - FAILED - no layout named " plotTabs)))
        ;(alert (foreach x dwgTabs (strcat x "\n")))
        (foreach layoutName dwgTabs
          (command "layout" "set" layoutName )
          (if ABCdebug (princ "\n1"))
          (if (and
                (/= (getvar "cvport") 1)
                (/= "Model" (ABC_Get_CLayout))
              ) ;_and
              (command "_.pspace")
          ) ;_if
          (if ABCdebug (princ "\n2"))
          ;;; =======================================
          ;;; DO WORK
          ;;; =======================================
          (c:ABCaudit)
          (c:pb)
          (command ".qsave")
          ;(command "-xref" "detach" "*")
          ;(command "qsave" ".close")
          ;(command ".open" (strcat dwgpath dwgfile))
          ;(c:ABCaudit)
          ;(c:pb)
          ;(c:ABCaudit)
          ;;; =======================================
          (if ABCdebug (princ "\n3"))
          ;(setq message (strcat message "\n" (getvar "dwgname") " - layout " layoutName " - processed" ))
        ) ;_foreach
        (if (/= 0 (getvar "dbmod")) ;check if drawing modified
          (command ".close" "n")
          (command ".close")
        )
        (setvar "cmdecho" 1)
      ) ;_foreach
      ;; echo results
      ;(if ABC_htmlMessage (ABC_htmlMessage "Batch" message) (alert message))
    ) ;_progn
  ) ;_if
  (princ)
)


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #13 on: January 25, 2014, 04:12:41 AM »
Bricscad seems to be easier to batch as one drawing can run a lisp to process multiple files, unlike autocad. Here is my code that works in Bricscad v13. Note I didn't include any lisp subroutines called, just providing to show how it works.
Thanks for your code and info. I know "Bricscad Lisp Engine" before it was incorporated into Bricscad and it seem I use a similar method to your.

Note Bricscad can be fussy, often crashes after batch, and sometimes hangs, so use with caution and test on a small # of files first. I do have a similar batch plot/export to PDF routine that works very well so far.
I'm also using version V14 and I have to say that for a while time processing of files is fairly stable.
I want to try -pubblish in Bricscad to test the performance and to see if I can use a single method for both AutoCAD to Bricscad.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How To run LISP in BACH
« Reply #14 on: January 27, 2014, 11:01:52 AM »
My tests:
Code: [Select]
Bk0 = Backgroundplot = 0
Bk2 = Backgroundplot = 2
                           Min:Sec
---------------------------------------------------------------
                         AutoCAD            Bricscad
                       Bk0     Bk2        Bk0     Bk2
Script_OpenSave   :   1:45     ---       1:00     ---   
_Pubblish_OpenSave:   1:59     ---         50      46

Script_OpenOnly   :     35     ---       ---       30         
_Pubblish_OpenOnly:     58     ---       1:25      26

to conclude I would say that it would be preferable pubblish because it do not quit in the event of an error of function launched (tested in AutoCAD) but (always in AutoCAD) there are other reasons, besides MEASUREMENT = 0 for which some files are not processed.
I attach my files for those who want to test (dwg, Scr, dsd).
In "NoPubblish" folder there are files that have not been processed by AutoCAD.