PDA

View Full Version : Insert a Layout via LISP


sumulong
2007-06-07, 12:08 AM
I'm trying to import a layout into a number of drawings and was thinking that I can just change a few codes from this lisp I got from this forum. I was hoping that it would have been this simple. Here's the code.


;;; Main program, command: batchjob
(defun c:BatchJob (/ dwgs file dwgName scrFile folderName)
(setq folderName
(browsefolder "Select folder to perform batch job: ")
)
(setq dwgs (vl-directory-files folderName "*.dwg"))
(setq scrFile (open (strcat folderName "\\batchJob.scr (file://batchJob.scr/)") "w"))
(foreach file dwgs
(setq dwgName (strcat "\"" folderName "\\" file "\""))
(write-line ".Open" scrFile)
(write-line dwgName scrFile)
(write-line "_layout t N:/test/changed/107i03202-1_00.dwg" scrfile)
(write-line ".zoom e" scrFile)
(write-line "CLOSE " scrFile)
)
(close scrFile)
(command ".script" (strcat folderName "\\batchJob.scr (file://batchJob.scr/)"))
(princ)
)
;;; Function to browse folder
;;; This code was originally posted by kpblc2000 in AUGI AutoLisp Forum
;;;
(defun browsefolder (title / shlobj folder fldobj)
(vl-load-com)
(setq
shlobj (vla-getinterfaceobject
(vlax-get-acad-object)
"Shell.Application"
)
folder (vlax-invoke-method shlobj 'browseforfolder 0 title 0)
)
(vlax-release-object shlobj)
(if folder
(progn
(setq
fldobj (vlax-get-property folder 'self)
folderName (vlax-get-property fldobj 'path)
)
(vlax-release-object folder)
(vlax-release-object fldobj)
folderName
)
)
)
(princ "\nBatchJob is loaded, Type BatchJob to run.")
(princ)

abdulhuck
2007-06-07, 03:55 PM
I guess you have to first save the source drawing as a drawing template. If your source drawing name is "ABCD.DWT" and your layout name is "XYZ", then replace the red line in your code with

(write-line "-Layout T" scrfile)
(write-line "ABCD.DWT" scrfile)
(write-line "XYZ")


I did not test it. Please let me know if there is any error messages/prompts.

Regards
AH

sumulong
2007-06-08, 12:50 AM
Well, after a while of trial and error, here's the correct line and it now works!

(write-line "_layout t N:/test/changed/107i03202-1_00.dwg 107-i03-202" scrfile)

a space and the layout name was the answer. now i'm wondering what happens if the layout name has a space? Is there a way to have the layout name have a space w/out having autocad treat it as a return?

Anythoughts?

abdulhuck
2007-06-10, 12:38 PM
Is there a way to have the layout name have a space w/out having autocad treat it as a return?
By default AutoCAD accepts spaces in layout names. It won't be treated as return even if you include spaces when it prompts for the layout names. In certain case, names containing spaces can be included within double quotes especially when running from script files.

Regards,
AH

fixo
2007-06-10, 09:52 PM
Please change this

;;; Function to browse folder
;;; This code was originally posted by kpblc2000 in AUGI AutoLisp Forum
;;;
on this one:
;; written by Tony Tanzillo



IMHO

~'J'~

abdulhuck
2007-06-11, 06:44 AM
Please change this

;;; Function to browse folder
;;; This code was originally posted by kpblc2000 in AUGI AutoLisp Forum
;;;
on this one:
;; written by Tony Tanzillo



IMHO

~'J'~Thanks J. I didn't know who is the author of this useful code so far, so I mentioned the source (the person who posted it). I will update my archive. And thanks to Tony Tanzillo too.

Regards
AH

sumulong
2007-06-12, 09:13 PM
will do! i'll update mine as well.

thanks again for all the input!