PDA

View Full Version : Batch routine to clean up Blocks within DWG files



george.arq
2007-01-23, 03:26 PM
Hi,
I dont know if this is possible, but ill ask..

I have a lot of blocks, most of them aren't like i want:
layer 0
color, weight and type by layer ..

I wish I could make same theres on photoshop, we can record some actions and 'play' the action in some folder.
Is it possible?
I choose the folder and it opens all files in this folders and use the sequence commands:

1. open first file
2. select all objects
3. layer 0
4. color weight and type by layer
5. PURGE
6. zoom extend
7. save
8. close
9. open next file
..

If its not possible to make this automatic..
at least if I can use this sequence(2-8) in ONE command it will be easier to me..

thanks :)

abdulhuck
2007-01-24, 08:54 AM
Hi,
I dont know if this is possible, but ill ask..

I have a lot of blocks, most of them aren't like i want:
layer 0
color, weight and type by layer ..

I wish I could make same theres on photoshop, we can record some actions and 'play' the action in some folder.
Is it possible?
I choose the folder and it opens all files in this folders and use the sequence commands:

1. open first file
2. select all objects
3. layer 0
4. color weight and type by layer
5. PURGE
6. zoom extend
7. save
8. close
9. open next file
..

If its not possible to make this automatic..
at least if I can use this sequence(2-8) in ONE command it will be easier to me..

thanks :)
George,

Save the following code as BatchJob.lsp, load the file, type "BatchJob" in command prompt, browse your folder, sit back and relax...



;;; Main program, command: batchjob
;;; By Abdul Huck
(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"))
(write-line ";;; © Abdul Huck, abdulhuck@rediffmail.com \n;;;" scrFile)
(write-line "SDI 1" scrFile)
(foreach file dwgs
(setq dwgName (strcat "\"" folderName "\\" file "\""))
(write-line ".Open" scrFile)
(write-line dwgName scrFile)
(write-line
".chprop all la 0 c bylayer lw bylayer "
scrFile
)
(write-line "-purge a * n" scrFile)
(write-line ".zoom e" scrFile)
(write-line ".Qsave" 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)


Note: You have to make sure that the current drawing does not ask for "Really want to discard all changes..." prompt. Better to save the current drawing before running BatchJob command.

Regards,
Abdul Huck

george.arq
2007-01-25, 12:04 PM
Perfect =]
thanks a lot man
luv ya
heheh
:)

Can I share with my friends?
see ya

abdulhuck
2007-01-25, 12:33 PM
Perfect =]
thanks a lot man

Happy to know that it helps.



Can I share with my friends?

Ofcourse, you can.

Regards,

Abdul Huck