Is there a section of code that could be inserted to save the variables and then re-set them to their initial values after the program has run?
For example: Filedia is one of them.
Hi Larry
Good question
This is correct observation, here it is possible to use
by all the known trick: at the start the program
to define (setq oldfiledia (getvar "filedia")) etc.
and at the end of the program to restore (setvar "filedia" oldfiledia)
BTW in this routine you can use any another function instead of or with
(vla-zoomextents (vla-get-application other_file)) i.e. something like this:
(set-layer other_file "LayerName" "LayerColor" "LayerLType")) etc.
or command i.e. (command "mslide" other_file_short_name)
or batch plot etc.
Let play with it and you will know new possibility of this routine
(No warranty)
Thank you
(defun set-lay (cdoc l_name lt_name col / alrs alts nl tbl tblt tmp tmp1)
(setq alrs (vla-get-layers cdoc)
alts (vla-get-linetypes cdoc)
tbl (vlax-for l_item alrs
(setq tmp (cons (vla-get-name l_item) tmp)))
tblt (vlax-for lt_item alts
(setq tmp1 (cons (vla-get-name lt_item) tmp1)))
)
(if (not (member lt_name tblt))
(vla-load alts (strcase lt_name) "acadiso.lin"));or acad.lin
(if (member l_name tbl)
(progn
(if (/= (vla-get-name (vla-get-activelayer cdoc)) l_name)
(setq nl (vla-put-activelayer cdoc (vla-add alrs l_name)))
(setq nl (vla-get-activelayer cdoc))
)
(vla-put-color nl col)
(vla-put-linetype nl lt_name)
)
(progn
(setq nl (vla-add alrs l_name))
(vla-put-activelayer cdoc nl)
(vla-put-color nl col)
(vla-put-linetype nl lt_name)
)
)
(if (/= (vlax-variant-value
(vla-getvariable cdoc "CECOLOR"))
"BYLAYER")
(vla-setvariable cdoc "CECOLOR" "BYLAYER")
)
(if (= (vla-get-layeron nl) :vlax-false)
(vla-put-layeron nl :vlax-true)
)
(if (= (vla-get-freeze nl) :vlax-true)
(vla-put-freeze nl :vlax-false)
)
(if (= (vla-get-lock nl) :vlax-true)
(vla-put-lock nl :vlax-false)
)
(princ)
)
(prompt
"\n\t\t****\tType BL to run batch file operation\t****\n")
(defun C:BL (/ acad_app acad_docs acapp adoc bad_files batch-err
file_list fnames oldcmd older oldfil oldsdi other_file path pick_file x)
(defun batch-err (msg)
(if (not (member msg '("console break"
"Function cancelled"
"quit / exit abort")))
(princ (strcat "\nError: " msg)))
(if (and acad_app
(not (vlax-object-released-p acad_app))
(vlax-read-enabled-p acad_app)
(vlax-write-enabled-p acad_app))
(progn
(vlax-release-object acad_app)
(setq acad_app nil)))
(setq *error* older)
(setvar "filedia" oldfil)
(setvar "cmdecho" oldcmd)
(setvar "sdi" oldsdi)
(gc)
(princ)
)
(vl-load-com)
(setq older *error*
*error* batch-err)
(or acapp
(setq acapp (vlax-get-acad-object)
)
)
(or adoc
(setq adoc
(vla-get-activedocument
acapp
)
)
)
(setq pick_file
(getfiled "Select any of DWG-files : >>>"
(getvar "dwgprefix")
"dwg"
16))
(setq path (strcat (vl-filename-directory pick_file) "\\"))
(setq fnames (vl-directory-files path "*.dwg"))
(setq file_list (acad_strlsort
(mapcar (function (lambda (x) (strcat path x))) fnames)))
(setq oldfil (getvar "filedia"))
(setq oldcmd (getvar "cmdecho"))
(setq oldsdi (getvar "sdi"))
(setvar "filedia" 0)
(setvar "cmdecho" 0)
(setvar "sdi" 0)
(setq acad_app (vlax-create-object "Autocad.Application"))
(if acad_app
(progn
(vlax-put-property acad_app "Visible" :vlax-true)
(setq acad_docs (vla-get-documents acad_app)
bad_files (list)
)
(foreach file file_list
(if
(not
(vl-catch-all-error-p
(setq other_file
(vl-catch-all-apply 'vla-open (list acad_docs file)))))
(progn
(vla-zoomextents (vla-get-application other_file));or comment this string
(set-lay other_file "TEST_BATCH_LAYER#1" "Phantom2" "160")
(set-lay other_file "TEST_BATCH_LAYER#2" "ZigZag" acred)
(vla-close other_file :vlax-true)
(vlax-release-object other_file)
)
(progn
(setq bad_files (append bad_files (list file))
)
)
)
)
(vl-catch-all-apply
(function (lambda ()
(vlax-invoke-method acad_app "Quit")
)))
(mapcar (function (lambda (x)
(if
(and x
(not (vlax-object-released-p x)))
(vl-catch-all-apply
(function (lambda ()
(vlax-release-object x))))
)
))
(list other_file acad_docs acad_app)
)
(setq other_file
nil
acad_docs nil
acad_app nil
)
)
)
(alert (strcat "There are not processed : \n"
"\t"
(itoa (length bad_files))
" files"))
(setq *error* older)
(setvar "filedia" oldfil)
(setvar "cmdecho" oldcmd)
(setvar "sdi" oldsdi)
(gc)
(princ)
)
______________________________________________________________
Sorry I don't understand your humor because of phraseological English nuances
Fatty