Author Topic: Update drawings in a directory  (Read 8661 times)

0 Members and 1 Guest are viewing this topic.

aicm

  • Guest
Re: Update drawings in a directory
« Reply #15 on: October 27, 2005, 02:34:39 PM »
Code: [Select]
    ...(close fp)
    (alert "ALL YOUR BASE ARE BELONG TO US")
    (command "_DELAY" 1500)
    (command "_SCRIPT" scrfile)   ; Run the script

    (princ)

I could think of more things to put there......

Like:
"Courtesy of The Swamp" 

among other choices .    :-D

deegeecees

  • Guest
Re: Update drawings in a directory
« Reply #16 on: October 27, 2005, 02:55:09 PM »
Not a bad choice at all, my freind.

Fatty

  • Guest
Re: Update drawings in a directory
« Reply #17 on: October 27, 2005, 04:01:46 PM »



Fatty,
This one is a winner.......... fantastic ......... now I just heed to study how you did this.
Looks like I'm going to have to stay up at nights with Stig's LISP course and Kenny's Afra LISP downloads and get my ar$e in gear and lean this stuff.

We can't thank you enough for taking the time to help.
Larry

PS.
I tried this one first and will take the other suggestions for a spin later today or tonight.

Thank you all again
Larry

Hi Larry
Glad if it work for you
BTW, if you don't pleased first routine, try another one:
(tested in A2005 only)

Code: [Select]
(prompt "\n\t\t****\tType BN to run batch file operation\t****\n")

(defun C:BN  (/ acad_app acad_docs acapp adoc bad_files file_list
      fnames other_file path pick_file sld_name x)
  (vl-load-com)
  (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)))
  (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 '()
    )
      (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))
     (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"))
  (gc)
  (princ)
  )

aicm

  • Guest
Re: Update drawings in a directory
« Reply #18 on: October 28, 2005, 08:21:27 AM »
Quote
Hi Larry
Glad if it work for you
BTW, if you don't pleased first routine, try another one:
(tested in A2005 only)

Fatty,   
For some reason addressing you with this name is disconcerting to me ..... my issue I guess.
Anyway....

This is another winner.  DING .... DING     :-)
One thing I did notice is that most of these routines change some of the current system variables.
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.

This is not a big issue but just something I noticed.
Thank you for taking the time to help
Larry & all the guys in the studio.

Fatty

  • Guest
Re: Update drawings in a directory
« Reply #19 on: October 28, 2005, 11:52:04 AM »


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

Code: [Select]

(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

aicm

  • Guest
Re: Update drawings in a directory
« Reply #20 on: October 28, 2005, 12:37:04 PM »
Quote
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

This has turned out to be the first time I have really taken the time to understand what is going on with lisp.  It is a wonderful experience and just might be something I can become interested in doing myself [with a lot more study].

Quote
Sorry I don't understand your humor because of phraseological English nuances
Fatty

It's has to do with the American hangup up on being over weight.  Too much commercial concentration on having "a model" physique.  Really not worth mentioning now that I start to explain what I was alluding to. 

Thanks for the short lesson on setting variables.  I realize, to you gurus on this site, it seems rather elementary.
Looks like I'll be spending a lot more time wandering around here ....... learning.

Fatty

  • Guest
Re: Update drawings in a directory
« Reply #21 on: October 28, 2005, 02:23:55 PM »


It's has to do with the American hangup up on being over weight.  Too much commercial concentration on having "a model" physique.  Really not worth mentioning now that I start to explain what I was alluding to. 

Thanks for the short lesson on setting variables.  I realize, to you gurus on this site, it seems rather elementary.
Looks like I'll be spending a lot more time wandering around here ....... learning.


Hi Larry

Are you welcome but..

Sorry I'm again wrote wrong expression:
change all strings like this:
(vla-put-color nl col)
on:
(vla-put-color (vla-item alrs l_name) col)

Happy computing :kewl:

Fatty