Wednesday, March 10, 2004

That's Visual Lisp Baby


Wow, when they say you do not get any sleep when you have a baby they are not kidding one bit, but boy is it worth it. ;)

I finally got the chance to hop on the computer earlier to work for a bit and had a request from a friend for a snippet of lisp code to copy files from a network location to a users local drive if/when the file is updated. This allows AutoCAD/ADT to control the copying of the files and not rely on DOS, VBScript or other scripting method and a startup/login script. Since this is a simple but useful item for CAD Managers and Power Users, feel free to use it.

I can honestly say I finally coded with one hand behind my back (I had Dylan beside me and he wanted to hold my finger while napping).

==========================================
; start of code here
; copy outdated file to users folder location
; created by Beau Turner 3/10/2004
; copy this code between the ==== and place in your acad*doc.lsp file
; * this may be either 2000, 2004 or 2005 depending on the verison you have installed
;
; in this example the f:/AutoCAD/mytestfile.txt is the "good" file
; the c:/mytestfile.txt is the users folder and location to copy the file to
; it will only copy if the file save time is different

(vl-load-com)
(setq origfile (vl-file-systime "c:/mytestfile.txt")
newfile (vl-file-systime "f:/AutoCAD/mytestfile.txt")
);close of setq

(if (/= origfile newfile)
(vl-file-copy "f:/AutoCAD/mytestfile.txt" "c:/mytestfile.txt"
(vl-file-delete "c:/mytestfile.txt"))
);close of if statement
; end of code here
==========================================

==========================================
; start of code here
; copy outdated file to users folder location
; created by Beau Turner 3/10/2004
; copy and paste code between the ==== and place in a new file
; name it CopyFile.lsp (or whatever you want to call it)
;
; in this example the f:/AutoCAD/mytestfile.txt is my "good" file
; the c:/mytestfile.txt is the users folder and location to copy the file to
; it will only copy if the file save time is different

(vl-load-com)
(defun c:CopyFile (/ origfile newfile)
(setq origfile (vl-file-systime "c:/mytestfile.txt"))
(setq newfile (vl-file-systime "f:/AutoCAD/mytestfile.txt"))

(if (/= origfile newfile)
(vl-file-copy "f:/AutoCAD/mytestfile.txt" "c:/mytestfile.txt"
(vl-file-delete "c:/mytestfile.txt"))
);close of if statement
);close of defun

; end of code here
==========================================

Want to get started coding with Lisp/Visual Lisp? Check out "The Visual Lisp Developers Bible", a free download from my buddy Dave Stein. Though there are currently no plans to continue development of this great resource you will still find this .pdf a great resource and reference and hey its free, so what are you waiting for.

happy coding...

Blog Archive

 

Copyright 2009 All Rights Reserved Beau Turner Triple D Design, LLC | Template design by Brian Gardner | Converted to Blogger Template by Bloganol dot com