TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on May 28, 2019, 12:25:08 AM

Title: Autolisp Open Multiple Files and Run LISP
Post by: mailmaverick 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.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: kpblc on May 28, 2019, 12:54:48 AM
I think you can't do it by simple lisp. Use script or ObjectDBX.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: MP on May 28, 2019, 01:05:35 AM
You can do it by invoking a vba routine from lisp.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: MSTG007 on May 28, 2019, 06:55:50 AM
I went from scripts (scriptpro) to using the acaddoc.lsp. Works great for me.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: vincent.r on May 28, 2019, 10:51:57 AM
@MSTG007 can you please explain ? I tried it some days back but was not successful.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: MSTG007 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)
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: kpblc 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.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: mailmaverick 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.
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: kpblc 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
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: mailmaverick on May 29, 2019, 05:58:25 AM
Thanks a lot. That should get me going !!!!
Title: Re: Autolisp Open Multiple Files and Run LISP
Post by: kdub_nz on May 29, 2019, 06:48:35 PM
kpblc
I like that you save/archive the file before you work on it.