Author Topic: Autolisp Open Multiple Files and Run LISP  (Read 374 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 433
Autolisp Open Multiple Files and Run LISP
« on: May 28, 2019, 12:25:08 AM »
Hi,

Is is possible within AutoLISP to Open selected Multiple AutoCAD Files, Run a given LISP, Save and Close the files, one by one.
If yes then how ?
Thanks.

kpblc

  • Bull Frog
  • Posts: 306
Re: Autolisp Open Multiple Files and Run LISP
« Reply #1 on: May 28, 2019, 12:54:48 AM »
I think you can't do it by simple lisp. Use script or ObjectDBX.
Sorry for my English.

MP

  • Seagull
  • Posts: 17336
Re: Autolisp Open Multiple Files and Run LISP
« Reply #2 on: May 28, 2019, 01:05:35 AM »
You can do it by invoking a vba routine from lisp.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MSTG007

  • Water Moccasin
  • Posts: 2374
  • I can't remeber what I already asked! I need help!
Re: Autolisp Open Multiple Files and Run LISP
« Reply #3 on: May 28, 2019, 06:55:50 AM »
I went from scripts (scriptpro) to using the acaddoc.lsp. Works great for me.
Autodesk Infrastructure Design Suite 2019

vincent.r

  • Newt
  • Posts: 26
Re: Autolisp Open Multiple Files and Run LISP
« Reply #4 on: May 28, 2019, 10:51:57 AM »
@MSTG007 can you please explain ? I tried it some days back but was not successful.

MSTG007

  • Water Moccasin
  • Posts: 2374
  • I can't remeber what I already asked! I need help!
Re: Autolisp Open Multiple Files and Run LISP
« Reply #5 on: May 28, 2019, 11:03:35 AM »
Hopefully this will make more sense. At least it works for me.

Code: [Select]
(defun c:Batch_Via_ACADDOC_LSP ()

;;Load this acaddoc.lsp within a support path.
;;If  ;;  is in front of the line, it will not work when opening drawings.
;;Remove  ;;  this to get command to work on each drawing it opens.


;;Place Code Below
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;(command "-layout" "set" "")

;;(command "-layer" "set" "0" "freeze" "*SEAL*" "")

;;(command "purge" "a" "" "n")

;;(command "purge" "regapps" "" "n")

;;(command "purge" "a" "" "n")

;;(command "_.close" "");;Closes Drawing with Saving

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Keep Bottom Code
)
(c:Batch_Via_ACADDOC_LSP)
(princ)
Autodesk Infrastructure Design Suite 2019

kpblc

  • Bull Frog
  • Posts: 306
Re: Autolisp Open Multiple Files and Run LISP
« Reply #6 on: May 28, 2019, 11:39:53 AM »
mailmaverick, what kind of lisp you wnat to run? If this lisp uses only activex methods, it could be run in ObjectDBX mode.
Sorry for my English.

mailmaverick

  • Bull Frog
  • Posts: 433
Re: Autolisp Open Multiple Files and Run LISP
« Reply #7 on: May 29, 2019, 04:31:21 AM »
mailmaverick, what kind of lisp you wnat to run? If this lisp uses only activex methods, it could be run in ObjectDBX mode.

I have to run normal LISP which shall put particular objects in given layers, such as all Dimensions in "DIM" Layer, all Texts in "TEXT" layer and then Save the File, Close and Proceed to next File.

If its possible in ObjectDBX, please let me know how to do it. Thanks.

kpblc

  • Bull Frog
  • Posts: 306
Re: Autolisp Open Multiple Files and Run LISP
« Reply #8 on: May 29, 2019, 04:53:33 AM »
Without any testing:
Code - Auto/Visual Lisp: [Select]
  1. (defun change-prop-in-dwgs (dwg-list / odbx conn layers)
  2.  (foreach file dwg-list
  3.    (if (findfile file)
  4.      (progn (vl-file-copy file (strcat (vl-filename-directory file) "\\" (vl-filename-base file) "_dbx.bak"))
  5.             (setq conn   (vla-open (vla-getinterfaceobject (vlax-get-acad-object)
  6.                                                            (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar "acadver"))))
  7.                                                            ) ;_ end of vla-getinterfaceobject
  8.                                    file
  9.                                    ) ;_ end of vla-open
  10.                   layers nil
  11.                   ) ;_ end of setq
  12.             (vlax-for item (vla-get-layers conn)
  13.               (setq layers (cons (cons item
  14.                                        (mapcar (function (lambda (x / tmp)
  15.                                                            (setq tmp (vlax-get-property item x))
  16.                                                            (vl-catch-all-apply (function (lambda () (vlax-put-property item x :vlax-false))))
  17.                                                            (cons x tmp)
  18.                                                            ) ;_ end of lambda
  19.                                                          ) ;_ end of function
  20.                                                '("freeze" "lock")
  21.                                                ) ;_ end of mapcar
  22.                                        ) ;_ end of cons
  23.                                  layers
  24.                                  ) ;_ end of cons
  25.                     ) ;_ end of setq
  26.               ) ;_ end of vlax-for
  27.             (foreach item '("TEXT" "DIM")
  28.               (if (vl-catch-all-error-p
  29.                     (vl-catch-all-apply (function (lambda () (vla-item (vla-get-layers conn) item))))
  30.                     ) ;_ end of vl-catch-all-error-p
  31.                 (vla-add (vla-get-layers conn) item)
  32.                 ) ;_ end of if
  33.               ) ;_ end of foreach
  34.             (vlax-for def (vla-get-blocks conn)
  35.               (vlax-for ent def
  36.                 (cond ((wcmatch (strcase (vla-get-objectname ent) "*TEXT")) (vla-put-layer ent "TEXT"))
  37.                       ((wcmatch (strcase (vla-get-objectname ent) "ACDB*DIM*")) (vla-put-layer ent "DIM"))
  38.                       ) ;_ end of cond
  39.                 ) ;_ end of vlax-for
  40.               ) ;_ end of vlax-for
  41.             (foreach item layers
  42.               (foreach pr (cdr item)
  43.                 (vl-catch-all-apply (function (lambda () (vlax-put-property item (car pr) (cdr pr)))))
  44.                 ) ;_ end of foreach
  45.               ) ;_ end of foreach
  46.             (vlax-invoke conn 'saveas file)
  47.             (vl-catch-all-apply (function (lambda () (vlax-release-object conn))))
  48.             (setq conn nil)
  49.             ) ;_ end of progn
  50.      ) ;_ end of if
  51.    ) ;_ end of foreach
  52.  ) ;_ end of defun
Sorry for my English.

mailmaverick

  • Bull Frog
  • Posts: 433
Re: Autolisp Open Multiple Files and Run LISP
« Reply #9 on: May 29, 2019, 05:58:25 AM »
Thanks a lot. That should get me going !!!!

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1285
  • class keyThumper<T>:ILazy<T>
Re: Autolisp Open Multiple Files and Run LISP
« Reply #10 on: May 29, 2019, 06:48:35 PM »
kpblc
I like that you save/archive the file before you work on it.
called Kerry in my other life

Sometimes the question is more important than the answer.